#!/bin/bash

#更换yum源为阿里云源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum makecache

#时间同步
yum -y install ntp
ntpdate ntp1.aliyun.com 
echo  "* */1 * * * /usr/sbin/ntpdate ntp1.aliyun.com" >> /var/spool/cron/root
#命令参数补全命令参数补全
yum -y install bash-completion
#安装epel源
curl -o  /etc/yum.repos.d/epel.repo   http://mirrors.aliyun.com/repo/epel-7.repo
#关闭网卡图形化设置模式
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
systemctl mask NetworkManager.service
#终端超时
# 300秒内，没有任何输入，则自动退出
echo "export TMOUT=600" >> /etc/profile
#保存生效
source /etc/profile
#ssh优化，*关闭SSH反向查询，以加快SSH的访问速度
sed -i 's@UseDNS yes@UseDNS no@' /etc/ssh/sshd_config 
sed -i 's@GSSAPIAuthentication yes@GSSAPIAuthentication no@' /etc/ssh/sshd_config 

systemctl restart sshd

#系统服务优化。关闭不必要的服务。
yum install -y ntsysv > /dev/null
echo 关闭不必要的服务
sleep 5

ntsysv


#内核优化
cat >> /etc/sysctl.conf<<EOF
net.core.wmem_max = 873200
net.core.rmem_max = 873200
net.ipv4.tcp_wmem = 32768 436600 873200
net.ipv4.tcp_rmem = 32768 436600 873200
net.ipv4.tcp_mem = 786432 1048576 1572864
net.core.somaxconn = 256
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_keepalive_time = 240
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_fin_timeout = 30
EOF

#保存生效
sysctl -p  
