系统初始化脚本

#!/usr/bin/bash
dns(){
        echo "正在配置DNS服务器地址.."
        cat > /etc/resolv.conf << EOF
# Generated by NetworkManager
nameserver  8.8.8.8
nameserver 114.114.114.114
EOF
    sleep 1
    echo "DNS配置完成"
}

repo(){
    echo "正在更换国内源及epel源.."
    rm -rf /etc/yum.repos.d/* &>/dev/null
    yum clean all &>/dev/null
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
    echo "系统源更换完成,epel源正在安装..."
    yum -y remove epel* &>/dev/null
    yum -y install epel-release &>/dev/null
    echo "系统源、epel源安装成功"
}

bash(){
    echo "正在安装常用软件.."
    yum -y install net-tool vim rz lsof wget unzip ntpdate tree bash-completion &>/dev/null
    read -p "是否进行升级内核及软件 [y/n]" num
    echo "升级速度依据网速快慢决定..   耐心等待.."
    if [ "${num}" = "y" ];then
    yum -y update &>/dev/null
    fi
}

ntp(){
    echo "正在进行ntp自动对时.."
    ntpdate -u ntp1.aliyun.com &>/dev/null
    sleep 1
    echo "自动对时成功"
}

filwd(){
    echo "正在关闭防火墙.."
    sleep 1
    systemctl stop firewalld.service &>/dev/null
    echo "正在关闭防火墙的开机自启.."
    sleep 1
    systemctl disable firewalld &>/dev/null
    echo "正在关闭Selinux.."
    sleep 1
    sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config &>/dev/null
    setenforce 0  &>/dev/null
    echo "防火墙与Selinux已关闭,重启使配置生效!"
}

sysctl(){
    echo "正在正在进行系统内核调优.."
    cat >  /etc/sysctl.conf << EOF
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
EOF

    cat > /etc/security/limits.conf << EOF
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
EOF
    sleep 2
    echo "系统初始化完成,是否重启机器加载配置文件!"
    read -p "是否立即重启 [y/n]   " num
    if [ "${num}" = "y" ];then
         reboot
    fi
    echo "To cancel the restart"
    echo "取消重启"
    echo "End"
    exit
}

cat <<-EOF

  +--------------------------------------------------+
  |          N e k o    系 统 初 始 化  	     |
  |						     |
  |	 [a] 配置DNS服务器地址                       |
  |	 [b] 下载国内源并自动安装epel源              |
  |	 [c] 安装常用软件			     |
  |	 [d] NTP自动对时			     |
  |	 [e] 永久关闭防火墙及临时关闭selinux 	     |
  |	 [f] 系统内核一键优化			     |
  |	 [g] 一键执行所有   			     |
  |						     |
  | [q] 退出			      by: Nekoosu    |
  +--------------------------------------------------+
EOF
while :
do
read -p "

请输入字母开始执行: " choice
case $choice in
a|A)
    dns
    ;;
b|B)	
    repo
    ;;
c|C)
    bash
    ;;
d|D)
    ntp
    ;;
e|E)
    filwd
    ;;
f|F)
    sysctl
    ;;
g|G)
    read -p "正在进行机器初始化,是否继续? [y/n]  " repos
    case $repos in
    Y|y) 
    dns
        sleep 1
    repo
        sleep 1
    bash
        sleep 1
    ntp
        sleep 1
    filwd
        sleep 1
    sysctl
        sleep 1
    esac
    ;;
q|Q)
    exit
    ;;
*)
    echo "输入错误,正在退出..."
    sleep 3
    exit
esac
done


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值