搭建 CentOS 6 服务器(3) - 初始环境设置

(1)系统架构

查看内核

Shell代码  

  1. # uname -s -r
  2. Linux 2.6.32-358.el6.x86_64

查看发布版本

Shell代码  

  1. # cat /etc/redhat-release
  2. CentOS release 6.4 (Final)

查看CPU架构

Shell代码  

  1. # arch
  2. x86_64(x86_64表示64位机器/i686表示32位机器)
  3. # getconf LONG_BIT
  4. 64

(2)用户设置

添加用户

Shell代码  

  1. # /usr/sbin/useradd user1 -d /home/user1 -G nobody
  2. # passwd user1
  3. New password: 123456
  4. Retype new password: 123456
  5. passwd: all authentication tokens updated successfully.

确认用户

Shell代码  

  1. # id user1

删除用户

Shell代码  

  1. # userdel -r user1

赋予root权限

Shell代码  

  1. # usermod -G wheel hoge
  2. # vi /etc/pam.d/su
  3. auth       required     pam_wheel.so use_uid  # <= 取消注释

用户一览

Shell代码  

  1. # cat /etc/passwd

(3)网络设置

设置IP

Shell代码  

  1. # vi /etc/sysconfig/network-scripts/ifcfg-eth0
  2. DEVICE="eth0"
  3. OTPROTO="static" # <=
  4. HWADDR="00:0C:29:53:A5:AE"
  5. IPV6INIT="no" # <=
  6. NM_CONTROLLED="yes"
  7. ONBOOT="yes"
  8. TYPE="Ethernet"
  9. UUID="1ca6acf4-ebce-415a-a89b-bf89a67819ff"
  10. IPADDR="xxx.xxx.xx.xx" # <=
  11. NETMASK="255.255.255.0" # <=
  12. GATEWAY="xxx.xxx.xx.xx" # <=
  13. DNS1="xxx.xxx.xx.xx" # <=
  14. # service network restart
  15. Shutting down interface eth0:
  16. ......
  17. Connection activated      [  OK  ]
  18. # ifconfig
  19. eth0      Link encap:Ethernet  HWaddr 00:0C:29:2F:D5:58
  20. inet addr:xxx.xxx.xx.xx  Bcast:xxx.xxx.xx.xx Mask:255.255.255.0
  21. ......

卸载NestworkManager服务

Shell代码  

  1. # chkconfig NetworkManager off
  2. # yum -y remove NetworkManager

关闭IPv6

Shell代码  

  1. # service ip6tables stop
  2. # chkconfig ip6tables off
  3. # echo "install ipv6 /bin/true" >> /etc/modprobe.d/disable-ipv6.conf
  4. # vi /etc/sysconfig/network
  5. NETWORKING_IPV6=no
  6. IPV6INIT=no
  7. # vi /etc/sysconfig/network-scripts/ifcfg-eth0
  8. # shutdown -r now
  9. # lsmod | grep ipv6
  10. 没有ipv6模块
  11. # netstat -an | grep ffff
  12. 没有:ffff:开始的IP
  13. # ifconfig
  14. 没有inet6 addr开始的文字

(4)包管理设置

yum清理

Shell代码  

  1. # yum clean all
  2. Loaded plugins: fastestmirror, security
  3. Cleaning repos: base extras updates
  4. Cleaning up Everything
  5. # yum makecache
  6. Loaded plugins: fastestmirror, security
  7. Determining fastest mirrors
  8. ………….
  9. Metadata Cache Created

yum更新

Shell代码  

  1. # yum -y update

自动更新

Shell代码  

  1. # yum -y install yum-cron
  2. # vi /etc/sysconfig/yum-cron
  3. CHECK_ONLY=yes
  4. DOWNLOAD_ONLY=yes
  5. # /etc/rc.d/init.d/yum-cron start
  6. # chkconfig yum-cron on
  7. # chkconfig --list yum-cron

自动查找最快镜像

Shell代码  

  1. # yum -y install yum-plugin-fastestmirror
  2. # vi /etc/yum/pluginconf.d/fastestmirror.conf
  3. enabled=0   ←0:无效 1:有效

添加repository

Shell代码  

  1. # vi /etc/yum.repos.d/CentOS-Base.repo
  2. # rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  3. # vi /etc/yum.repos.d/rpmforge.repo
  4. enabled=0
  5. # yum --enablerepo=rpmforge install xxxx
  6. # rpm -Uvh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  7. # vi /etc/yum.repos.d/epel.repo
  8. enabled=0
  9. # yum --enablerepo=epel install xxxx

(5)设置vim

