CentOS-6.5操作系统环境安装优化
CentOS-6.5操作系统环境优化
1. 设置网络
vi /etc/sysconfig/network-scripts/ifcfg-eth0
2. 配置DNS(上图配置完成后重启网卡DNS会自动写入)
cat /etc/resolv.conf
echo nameserver 114.114.114.114 >/etc/resolv.conf
3. 配置YUM源
备份源配置
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
网易源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum clean all
yum makecache
阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum clean all
yum makecache
4. 安装基础软件
yum -y install tree nmap sysstat gcc gcc-c++ make telnet vim
5. 设置主机名称
vim /etc/sysconfig/network
6. 设置语言环境
备份
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
修改语言环境
echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n
source /etc/sysconfig/i18n
7. 关闭防火墙
/etc/init.d/iptables stop
chkconfig iptables off
8. 关闭SElinux
临时关闭
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
9. 精简开机自启动服务
chkconfig |egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
查看
chkconfig |grep 3:on
10. 配置时间同步
echo "#time sync by oldboy at 2010-2-1" >>/var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1'>>/var/spool/cron/root
11. 内核优化
参考博客:https://www.cnblogs.com/olinux/p/5577767.html
修改打开文件数
vim /etc/security/limits.conf
* soft nofile 65535 * soft nproc 65535 * hard nofile 65535 * hard nproc 65535 |
cd /etc/security/limits.d/
vim 90-nofile.conf
* soft nofile 65535
* hard nofile 65535
|
cat /etc/sysctl.conf
net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.tcp_keepalive_probes = 3 net.ipv4.tcp_keepalive_intvl =15 net.ipv4.tcp_retries2 = 5 net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_max_orphans = 32768 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_wmem = 8192 131072 16777216 net.ipv4.tcp_rmem = 32768 131072 16777216 net.ipv4.tcp_mem = 786432 1048576 1572864 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.ip_conntrack_max = 65536 net.ipv4.netfilter.ip_conntrack_max=65536 net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=180 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 vm.swappiness=10 |
12. 设定操作系统启动级别
老版本
vi /etc/inittab中的id:5:initdefault: 中间的数字是启动级别
新版本
ln -svf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
13. 配置sudo
useradd zqc
cp /etc/sudoers /etc/sudoers.ori
echo "zqc ALL=(ALL) NOPASSWD: ALL">>/etc/sudoers
tail -1 /etc/sudoers
visudo -c
虚拟机克隆网络问题
14. 虚拟机VMware的克隆bug
我们在用虚拟机克隆多台机器,搭建集群环境的时候,可能会出各种各样的bug,比如mac地址冲突,比如网卡无法启动,再比如无法ping通,一切的罪魁祸首都是/etc/udev/rules.d/70-persistent-net.rules这个文件导致的,因此,我们在克隆虚拟机之前一定要:
第一步:
先要清空这个文件。/etc/udev/rules.d/70-persistent-net.rules
第二步:
编辑你的网卡配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0
删除里面两句话,如下图:
注意:有几块网卡就得删掉几块的对应配置文件的HWADDR,UUID。
sed '/^UUID/d;/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0