tools.sh 工具箱主脚本:
#!/bin/bash
while [ 1 -gt 0 ]
do
clear
cat <<EOF
=================================================================
= **工具箱** =
-----------------------------------------------------------------
= =
= 1.mysql service =
= 2.yum install nginx =
= 3.yum insatll php =
= 4.初始化操作 =
= 5.配置本地yum源 =
= 6.退出 =
=================================================================
EOF
read -p "请输入编号:" num
case $num in
1)
sh mysql.sh
;;
2)
systemctl start nginx &>/dev/null | nginx &>/dev/null
ss -nplt | grep "nginx" &>/dev/null
if [ $? -eq 0 ];then
echo "nginx已经安装且已开启"
else
yum -y install nginx &>/dev/null
if [ $? -eq 0 ];then
echo "完成安装nginx服务"
else
echo "nginx安装失败,未成功启动"
fi
fi
read -p"请再次回车"
;;
3)
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm &>/dev/null
yum -y install php74-php-xsl php74-php php74-php-cli php74-php-devel php74-php-gd php74-php-pdo php74-php-mysql php74-php-fpm &>/dev/null
if [ $? -eq 0 ];then
echo "完成安装php服务"
else
systemctl start php74-php-fpm &>/dev/null
ss -nplt | grep php &>/dev/null
if [ $? -eq 0 ];then
echo "php已经安装且开启"
else
echo "php安装失败,未启动成功,此服务待更新敬请期待"
fi
fi
read -p"请再次回车"
;;
4)
sh ini.sh
;;
5)
mkdir /etc/yum.repos.d/localbackup &>/dev/null
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/localbackup &>/dev/null
cd /etc/yum.repos.d && curl -O ftp://10.35.154.3/pub/Ftp-Yum源/local.repo &>/dev/null && yum clean all
yum repolist
echo "本地yum源配置完成"
read -p "请再次回车"
;;
6)
break
exit
;;
*)
echo "请输入现有的工具编号"
read -p "再次敲击回车返回工具箱"
esac
sleep 0.5
done
mysql.sh 附加脚本:
#!/bin/bash
while [ 1 -gt 0 ]
do
clear
cat << EOF
+-------------------------------------------------------+
| **mysql service** |
+-------------------------------------------------------+
| 1.安装mysql(5.7版本) |
| 2.修改root的mysql密码 |
| 3.返回 |
+-------------------------------------------------------+
EOF
read -p "输入需要执行的mysql服务编号:" num
case $num in
1)
yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm &>/dev/null
yum -y install yum-utils &>/dev/null && yum repolist all |grep mysql &>/dev/null && yum-config-manager --disable mysql80-community &>/dev/null && yum-config-manager --enable mysql57-community &>/dev/null && yum install -y mysql-community-server --enablerepo mysql57-community --disablerepo mysql80-community --nogpgcheck &>/dev/null;
if [ $? -eq 0 ];then
echo "完成安装mysql服务"
else
echo "mysql安装失败"
fi
read -p"请再次回车"
;;
2)
code1=`awk '/A temporary password/{p=$NF}END{print p}' /var/log/mysqld.log `
read -p "请输入新密码:" code2
mysqladmin -uroot -p"$code1" password "$code2"
if [ $? -eq 0 ]
then
echo "密码修改成功"
else
ss -nplt | grep "mysqld"
if [ $? -eq 0 ]
then
echo "密码修改失败,请输入符合密码设定规则的密码,包括字母数字和特殊符号"
else
echo "mysql服务未启动,请先启动mysql"
fi
fi
read -p "请再次回车"
;;
3)
break
sh tools.sh
;;
*)
echo "请输入现有的初始化操作对应编号"
read -p "再次敲击回车返回工具箱"
;;
esac
done
ini.sh 附加脚本:
#!/bin/bash
while [ 1 -gt 0 ]
do
clear
cat << EOF
+---------------------------------------------------------------+
| **初始化操作** |
+---------------------------------------------------------------+
| 1.关闭防火墙和自启 |
| 2.关闭selinux |
| 3.同步时间 |
| 4.下载基础服务 |
| 5.返回 |
+---------------------------------------------------------------+
EOF
read -p "输入需要执行的初始化操作编号:" num
case "$num" in
1)
systemctl status firewalld |grep running &>/dev/null
if [ $? -eq 0 ];then
systemctl stop firewalld
systemctl disable firewalld
echo "防火墙在运行"
echo "防火墙已永久关闭"
else
systemctl disable firewalld
echo "防火墙未运行"
echo "防火墙已永久关闭"
fi
read -p"请再次回车"
;;
2)
getenforce |grep Enforcing &>/dev/null
if [ $? -eq 0 ];then
echo "selinux已打开"
setenforce 0 echo"selinux临时关闭"
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config &>/dev/null
echo "selinux永久关闭"
else
echo "selinux已临时关闭"
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config &>/dev/null
echo "selinux已永久关闭"
fi
read -p"请再次回车"
;;
3)
ntpdate time.windows.com &>/dev/null
if [ $? -eq 0 ];then
echo "同步时间成功"
else
ping -W1 -c3 baidu.com &>/dev/null
if [ $? -eq 0 ];then
echo "ntpdate服务没安装,先用yum安装"
else
echo "网卡未开启,无网络服务"
fi
fi
read -p"请再次回车"
;;
4)
yum -y install ntpdate vim net-tools wget
echo "安装完成"
read -p"请再次回车"
;;
5)
break
sh tools.sh
;;
*)
echo "请输入现有的初始化操作对应编号"
read -p "再次敲击回车返回工具箱"
;;
esac
done