centos环境配置

本文最后更新于:2 年前

centos环境配置

centos7基础环境
1
2
yum install -y vim ntp rsync
yum install -y telnet bind-utils sysstat net-tools
limit 修改线程数限制
1
2
3
4
5
6
7
8
9
10
11
grep -q 'docker' /etc/security/limits.conf 
if [ $? -ne 0 ];then
tee -a /etc/security/limits.conf << EOF
root - nofile 40960
nginx - nofile 40960
apache - nofile 40960
www - nofile 40960
service - nofile 40960
docker - nofile 40960
EOF
fi
DNS
1
2
3
4
5
cat > /etc/resolv.conf << EOF
options timeout:1 attempts:1
nameserver 10.10.25.4
nameserver 114.114.114.114
EOF
时间同步
1
2
3
4
5
yum install ntp -y
ntpdate time-server.boss.com
sed -i 's/^server 0.centos.pool.ntp.org iburst/server time-server.boss.com/' /etc/ntp.conf
systemctl start ntpd
systemctl enable ntpd
加上本机 hosts 解析
1
2
3
host_name=`hostname`
host_ip=$(ip addr |grep inet | egrep -v 'inet6|docker|br-|127.0.0.1|lo:' | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}' | head -n 1)
grep $host_name /etc/hosts || echo '' >> /etc/hosts && echo "${host_ip} ${host_name}" >> /etc/hosts
TCP优化
1
2
3
4
5
6
7
grep -q 'tcp_fin_timeout' /etc/sysctl.conf
if [ $? -ne 0 ];then
tee -a /etc/sysctl.conf <<-EOF
net.ipv4.tcp_fin_timeout = 30
EOF
sysctl -p
fi