Shell代码  

  1. # yum -y install vim-enhanced
  2. # vi /etc/profile
  3. alias vi=‘vim‘
  4. # source /etc/profile
  5. # vi /etc/vimrc

(6)安全设置

关闭SELinux

Shell代码  

  1. # getenforce
  2. # setenforce 0 ←临时关闭
  3. # vi /etc/sysconfig/selinux
  4. SELINUX=enforcing
  5.    ↓
  6. SELINUX=disabled

停止iptables

Shell代码  

  1. # /etc/rc.d/init.d/iptables stop
  2. iptables: Flushing firewall rules:                         [  OK  ]
  3. iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
  4. iptables: Unloading modules:                               [  OK  ]
  5. # chkconfig iptables off
  6. # chkconfig --list iptables
  7. iptables        0:off 1:off 2:off 3:off 4:off 5:off 6:off

(7)系统运行情况

磁盘使用情况

Shell代码  

  1. # df -h
  2. # yum -y install sysstat
  3. # iostat

内存使用情况

Shell代码  

  1. # free -m

CPU和内存

Shell代码  

  1. # cat /proc/cpuinfo
  2. # cat /proc/meminfo

(8)其他

本地语言化

Shell代码  

  1. # yum -y groupinstall "Japanese Support"
  2. # vi /etc/sysconfig/i18n
  3. LANG="en_US.UTF-8"
  4.    ↓
  5. LANG="ja_JP.UTF-8"
  6. # source /etc/sysconfig/i18n
  7. # echo $LANG
  8. ja_JP.UTF-8
  9. # shutdown -r now

停止不必要的服务

Shell代码  

  1. # chkconfig --list | grep 3:on
  2. # service ip6tables stop
  3. # chkconfig ip6tables off

编码转换nkf(Network Kanji Filter)

Shell代码  

  1. # yum -y install nkf
  2. # vi readme.txt
  3. test
  4. 漢字
  5. # nkf -g readme.txt
  6. UTF-8 (LF)
  7. # nkf -s --overwrite readme.txt
  8. # nkf -g readme.txt
  9. Shift_JIS (LF)
  10. # nkf -j --overwrite readme.txt
  11. # nkf -g readme.txt
  12. ISO-2022-JP (LF)

安装gcc

Shell代码  

  1. # rpm -qa gcc
  2. # yum -y install gcc gcc-c++
  3. # gcc -v
  4. Using built-in specs.
  5. Target: i686-redhat-linux
  6. …………
  7. gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

安装PCRE

Shell代码  

  1. # cd /usr/local/src
  2. # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
  3. # tar zxvf pcre-8.35.tar.gz
  4. # cd /usr/local/src/pcre-8.35
  5. # ./configure --prefix=/usr/local/pcre/8.35
  6. # make clean
  7. # make && make install
  8. # PATH=/usr/local/pcre/8.35/bin:$PATH
  9. # vi /etc/ld.so.conf
  10. /usr/local/pcre/8.35/lib ←末尾追加
  11. # ldconfig
  12. # rpm -qa pcre
  13. pcre-7.8-6.el6.x86_64
  14. # pcretest -C
  15. PCRE version 7.8 2008-09-05

安装OpenSSL

Shell代码  

  1. # cd /usr/local/src
  2. # wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
  3. # tar xzvf openssl-1.0.1h.tar.gz
  4. # cd openssl-1.0.1h
  5. # ./config shared -fPIC
  6. # make && make install
  7. # vi /etc/ld.so.conf
  8. /usr/local/ssl/lib ←末尾追加
  9. # ldconfig
  10. # ldconfig -f /etc/ld.so.conf -vp|grep ssl/lib
  11. libssl.so.1.0.0 (libc6) => /usr/local/ssl/lib/libssl.so.1.0.0
  12. libssl.so (libc6) => /usr/local/ssl/lib/libssl.so
  13. libcrypto.so.1.0.0 (libc6) => /usr/local/ssl/lib/libcrypto.so.1.0.0
  14. libcrypto.so (libc6) => /usr/local/ssl/lib/libcrypto.so
  15. # /usr/local/ssl/bin/openssl version
  16. OpenSSL 1.0.1h 5 Jun 2014

NTP同步时间

引用

# yum -y install ntp

# mv /etc/ntp.conf /etc/ntp.conf.org

# vi /etc/ntp.conf

driftfile /var/lib/ntp/drift

server 0.jp.pool.ntp.org

server 1.jp.pool.ntp.org

server 2.jp.pool.ntp.org

server 3.jp.pool.ntp.org

