centos7.3系统的初始化脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.3系统的初始化脚本相关的知识,希望对你有一定的参考价值。

#!/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系统的初始化脚本的主要内容,如果未能解决你的问题,请参考以下文章

分享前端开发常用代码片段

LINUX PID 1和SYSTEMD PID 0 是内核的一部分,主要用于内进换页,内核初始化的最后一步就是启动 init 进程。这个进程是系统的第一个进程,PID 为 1,又叫超级进程(代码片段

收藏|分享前端开发常用代码片段

npm : 无法加载文件 D:softcodeProcess ode ode_global pm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.micr +(代码片段

关于js----------------分享前端开发常用代码片段

常用python日期日志获取内容循环的代码片段