Shell编程之if语法练习-实战LNMP全过程

前端之家收集整理的这篇文章主要介绍了Shell编程之if语法练习-实战LNMP全过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. #!/bin/bash
  2. # DATE:Wed Jan 17 1# ywyankerp@163.com
  3. #this is a yankerp
  4.  
  5. # The Nginx service is being installed
  6. ROOT_ID=0
  7. ML=/usr/local/src
  8. Nginx_ML=/usr/local/src/Nginx-1.12.2
  9. PML=/usr/local/src/PHP-5.6.27
  10. QD=`netstat -anpt | grep 80 | awk '{print $7}' | cut -d "/" -f2 | cut -d ":" -f1`
  11. ADDR=`ip a | grep eno16777728$ | awk '{print $2}' | cut -d "/" -f1`
  12. MMM=`netstat -anput | grep MysqLd | awk '{print $4}' | cut -d ":" -f4`
  13. MAR=`rpm -qa | grep mariadb`
  14. cd $ML && {
  15. wget http://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
  16. mv Centos-7.repo /etc/yum.repos.d/Centos-Base.repo
  17. yum clean all &> /dev/null
  18. yum makecache &> /dev/null
  19. }
  20.  
  21. if [ $? -eq 0 ]
  22. then
  23. echo "Yum源更新完毕,开始安装!!!"
  24. else
  25. echo "Yum源error"
  26. exit 1
  27. fi
  28. echo "Yum源配置成功"
  29.  
  30. if [ "$UID" -eq "$ROOT_ID" ]
  31. then
  32. echo "root用户运行中" && systemctl stop firewalld && yum install -y gcc gcc-c++ pcre-devel zlib-devel openssl-devel &> /dev/null
  33. else
  34. echo "请使用Root用户运行"
  35. exit 1
  36. fi
  37. echo "依赖包安装完成!"
  38. cd $ML || {
  39. echo "进入目录失败!!!"
  40. exit 1
  41. }
  42.  
  43. wget http://Nginx.org/download/Nginx-1.12.2.tar.gz &> /dev/null && {
  44. tar zxf Nginx-1.12.2.tar.gz && groupadd www && useradd -g www www -s /sbin/nologin
  45. }
  46. echo "Nginx包下载成功"
  47. cd $Nginx_ML && {
  48. ./configure --prefix=/usr/local/Nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www &> /dev/null && make &> /dev/null && make install &> /dev/null
  49. }
  50.  
  51. if [ $? -eq "0" ]
  52. then
  53. ln -s /usr/local/Nginx/sbin/Nginx /usr/local/sbin ;Nginx && echo "Nginx启动成功,请访问http://$ADDR:80"
  54. else
  55. echo "Nginx启动失败!!!"
  56. exit 1
  57. fi
  58.  
  59.  
  60. #Start installing MysqL5.7!
  61. echo "开始下载MysqL二进制安装包,请稍等..."
  62. if [ -z "$MAR" ]
  63. then
  64. echo "开始安装MysqL"
  65. fi
  66. if [ -n "$MAR" ]
  67. then
  68. rpm -e mariadb-libs --nodeps && echo "卸载mariadb成功!正式安装MysqL"
  69. fi
  70.  
  71. cd $ML || {
  72. echo "进入目录失败!!!"
  73. exit 1
  74. }
  75.  
  76. wget http://mirrors.sohu.com/MysqL/MysqL-5.7/MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz &> /dev/null && {
  77. tar zxf MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz && mv MysqL-5.7.18-linux-glibc2.5-x86_64 /usr/local/MysqL
  78. cd /usr/local/MysqL/ && mkdir data && mkdir log && echo "export PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile
  79. source /etc/profile && groupadd MysqL && useradd -r -g MysqL -s /bin/false MysqL
  80. }
  81.  
  82. cat << EOF >/etc/my.cnf
  83. [client]
  84. socket=/usr/local/MysqL/MysqL.sock
  85. [MysqLd]
  86. basedir=/usr/local/MysqL
  87. datadir=/usr/local/MysqL/data
  88. pid-file=/usr/local/MysqL/data/MysqLd.pid
  89. socket=/usr/local/MysqL/MysqL.sock
  90. log_error=/usr/local/MysqL/log/MysqL.err
  91. EOF
  92.  
  93. if [ ! -d /etc/my.cnf ]
  94. then
  95. chmod 750 data/ && chown -R MysqL . && chgrp -R MysqL . && bin/MysqLd --initialize --user=MysqL && cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd && service MysqLd start &> /dev/null
  96. else
  97. echo "错误!!!"
  98. fi
  99. if [ $? -eq "0" ]
  100. then
  101. echo "MysqL正式安装完成杀青!"
  102. else
  103. echo "MysqL安装失败!!!"
  104. exit 1
  105. fi
  106.  
  107. #PHP install sccessy
  108. yum -y install libxml2-devel libcurl-devel openssl-devel bzip2-devel &> /dev/null
  109. if [ $? -eq 0 ]
  110. then
  111. echo "依赖包安装成功!!!"
  112. else
  113. echo "依赖包安装失败!!!"
  114. fi
  115.  
  116. cd $ML || {
  117. echo "进入目录失败!!!"
  118. exit 1
  119. }
  120.  
  121. wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz &> /dev/null && {
  122. tar zxf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7/ && ./configure --prefix=/usr/local/libmcrypt &> /dev/null && make &> /dev/null && make install &> /dev/null
  123. }
  124.  
  125. if [ $? -eq 0 ]
  126. then
  127. echo "Libmcrypt安装成功!"
  128. else
  129. echo "Libmcrypt-ERROR!"
  130. exit 1
  131. fi
  132. # PHP install
  133. cd $ML || {
  134. echo "进入目录失败!!!"
  135. exit 1
  136. }
  137. wget http://cn2.PHP.net/distributions/PHP-5.6.27.tar.gz &> /dev/null && {
  138. tar zxf PHP-5.6.27.tar.gz && cd PHP-5.6.27/ && ./configure --prefix=/usr/local/PHP5.6 --with-MysqL=MysqLnd --with-pdo-MysqL=MysqLnd --with-MysqLi=MysqLnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/PHP.d --with-bz2 --enable-maintainer-zts &> /dev/null
  139. }
  140. if [ $? -eq 0 ]
  141. then
  142. make &> /dev/null && make install &> /dev/null && echo "PHP编译安装成功,正在配置请稍等...."
  143. else
  144. echo "PHP安装失败"
  145. fi
  146.  
  147. cd $PML || {
  148. echo "进入目录失败!!!"
  149. exit 1
  150. }
  151. cp PHP.ini-production /etc/PHP.ini && {
  152. cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm && chmod +x /etc/init.d/PHP-fpm && chkconfig --add PHP-fpm && chkconfig PHP-fpm on
  153. }
  154.  
  155. if [ $? -eq 0 ]
  156. then
  157. cp /usr/local/PHP5.6/etc/PHP-fpm.conf.default /usr/local/PHP5.6/etc/PHP-fpm.conf && echo "复制主配置成功"
  158. else
  159. echo "PHP权限失败,请重试!"
  160. fi
  161.  
  162. if [ ! -d /usr/local/PHP5.6/etc/PHP-fpm.conf ]
  163. then
  164. sed -i 's#;pid = run/PHP-fpm.pid#pid = run/PHP-fpm.pid#g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  165. sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9000/g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  166. sed -i 's/pm.max_children = 5/pm.max_children = 300/g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  167. sed -i 's/pm.start_servers = 2/pm.start_servers = 20/g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  168. sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 20/g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  169. sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 100/g' /usr/local/PHP5.6/etc/PHP-fpm.conf
  170. else
  171. echo "NONONO"
  172. fi
  173. if [ $? -eq 0 ]
  174. then
  175. systemctl start PHP-fpm && echo "PHP启动成功"
  176. else
  177. echo "启动PHP失败"
  178. fi
  179.  
  180. #配置Nginx解析PHP
  181. if [ ! -d /usr/local/Nginx/conf/Nginx.conf ]
  182. then
  183. sed -i 's/index index.html index.htm;/index index.PHP index.html index.htm;/g' /usr/local/Nginx/conf/Nginx.conf
  184. sed -i 's/# root html;/ root html;/g' /usr/local/Nginx/conf/Nginx.conf
  185. sed -i 's/# fastcgi_pass 127.0.0.1:9000;/ fastcgi_pass 127.0.0.1:9000;/g' /usr/local/Nginx/conf/Nginx.conf
  186. sed -i 's/# fastcgi_index index.PHP;/ fastcgi_index index.PHP;/g' /usr/local/Nginx/conf/Nginx.conf
  187. sed -i 's*# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;* fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;*g' /usr/local/Nginx/conf/Nginx.conf
  188. sed -i 's/# include fastcgi_params;/ include fastcgi.conf;/g' /usr/local/Nginx/conf/Nginx.conf
  189. sed -i '71d' /usr/local/Nginx/conf/Nginx.conf && sed -i 'N;70a}' /usr/local/Nginx/conf/Nginx.conf
  190. sed -i '65d' /usr/local/Nginx/conf/Nginx.conf && sed -i 'N;64alocation ~ \\.PHP$ {' /usr/local/Nginx/conf/Nginx.conf
  191. else
  192. echo "解析PHP失败!!!"
  193. fi
  194.  
  195. touch /usr/local/Nginx/html/yankerp.PHP
  196. cat << EOF >/usr/local/Nginx/html/yankerp.PHP
  197. <?PHP
  198. PHPinfo();
  199. ?>
  200. EOF
  201.  
  202. if [ ! -d /usr/local/Nginx/html/yankerp.PHP ]
  203. then
  204. Nginx -s reload && systemctl restart PHP-fpm
  205. else
  206. echo "测试目录文件失败"
  207. fi
  208. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo &> /dev/null && yum install -y sl &> /dev/null
  209. sl
  210. if [ $? -eq 0 ]
  211. then
  212. echo "LNMP安装成功,请您访问http://$ADDR/yankerp.PHP"
  213. else
  214. echo "安装失败"
  215. fi
  216.  
  217. if [ $? -eq 0 ]
  218. then
  219. echo "LNMP安装成功,请您访问http://$ADDR/yankerp.PHP"
  220. else
  221. echo "安装失败"
  222. fi
  223. ###################################################################################################This is a yankerp~

猜你在找的Bash相关文章