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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值