linux-系统初始化shell脚本

#!/bin/bash

iotmpuser='iotmp'
scriptname=$0
timedate=`date +%Y-%m-%d_%H:%M:%S`

if [ `id -u` -eq 0 ];then
    echo "Current User is root"
else
    echo "Current User is not root,Please Use root"\n
    echo "You can: su - or sudo ./$scriptname"\n
    exit
fi

cp -rf /etc/ssh/ssh_config /etc/ssh/ssh_config_bak
sed -i '/StrictHostKeyCheckin/d' /etc/ssh/ssh_config
sed -i '$aStrictHostKeyChecking no' /etc/ssh/ssh_config

cp -rf /etc/security/limits.d/20-nproc.conf /etc/security/limits.d/20-nproc.conf.bak-"$timedate" 
echo "* soft nproc 65536" > /etc/security/limits.d/20-nproc.conf
echo "root soft nproc unlimited" >> /etc/security/limits.d/20-nproc.conf

cp -rf /etc/security/limits.conf /etc/security/limits.conf.bak-"$timedate"
echo '* soft nofile 65536' > /etc/security/limits.conf
echo '* hard nofile 65536' >> /etc/security/limits.conf
echo '* soft nproc 65536' >> /etc/security/limits.conf
echo '* hard nproc 65536' >> /etc/security/limits.conf

setenforce 0
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

echo "ulimit -n 65536" >> /etc/rc.local
echo "ulimit -u 65536" >> /etc/rc.local

systemctl stop firewalld
systemctl disable firewalld

cp -rf /etc/sysctl.conf /etc/sysctl.conf.bak-"$timedate"
echo '' > /etc/sysctl.conf
cat > /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.pid_max = 99999
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.route.gc_timeout = 100
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_max_orphans = 204800
net.ipv4.tcp_retries2 = 2
net.core.somaxconn = 204800
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_max_syn_backlog = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 300
net.ipv4.ip_local_port_range = 1024     65535
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380   4194304
net.ipv4.tcp_wmem = 4096        16384   4194304
vm.max_map_count=655360
EOF

sysctl -p

cp -rf /etc/yum.repos.d /etc/yum.repos.d.bak-"$timedate"

rm -rf /etc/yum.repos.d/*

cat > /etc/yum.repos.d/ftp.repo << EOF
[ftp]
name=ftp
baseurl=ftp://192.168.8.88/centos7
enable=1
gpgcheck=0
EOF

#创建用户与密码

id $iotmpuser > /dev/null 2>&1
if [ $? -eq 0 ];then
    echo "$iotmpuser is exist,It's not create"
else
    useradd -m iotmp 
    echo 123456 | passwd --stdin iotmp
    #sed -i '"$iotmpuser" ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
    echo "$iotmpuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
fi

yum install gcc -y

echo "$iotmpuser was create Complete"\n
echo "Servers was Initialize Complete,it must reboot"

read -p "Are you sure reboot the server,Please input 'yes/no':" input

while true
    do
        if [ "$input" == "yes" ];then
            reboot
        elif [ "$input" == "no" ];then
            echo "the server isn't reboot,Initialize Does not take effect until the restart"
            break
        else
            echo "You input Error,Please Input 'yes/no'"
            read -p "Are you sure reboot the server,Please input 'yes/no':" input
            continue
        fi
    done

 

posted @ 2019-07-29 15:51  虫儿飞_mustartk  阅读(291)  评论(0)    收藏  举报