码迷,mamicode.com
首页 > 其他好文 > 详细

centos7.3系统的初始化脚本

时间:2017-12-13 19:36:50      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:reboot   let   usr   boot   security   ati   linu   ble   gpo   

#!/bin/bash
#
#authentication
if    [ `whoami` != "root" ]
then    echo "please run this script as root." >&2
    exit 1
fi
echo    -e "\033[31m system initialization script, only support CentOS-7-x86_64 \033[0m"
echo    -e "\033[31m please run carefully,press ctrl+C to cancel \033[0m"
sleep    5

#set date
date(){
if    [ `date +%z` != "+0800" ]
then    timedatectl set-timezone Asia/Shanghai
 if    [ `date +%z` != "+0800" ]
 then    echo "Shanghai time zone set fail "
    timedatectl set-timezone Asia/Chongqing
  if    [ `date +%z` != "+0800" ]
  then    echo -e "\033[31m Chongqing time zone set fail \033[0m"
    echo -e "\033[31m please manual setting \033[0m"
  fi
 fi
fi
yum -y install ntp
/usr/sbin/ntpdate cn.ntp.org.cn &>/dev/null
/usr/sbin/hwclock -w &>/dev/null
cat >> /etc/crontab <<EOF
*/10 * * * * root /usr/sbin/ntpdate cn.ntp.org.cn &>/dev/null
* * * * */1 root /usr/sbin/hwclock -w &>/dev/null
EOF
echo    "present time: `date`"
echo    -e "\033[31m date set completed \033[0m"
sleep    1
}

#ban kernel update
yum_conf(){
if    [ ! -f /etc/yum.conf.bak]
then    cp /etc/yum.conf /etc/yum.conf.bak
fi
sed    -i /\[main\]/a\exclude=kernel* /etc/yum.conf
cat     /etc/yum.conf | grep "exclude=kernel*"
echo    -e "\033[31m ban kernel update set completed \033[0m "
sleep    1
}

#set limit
limit_config(){
if    [ ! -f /etc/security/limits.conf.bak ] 
then    cp /etc/security/limits.conf /etc/security/limits.conf.bak 
fi
sed    -i /^*.*soft.*nofile.*/d /etc/security/limits.conf
sed    -i /^*.*hard.*nofile.*/d /etc/security/limits.conf
sed    -i /^*.*soft.*nproc.*/d /etc/security/limits.conf
sed    -i /^*.*hard.*nproc.*/d /etc/security/limits.conf
cat >> /etc/security/limits.conf <<EOF
* soft nofile 102400
* hard nofile 102400
* soft nproc 102400
* hard nproc 102400
EOF
cat    /etc/security/limits.conf | grep "^*.*"
echo    -e "\033[31m limit setup completed \033[0m"
sleep    1
}

#disable selinux
selinux(){
if    [ ! -f /etc/selinux/config.bak ]
then    cp /etc/selinux/config /etc/selinux/config.bak
fi
sed    -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config
setenforce 0
getenforce
echo    -e "\033[31m selinux set completed \033[0m"
sleep    1
}

#reboot hotkey
hotkey(){
if    [ ! -f /usr/lib/systemd/system/ctrl-alt-del.target.bak ]
then    cp /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.bak
fi
sed    -i s/^/#/g /usr/lib/systemd/system/ctrl-alt-del.target
cat    /usr/lib/systemd/system/ctrl-alt-del.target
echo    -e "\033[31m hotkey set completed \033[0m"
sleep    1
}

#set SSH login timeout
ssh(){
if    [ ! -f /etc/profile.bak ]
then    cp /etc/profile /etc/profile.bak
fi
echo "TMOUT=300" >>/etc/profile
cat    /etc/profile | grep "TMOUT"
echo    -e "\033[31m SSH timeout set completed \033[0m"
sleep    1
}

#ban root ssh login permission
sshd_cofig(){
if    [ ! -f /etc/ssh/sshd_config ]
then    cp /etc/ssh/sshd_config  /etc/ssh/sshd_config.bak 
fi
sed    -i s/#PermitRootLogin.*/PermitRootLogin no/ /etc/ssh/sshd_config
systemctl reload sshd
echo    -e "\033[31m bin root ssh login set completed \033[0m"
sleep    1
}

 

centos7.3系统的初始化脚本

标签:reboot   let   usr   boot   security   ati   linu   ble   gpo   

原文地址:http://www.cnblogs.com/hyc-blog/p/8034124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!