centos 7.x 64位 基础配置脚本
centos 7.x 64位 基础配置脚本
# 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
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
sleep 2
cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
EOF
yum install wget -y
mv -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
if [ $? -eq 0 ]
then
yum clean all
yum makecache
else
echo "替换yum源,不成功请检查!!!"
exit 1
fi
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
read -p "请输入主机名称:" name
hostnamectl set-hostname $name
if [ $? -eq 0 ]
then
echo "主机名修改完成!您的主机名是:$name"
else
echo "主机名修改失败!请检查!"
exit 1
fi
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
EOF
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
#设置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
#升级软件
yum -y update
cat << EOF
+----------------------------------------------------------------------------------------------------------+
| 优化配置完成 |
| 5S后重启服务器! |
+----------------------------------------------------------------------------------------------------------+
EOF
sleep 5
echo -e "\n\033[31m主机开始重启!!!\033[0m\n"
shutdown -r now

浙公网安备 33010602011771号