#!/bin/bash
echo "------设置时区并同步时间------"
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if ! crontab -l |grep ntpdate &>/dev/null ; then
(echo "* 1 * * * ntpdate time.aliyun.com >/dev/null 2>&1";crontab -l) |crontab
fi
echo "------禁用selinux------"
sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
echo "------安装命令补全包------"
yum install -y epel-release &>/dev/null 2>&1
yum install -y bash-completion &>/dev/null 2>&1
echo "------清空firewall防火墙原来所有的规则,只保留ssh------"
cd /etc/firewalld/zones/
echo "" > public.xml
cat >> public.xml << EOF
<zone>
<short>Public</short>
<service name="ssh"/>
</zone>
EOF
firewall-cmd --reload >/dev/null 2>&1
echo "------设置最大打开文件数------"
if ! grep "* soft nofile 65535" /etc/security/limits.conf &>/dev/null; then
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
fi
echo "------设置最大进程数------"
if ! grep "* hard nproc 1204000" /etc/security/limits.conf &>/dev/null; then
cat >> /etc/security/limits.conf << EOF
* hard nproc 1204000
* soft nproc 1204000
EOF
fi
echo "------高并发内核优化------"
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
EOF
echo "------禁止SWAP使用------"
sed -ri 's/.*swap.*/#&/' /etc/fstab
echo "------选择安装常用软件------"
read -p "是否安装常用工具(y|n):" num
case $num in
y|Y|yes|YES|Yes)
yum install -y wget vim net-tools lrzsz &>/dev/null 2>&1
echo "安装完成"
;;
N|n|NO|No|no|nO)
break
;;
*)
echo "请输入正确选项"
exit
;;
esac
echo "------下载阿里云------"
aa="/etc/yum.repo/"
rm -rf $aa*.repo
wget -P $aa http://mirrors.aliyun.com/repo/Centos-7.repo
echo "------清除yum源缓存------"
yum makecache fast &> /dev/null
if [ $? -eq 0 ];then
echo "刷新成功"
fi
#重启之后电脑配置生效
echo "------即将重启电脑------"
read -p "是否重启电脑(y|n):" reboot
case $reboot in
y|Y|yes|YES|Yes)
reboot
;;
N|n|NO|No|no|nO)
echo "稍后手动重启"
;;
*)
echo "请输入正确选项"
exit
;;
esac
添加防火墙端口脚本
#!/bin/bash
echo "------允许iptable的端口------"
ipableport(){
port=$1
protocol=$2
iptables -I INPUT -p $port --dport $protocol -j ACCEPT
service iptables save
}
ipableport(){
}