添加 centos.sh

This commit is contained in:
zwb 2024-10-22 12:08:37 +08:00
parent 1741af7189
commit 519791e6c1
1 changed files with 81 additions and 0 deletions

81
centos.sh Normal file
View File

@ -0,0 +1,81 @@
#!/usr/bin/bash
list(){
echo "--------------------------------------"
echo "------------性能优化工具箱------------"
echo "------------1.更换YUM源---------------"
echo "------------2.关闭防火墙--------------"
echo "------------3.时间同步----------------"
echo "------------4.创建用户----------------"
echo "------------5.安装软件----------------"
echo "------------6.EXIT--------------------"
}
yuan(){
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo &>/dev/null
yum clean all
yum makecache fast
}
fire(){
systemctl stop firewalld
systemctl disable firewalld
setenforce 0 #临时关闭
sed -ri s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config #永久关闭
}
timed(){
rpm -qa |grep ntpdate
if [ $? -eq 0 ];then
ntpdate ntp.aliyun.com
else
yum -y install ntpdate &> /dev/null
ntpdate ntp.aliyun.com
fi
}
user(){
read -p "请输入你要创建的用户名字:" name
useradd $name
userpasswd=`echo $RANDOM`
echo $userpasswd|passwd --stdin $name &>/dev/null
if [ $? -eq 0 ];then
echo "用户名:$name的密码$userpasswd">>/opt/user.txt
echo "用户创建成功"
else
exit
fi
anzhuang(){
yum -y install vim lsof unzip wget &>/dev/null
}
}
while :
do
list
read -p "请输入您的选项:" num
case $num in
1)
yuan
sleep 3
;;
2)
fire
sleep 3
;;
3)
timed
sleep 3
;;
4)
user
sleep 3
;;
5)
anzhuang
sleep 3
;;
6)
exit
;;
*)
echo "请您按要求输入:(12345)"
;;
esac
done