shell脚本部署lnmp环境
根据别人的脚本改编
#!/bin/bash
menu(){
clear
echo "######################-Menu-#################"
echo "#1.Install Nginx"
echo "#2.Install MySQL"
echo "#3.Install PHP"
echo "#4.Exit Program"
echo "############################################"
}
choice(){
read -p "Please choice a menu[1-4]:" select
}
install_nginx(){
id nginx &> /dev/null
if [ $? -ne 0 ];then
useradd -s /sbin/nologin nginx
fi
if [ -f nginx-1.17.6.tar.gz ];then
tar -xf nginx-1.17.6.tar.gz
cd nginx-1.17.6
yum -y install gcc pcre-devel openssl-devel zlib-devel make
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
conf=/usr/local/nginx/conf/nginx.conf
sed -i '65,71s/#//' $conf
sed -i '/SCRIPT_FILENAME/d' $conf
sed -i 's/fastcgi_params/fastcgi.conf/' $conf
cd ..
/usr/local/nginx/sbin/nginx
echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.php
cat > /usr/local/nginx/html/mysql.php <<"EOF"
<?php
$servername = "localhost";
$username = "root";
$password = "Qwe123..";
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
?>
EOF
else
echo "没有Nginx源码包"
fi
}
install_php(){
yum -y install php php-fpm php-mysql
systemctl restart php-fpm
}
install_mysql(){
if [ -f mysql-5.7.32 ];then
tar -xvf mysql-5.7.32
yum -y install mysql-community-*.rpm
systemctl restart mysqld
systemctl enable mysqld
mysql --connect-expired-password -uroot -p`cat /var/log/mysqld.log|awk '/temporary password/{print $NF}'` << EOF
alter user root@localhost identified by "Qwe123..";
flush privileges;
EOF
else
echo "安装包不存在"
fi
}
while :
do
clear
menu
choice
case $select in
1)
install_nginx;;
2)
install_mysql;;
3)
install_php;;
4)
exit;;
esac
done
还没有评论,来说两句吧...