LNMP一键部署脚本

系列文章目录

`

文章目录

  • 系列文章目录
  • 一、一键部署脚本
  • 总结

一、一键部署脚本

注意:使用时,需更改IP地址,并记住Mysql的登录密码

#!/bin/bash
#/opt/目录下有以下文件即可操作
#mysql-boost-5.7.20.tar.gz  
#nginx-1.22.0.tar.gz  
#php-7.1.10.tar.bz2



systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum -y install expect   

#安装 Nginx 服务
yum -y install pcre-devel zlib-devel gcc gcc-c++ make

useradd -M -s /sbin/nologin nginx

cd /opt
tar zxvf nginx-1.22.0.tar.gz -C /opt/

cd nginx-1.22.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

make -j4 && make install 

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

touch /lib/systemd/system/nginx.service
cat > /lib/systemd/system/nginx.service < my.cnf

cat > /etc/my.cnf <> /etc/profile	
source /etc/profile

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld

/usr/bin/expect < /usr/local/nginx/html/index.php <
EOF

/usr/bin/expect << EOF
spawn mysql -u root -p
expect "password" { send "admin123\r" }
expect "mysql" {send "create database abc;\n"} 
expect "mysql" { send "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';\n" }
expect "mysql" { send "GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';\n" }
expect "mysql" { send "flush privileges;\n" }
expect "mysql" { send "quit;\n" }
expect eof
EOF

cat  /dev/null > /usr/local/nginx/html/index.php 

cat  < /usr/local/nginx/html/index.php
Success!!";
else echo "Fail!!";
?>
EOF

总结

你可能感兴趣的:(php,nginx,服务器)