#!/usr/bin/bash
#机器初始化脚本
#by wangfugui
cat << EOP
是否执行初始化脚本!
请选择
【a/A】DNS安装
【b/B】安装阿里源
【c/C】安装基础工具
【d/D】自动对时
【e/E】永久关闭防火墙
【f/F】内核调优
【g/G】退出
EOP
while :
do
read -p "put :" a
case $a in
a|A)
ping -c1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then
echo "DNS可以解析!"
else
echo "DNS存在问题,正在为您解决!"
cat > /etc/resolv.conf <<EOP
nameserver 114.114.114.114
EOP
echo "解决DNS解析,请查验!"
fi
;;
b|B)
echo "正在为你清理yum源!"
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
echo "阿里源安装完成"
yum -y reinstall epel-release &>/dev/null
echo "拓展源安装"
;;
c|C)
echo "为您安装基本工具!"
yum -y install net-tools vim lsof wget lrzsz-0.12.20-36.el7.x86_64 &>/dev/null
echo "为您安装完成!"
;;
d|D)
echo "正在为您对时!"
yum -y install ntpdate &> /dev/null
ntpdate -u ntp1.aliyun.com &>/dev/null
echo "对时完成!"
;;
e|E)
echo "永久关闭防火墙与selinux!"
systemctl disable firewalld
systemctl stop firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
;;
f|F)
echo "为您进行内核优化!"
cat >> /etc/sysctl.conf << EOP
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time = 120
# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
kernel.sysrq = 1
EOP
cat >> /etc/security/limits.conf << EOP
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
EOP
sysctl -p
echo "优化完成!"
;;
g|G)
exit
;;
*)
echo "请正确输入!"
;;
esac
done
机器初始化
最新推荐文章于 2024-07-17 14:55:21 发布