#########################################################################
# File Name: envconfiguration.sh
# Author: dinmin
# mail: 103482702@qq.com
# this script is only for CentOS 7.x
# Created Time: 2021年11月26日 星期五 14时53分01秒
#########################################################################
#!/bin/bash
function core_check(){
platform=`uname -i`
if [ $platform != "x86_64" ]
then
echo "此脚本只能应用在64位平台系统!"
exit 1
fi
echo "平台OK!"
cat << EOF
+--------------------------------------------+
| your system is CentOS7 X86_64 |
| start optimizing...... |
+--------------------------------------------+
EOF
}
function dns_seetings(){
cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
EOF
}
function yum_source_seetings(){
yum install wget -y
mv -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup http://mirrors.aliyun.com/repo/epel-7.repo
if [ $? -eq 0 ]
then
yum clean all
yum makecache
else
echo "替换yum源,不成功请检查!!!"
exit 1
fi
}
function time_sync(){
yum install ntp -y
/usr/sbin/ntpdate ntp1.aliyun.com
echo "* 4 * * *" /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1" >> /var/spool/cron/root
systemctl restart crond.service
}
function modify_hostname(){
read "请输入主机名称:" name
hostnamectl set-hostname $name
if [ $? -eq 0 ]
then
echo "主机名修改完成!您的主机名是:$name"
else
echo "主机名修改失败!请检查!"
exit 1
fi
}
function file_limit(){
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
EOF
}
function sshd_settings(){
#设置ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes /UseDNS no/' /etc/ssh/sshd_config
sed -i "s/#MaxAuthTries 6/MaxAuthTries 5/" /etc/ssh/sshd_config
sed -i "s/#ClientAliveInterval 0/ClientAliveInterval 900/" /etc/ssh/sshd_config
systemctl restart sshd.service
}
function SELINUX_seetings(){
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
}
function update_soft(){
#升级软件
yum -y update
}
function restart(){
cat << EOF
+------------------------------------------------------------+
| 优化配置完成 |
| 5S后重启服务器! |
+------------------------------------------------------------+
EOF
sleep 5
echo -e "\n\033[31m主机开始重启!!!\033[0m\n"
shutdown -r now
}
function mainmenu(){
cat << EOF
+------------------------------------------------------------+
| 1.主机DNS设置 |
| 2.yum源aliyun设置 |
| 3.同步系统时间设置 |
| 4.修改主机名称 |
| 5.SSHD设置 |
| 6.关闭SELINUX |
| 7.更新所有软件 |
| 8.新服务器一键设置 |
+------------------------------------------------------------+
EOF
}
mainmenu