# ntpdate 0.jp.pool.ntp.org

# /etc/init.d/ntpd start

# ntpq -p

# ntpstat

GHOST: glibc vulnerability (CVE-2015-0235)

Shell代码  

    1. # yum update glibc
    2. # rpm -qa | grep glibc
    3. 2.12-1.149.el6_6.5
时间: 2024-08-06 11:36:32

搭建 CentOS 6 服务器(3) - 初始环境设置的相关文章

搭建 CentOS 6 服务器 - 目录

搭建 CentOS 6 服务器 - 目录 博客分类: Linux (1) 安装CentOS ISO(desktop/minimal).Cloud(AWS/阿里云).Virtualization(VMWare.VirtualBox)详细内容 (2) Linux常用命令 cd.ls.rm.chmod......详细内容 (3) 初始环境设置 用户管理.网络设置.安全设置......详细内容 (4) 常驻服务Daemon (5) 客户端远程登录 WinSCP/PuTTY/TeraTerm/Podero

搭建 CentOS 6 服务器(1) - 安装CentOS 6.6

以下是在VirtualBox里的安装过程: 1. 选择“Select Install or upgrade existing system” 2. 选择“skip ” 3. 点击“Next” 4. 选择语言后点击“Next” 5. 选择键盘 6. 选择“Select Basic Storage Device” 7. 选择“Yes, discard any data” 8. 设置“Hostname”,也可以点击“Configure Network”来设置网络 9. 选择时区 10. 设置root用

Centos Samba 服务器 iptables 和 SElinux 设置

1.安装samba服务器 # yum install samba 2.配置 # vi /etc/samba/smb.conf security = user (100行左右) 在Share Definitions下 注释以下的所有配置文件 添加以下几行 [共享的名字(如果linux支持中文,可以写中文)] path = 你需要共享的路径 browseable = yes writable = yes 3.新建用户名,新建文件夹并且设定ACL权限 # useradd -s /sbin/nologi

搭建 CentOS 6 服务器(16) - CVS、SVN、Git

(一)CVS 安装xinetd Shell代码   # rpm -q xinetd # yum install xinetd # chkconfig xinetd on # /etc/init.d/xinetd start 安装CVS Shell代码   # rpm -q cvs cvs-1.11.23-15.el6.x86_64 (CentOS自带) # yum install cvs 创建用户 Shell代码   # groupadd cvsgroup # useradd -G wheel,

centos linux服务器apache+mysql环境访问慢优化方法

一.优化apache配置增加MaxClients的值 默认情况下,2.0及以上apache版本MaxClients的值为256,对于中大型应用访问是远远不够的. 在Apache2.0中,可以通过在httpd.conf配置的perfork代码段内修改ServerLimit和MaxClients参数来突破256的限制,此时必须MaxClients ≤ ServerLimit ≤ 20000设置完之后大致是这样的: ServerLimit 1000StartServers 30MinSpareServ

搭建 CentOS 6 服务器(14) - squid、Varnish

(一)squid 安装 Java代码   # yum install httpd-tools -y # htpasswd -c -b /etc/squid/passwords squiduser 123456 # yum install squid -y 设置 Java代码   # cp /etc/squid/squid.conf /etc/squid/squid.conf.bak # vi /etc/squid/squid.conf auth_param basic program /usr/

搭建 CentOS 6 服务器(2) - Linux常用命令

(1)文件/文件夹 pwd - 显示当前路径 Shell代码   $ pwd cd - 跳到指定文件夹 Shell代码   $ cd /usr/local/src $ cd ~/ ←移动到用户的home ls - 显示当前文件夹下自己能看到的所有文件/文件夹一览 Shell代码   $ ls ←显示文件名 $ ls -l ←显示详细信息 $ ls -a ←显示隐藏文件 $ ls -t ←按做成时间降序显示 $ ls -l /usr/src/test/ ←显示指定文件夹的信息 mkdir - 创建

搭建 CentOS 6 服务器(12) - Samba

(1)安装 Java代码   # yum -y install samba Installed: samba.i686 0:3.6.9-169.el6_5 # pdbedit -a rensn new password:123456 retype new password:123456 …… (2)Home文件夹 Java代码   # mkdir /etc/skel/samba # mkdir /home/rensn/samba # chown rensn:rensn /home/rensn/s

搭建 CentOS 6 服务器(8) - MySQL、PostgreSQL

(一)MySQL (1)安装 Shell代码   # yum -y install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm # yum info mysql-community-server # yum -y install mysql-community-server # vi /etc/my.cnf character-set-server=utf8 # /etc/init.d/mysqld rest