shell脚本 一键部署 Lnmp 及社区论坛 服务架构【PHP教程】

!
也想出现在这里? 联系我们
信息

shell脚本 一键部署 Lnmp 及社区论坛 服务架构,第1张

概述shell脚本一键部署Lnmp一键部署Lnmp一键部署注:亲,记得把所需要的软件包,先放到/opt目录中;以及该机子的内存大小、核数先设置好!#!/bin/bash#先配置好yumecho-e"—-正在验证当前为仅主机还是NAT模式—-"ping-c2-w2www.baidu.com&>/devullif[$?-e

shell脚本 一键部署Lnmp 一键部署

Lnmp 一键部署

注:亲,记得把所需要的软件包,先放到/opt目录中;以及该机子的内存大小、核数先设置好!

#!/bin/bash#先配置好yumecho -e \"----正在验证当前为仅主机还是NAT模式----\"Ping -c 2 -w 2 www.baIDu.com &> /dev/nullif [ $? -eq 0 ];then echo -e \"检测当前为NAT模式,为您配置在线yum源\"    mkdir -p /etc/yum.repos.d/repo.bak    mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null    wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null    yum clean all &> /dev/null    yum List &> /dev/null    echo -e \"在线源已配置完成\"else    echo -e \"检测当前为仅主机模式,为您配置本地yum源\"    mount /dev/sr0 /mnt &> /dev/null    cd /etc/yum.repos.d/    mkdir -p /etc/yum.repos.d/repo.bak    mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/nullecho \'[local]name=localbaseurl=file:///mntenabled=1gpgcheck=0\' > /etc/yum.repos.d/local.repoyum clean all &> /dev/nullyum makecache &> /dev/null     df -h | grep \"/mnt\"     if [ $? -ne 0 ];then     echo -e \"检测当前为仅主机模式,但光盘未挂载!\"else     echo -e \"本地yum源已配置完成\"     fifi#接下来,准备安装Nginxsystemctl stop firewalldsystemctl disable firewalldsetenforce 0#安装依赖包yum -y install pcre-devel zlib-devel gcc gcc-c++ make#创建运行用户useradd -M -s /sbin/nologin Nginx#加入模块并编译安装cd /opttar zxvf Nginx-1.12.0.tar.gzcd Nginx-1.12.0/./configure \\--prefix=/usr/local/Nginx \\--user=Nginx \\--group=Nginx \\--with-http_stub_status_modulemake -j4 && make install#优化路径ln -s /usr/local/Nginx/sbin/Nginx /usr/local/sbin/#添加Nginx系统服务echo \'[Unit]Description=NginxAfter=network.target[Service]Type=forkingPIDfile=/usr/local/Nginx/logs/Nginx.pIDExecStart=/usr/local/Nginx/sbin/NginxExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target\' > /lib/systemd/system/Nginx.servicechmod 754 /lib/systemd/system/Nginx.servicesystemctl start Nginx.servicesystemctl enable Nginx.serviceif [ $? = 0 ];thenecho -e \"----Nginx安装完成----\"fi#编译安装MysqLd服务#将安装MysqL所需软件包传到/opt目录下,并解压cd /opttar zxvf MysqL-5.7.17.tar.gztar zxvf boost_1_59_0.tar.gz#安装环境依赖包yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmakeif [ $? = 0 ];thenecho -e \"环境依赖包安装完成\"fi#配置软件模块mv boost_1_59_0 /usr/local/boostcd /opt/MysqL-5.7.17/cmake \\-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \\-DMysqL_UNIX_ADDR=/usr/local/MysqL/MysqL.sock \\-DSYSconfdIR=/etc \\-DSYstemD_PID_DIR=/usr/local/MysqL \\-DDEFAulT_CHARSET=utf8  \\-DDEFAulT_ColLATION=utf8_general_ci \\-DWITH_EXTRA_CHARSETS=all \\-DWITH_INNOBASE_STORAGE_ENGINE=1 \\-DWITH_ARCHIVE_STORAGE_ENGINE=1 \\-DWITH_BLACKHolE_STORAGE_ENGINE=1 \\-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \\-DMysqL_DATADIR=/usr/local/MysqL/data \\-DWITH_BOOST=/usr/local/boost \\-DWITH_SYstemD=1if [ $? = 0 ];thenecho \"模块配置完成\"fi#编译安装make -j4  && make installif [ $? = 0 ];thenecho \"编译安装完成\"fi#创建MysqL用户useradd -M -s /sbin/nologin  MysqL#修改MysqL配置文件echo \'[clIEnt]port = 3306default-character-set=utf8socket=/usr/local/MysqL/MysqL.sock[MysqL]port = 3306default-character-set=utf8socket = /usr/local/MysqL/MysqL.sockauto-rehash[MysqLd]user = MysqLbasedir=/usr/local/MysqLdatadir=/usr/local/MysqL/dataport = 3306character-set-server=utf8pID-file = /usr/local/MysqL/MysqLd.pIDsocket=/usr/local/MysqL/MysqL.sockbind-address = 0.0.0.0skip-name-resolvemax_connections=2048default-storage-engine=INNODBmax_allowed_packet=16Mserver-ID = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_tableS,NO_auto_CREATE_USER,NO_auto_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_divISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES\' > /etc/my.cn#更改MysqL安装目录和配置文件的属主属组chown -R MysqL:MysqL /usr/local/MysqL/chown MysqL:MysqL /etc/my.cnf#设置路径环境变量echo \'export PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH\' >> /etc/profilesource /etc/profile#初始化数据库cd /usr/local/MysqL/bin./MysqLd \\--initialize-insecure \\--user=MysqL \\--basedir=/usr/local/MysqL \\--datadir=/usr/local/MysqL/data#添加MysqL系统服务cp /usr/local/MysqL/usr/lib/systemd/system/MysqLd.service /usr/lib/systemd/system/systemctl daemon-reloadsystemctl start MysqLd.servicesystemctl enable MysqLdnetstat -anpt | grep 3306rpm -q expectif [ $? = 1 ];thenyum -y install expectfisource /etc/profile#修改MysqL登录密码/usr/bin/expect <<EOFspawn MysqLadmin -u root -p password \"123456\"expect \"Enter password:\"send \"\\r\"expect eofEOF#授权远程登录/usr/bin/expect <<EOFspawn MysqL -u root -pexpect \"Enter password:\" {send \"123456\\r\"}expect \"MysqL>\" {send \"grant all privileges on *.* to \'root\'@\'%\' IDentifIEd by \'123456\';\\r\"}expect \"MysqL>\" {send \"show databases;\\r\"}expect \"MysqL>\" {send \"quit\\r\"}expect eofEOFsource /etc/profileecho \"----MysqL安装完成----\"#安装配置 PHP 解析环境#安装环境依赖包yum -y install gd \\libjpeg libjpeg-devel \\libpng libpng-devel \\freetype freetype-devel \\libxml2 libxml2-devel \\zlib zlib-devel \\curl curl-devel \\openssl openssl-devel#解压;添加模块并编译安装cd /opttar jxvf PHP-7.1.10.tar.bz2cd PHP-7.1.10./configure \\--prefix=/usr/local/PHP \\--with-MysqL-sock=/usr/local/MysqL/MysqL.sock \\--with-MysqLi \\--with-zlib \\--with-curl \\--with-gd \\--with-jpeg-dir \\--with-png-dir \\--with-freetype-dir \\--with-openssl \\--enable-fpm \\--enable-mbstring \\--enable-xml \\--enable-session \\--enable-ftp \\--enable-pdo \\--enable-tokenizer \\--enable-zip \\make -j4  && make install#路径优化ln -s /usr/local/PHP/bin/* /usr/local/bin/ln -s /usr/local/PHP/sbin/* /usr/local/sbin/#调整PHP配置文件#PHP有三个配置文件: #PHP.ini        主配置文件  #PHP-fpm.conf   进程服务配置文件 #www.conf       扩展配置文件cp /opt/PHP-7.1.10/PHP.ini-development /usr/local/PHP/lib/PHP.inised -i \'1170c MysqLi.default_socket = /usr/local/MysqL/MysqL.sock\' /usr/local/PHP/lib/PHP.inised -i \'939c date.timezone = Asia/Shanghai\' /usr/local/PHP/lib/PHP.ini#调整进程服务配置文件:cd /usr/local/PHP/etc/cp  PHP-fpm.conf.default PHP-fpm.confsed -i \'17 s/^;//\' /usr/local/PHP/etc/PHP-fpm.conf#调整扩展配置文件:cd /usr/local/PHP/etc/PHP-fpm.d/cp www.conf.default www.conf#启动PHP-fpm/usr/local/PHP/sbin/PHP-fpm -c /usr/local/PHP/lib/PHP.ininetstat -anpt | grep 9000#PHP-FPM(FastCGI Process Manager:FastCGI 进程管理器)是一个 PHPFastCGI 管理器, >由于Nginx服务器不能处理动态页面,需要由 Nginx 把动态请求交给 PHP-fpm 进程进行解析。cd /opt/PHP-7.1.10/sAPI/fpmcp PHP-fpm.service /usr/lib/systemd/system/PHP-fpm.servicesystemctl restart PHP-fpm.service#配置 Nginx 支持 PHP 解析sed -i \'65c location ~ \\.PHP$ {\' /usr/local/Nginx/conf/Nginx.confsed -i \'66c root           HTML;\' /usr/local/Nginx/conf/Nginx.confsed -i \'67c fastcgi_pass   127.0.0.1:9000;\' /usr/local/Nginx/conf/Nginx.confsed -i \'68c fastcgi_index  index.PHP;\' /usr/local/Nginx/conf/Nginx.confsed -i \'69c fastcgi_param  SCRIPT_filename  /usr/local/Nginx/HTML$fastcgi_script_name;\' /usr/local/Nginx/conf/Nginx.confsed -i \'70c include        fastcgi_params;\' /usr/local/Nginx/conf/Nginx.confsed -i \'71c }\' /usr/local/Nginx/conf/Nginx.confsystemctl restart Nginx.service#验证PHP 测试页echo \'<?PHPPHPinfo();?>\' > /usr/local/Nginx/HTML/index.PHPif [ $? = 0 ];thenecho -e \"----PHP已安装完成,请前往测试PHP页面----\"fi#验证数据库工作是否正常#一开始要输入前面设置的MysqL的密码/usr/bin/expect <<EOFspawn MysqL -u root -pexpect \"Enter password:\" {send \"123456\\r\"}expect \"MysqL>\" {send \"CREATE DATABASE bbs;\\r\"}expect \"MysqL>\" {send \"GRANT all ON bbs.* TO \'bbsuser\'@\'%\' IDENTIFIED BY \'admin123\';\\r\"}expect \"MysqL>\" {send \"GRANT all ON bbs.* TO \'bbsuser\'@\'localhost\' IDENTIFIED BY \'admin123\';\\r\"}expect \"MysqL>\" {send \"flush privileges;\\r\"}expect \"MysqL>\" {send \"quit\\r\"}expect eofEOF#截取出IP地址ifconfig | grep \"inet\" | awk \'NR==1 {print }\'echo \'<?PHP$link=MysqLi_connect(\"192.168.116.70\",\"bbsuser\",\"admin123\");if($link) echo \"<h1>Success!!</h1>\";else echo \"Fail!!\";?>\' > /usr/local/Nginx/HTML/index.PHPif [ $? = 0 ];thenecho -e \"----请前往验证数据库工作是否正常----\"fi#部署 discuz!社区论坛 Web 应用cd /opt#解压unzip discuz_X3.4_SC_UTF8.zip  -d /opt/discd /opt/dis/dir_SC_UTF8/cp -r upload/ /usr/local/Nginx/HTML/bbs/#调整论坛目录的权限:cd /usr/local/Nginx/HTML/bbs/chmod -R 777 ./config/chmod -R 777 ./data/chmod -R 777 ./uc_clIEnt/chmod -R 777 ./uc_server/#or#chown -R Nginx ./config/#chown -R Nginx ./data/#chown -R Nginx ./uc_clIEnt/#chown -R Nginx ./uc_server/if [ $? = 0 ];thenecho -e \"----请前往验证社区论坛----\"fi#论坛页面访问#http://192.168.116.70/bbs/install/index.PHPecho -e \"数据库服务器:localhost\\n数据库名字:bbs\\n数据库用户名:bbsuser\\n数据库>密码:admin123\\n管理员账号: admin\\n管理员密码: admin123\"#本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号#访问论坛页面:#http://192.168.116.70/bbs/index.PHP#http://192.168.116.70/bbs/admin.PHP

注:亲,写这种脚本服务架构,建议分开一块块的写以及测试,免得排错排到心态爆炸

总结

以上是内存溢出为你收集整理的shell脚本 一键部署 Lnmp 及社区论坛 服务架构全部内容,希望文章能够帮你解决shell脚本 一键部署 Lnmp 及社区论坛 服务架构所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞51 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容