Practice LNMP full-process Shell programming: if syntax exercises, lnmpshell

Source: Internet
Author: User
Tags mcrypt

Practice LNMP full-process Shell programming: if syntax exercises, lnmpshell

#! /Bin/bash # DATE: wed Jan 17 1 # ywyankerp@163.com # this is a yankerp # The Nginx service is being installedROOT_ID = 0 ML =/usr/local/srcNGINX_ML =/usr/local/src/nginx-1.12.2PML =/usr /local/src/php-5.6.27QD = 'netstat-anpt | grep 80 | awk '{print $7}' | cut-d "/"-f2 | cut-d ": "-f1 'addr = 'IP a | grep eno16777728 $ | awk' {print $2} '| cut-d"/"-f1 'mmm = 'netstat-anput | grep mysqld | awk '{print $4}' | cut -D ":"-f4 'mar = 'rpm-qa | grep mariadb' cd $ ML & {wget http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/nullmv Centos-7.repo/etc/yum. repos. d/Centos-Base.repoyum clean all &>/dev/nullyum makecache &>/dev/null} if [$? -Eq 0] then echo "Yum source update is complete. Start installation !!! "Elseecho" Yum source error "exit 1 fiecho" Yum source configuration successful "if [" $ UID "-eq" $ ROOT_ID "] then echo" root user running "& systemctl stop firewalld & yum install-y gcc-c ++ pcre-devel zlib-devel openssl-devel &>/dev/null else echo "run" exit 1 "as the Root user fiecho "dependency package installation is complete! "Cd $ ML | {echo" failed to enter the directory !!! "Exit 1} wget http://nginx.org/download/nginx-1.12.2.tar.gz &>/dev/null & {tar zxf nginx-1.12.2.tar.gz & groupadd www & useradd-g www-s/sbin/nologin} echo" Nginx package downloaded successfully "cd $ NGINX_ML &&{. /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_mo -- Dule -- with-http_gzip_static_module -- user = www -- group = www &>/dev/null & make install &>/dev/null} if [$? -Eq "0"] then ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin; nginx & echo "Nginx started successfully. Please visit http: // $ ADDR: 80 "else echo" Nginx startup failed !!! "Exit 1fi # Start installing MySQL5.7! Echo "start to download the MySQL binary installation package. Please wait... "if [-z" $ MAR "] then echo" start to install MySQL "fiif [-n" $ MAR "] then rpm-e mariadb-libs -- nodeps & echo" Uninstall mariadb successful! An error occurred while entering the directory of MySQL "ficd $ ML | {echo !!! "Exit 1} wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz &>/dev/null & {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/mysqlcd/usr/local/mysql/& mkdir data & & mkdir log & echo "export PATH = $ PATH: /usr/local/mysql/bin ">/etc/profilesource/etc/profile & groupadd mysql & useradd-r-g mysql-s/bin/f Alse mysql} cat <EOF>/etc/my. cnf [client] socket =/usr/local/mysql. sock [mysqld] basedir =/usr/local/mysql datadir =/usr/local/mysql/data pid-file =/usr/local/mysql/data/mysqld. pid socket =/usr/local/mysql. sock log_error =/usr/local/mysql/log/mysql. errEOFif [! -D/etc/my. cnf] then 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 else echo "error !!! "Fiif [$? -Eq "0"] thenecho "MySQL installation is complete! "Elseecho" MySQL Installation failed !!! "Exit 1fi # PHP install sccessyyum-y install libxml2-devel libcurl-devel openssl-devel bzip2-devel &>/dev/nullif [$? -Eq 0] then echo "dependent package installation successful !!! "Else echo" dependency package installation failed !!! "Ficd $ ML | {echo" failed to enter the directory !!! "Exit 1} wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz &>/dev/null & {tar zxf libmcrypt-2.5.7.tar.gz & cd libmcrypt-2.5.7 /&&. /configure -- prefix =/usr/local/libmcrypt &>/dev/null & make install &>/dev/null} if [$? -Eq 0] then echo "Libmcrypt is successfully installed! "Else echo" Libmcrypt-ERROR! "Exit 1fi # PHP installcd $ ML | {echo" failed to enter the directory !!! "Exit 1} wget http://cn2.php.net/distributions/php-5.6.27.tar.gz &>/dev/null & {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} if [$? -Eq 0] then make &>/dev/null & make install &>/dev/null & echo "PHP compilation and installation is successful. Please wait .... "else echo" PHP installation failed "ficd $ PML | {echo" failed to enter the directory !!! "Exit 1} cp php. ini-production/etc/php. ini & {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} if [$? -Eq 0] then cp/usr/local/php5.6/etc/php-fpm.conf.default/usr/local/php5.6/etc/php-fpm.conf & echo "copy master configuration successful" else echo "PHP permission failed, please try again! "Fiif [! -D/usr/local/php5.6/etc/php-fpm.conf] then sed-I's #; pid = run/php-fpm.pid # G'/usr/local/php5.6/etc/php-fpm.conf sed-I's/listen = 127.0.0.1: 9000/listen = 127.0.0.1: 9000/G'/usr/local/php5.6/etc/php-fpm.conf sed-I's/pm. max_children = 5/pm. max_children = 300/G'/usr/local/php5.6/etc/php-fpm.conf sed-I's/pm. start_servers = 2/pm. start_servers = 20/G'/usr/local/php5.6/et C/php-fpm.conf sed-I's/pm. min_spare_servers = 1/pm. min_spare_servers = 20/G'/usr/local/php5.6/etc/php-fpm.conf sed-I's/pm. max_spare_servers = 3/pm. max_spare_servers = 100/G'/usr/local/php5.6/etc/php-fpm.conf else echo "NONONO" fiif [$? -Eq 0] then systemctl start php-fpm & echo "PHP started successfully" else echo "failed to start PHP" fi # configure nginx to parse phpif [! -D/usr/local/nginx/conf/nginx. conf] then sed-I's/index index.html index.htm;/index. php index.html index.htm;/G'/usr/local/nginx/conf/nginx. conf sed-I's/# root html;/G'/usr/local/nginx/conf/nginx. conf sed-I's/# fastcgi_pass 127.0.0.1: 9000;/fastcgi_pass 127.0.0.1: 9000;/G'/usr/local/nginx/conf/nginx. conf sed-I's/# fastcgi_index index. php;/fastcgi_index index. php;/G'/u Sr/local/nginx/conf/nginx. conf sed-I's * # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; * G'/usr/local/nginx/conf/nginx. conf sed-I's/# include fastcgi_params;/include fastcgi. conf;/G'/usr/local/nginx/conf/nginx. conf sed-I '71d '/usr/local/nginx/conf/nginx. conf & sed-I 'n'; 70a} '/usr/local/nginx/conf/nginx. conf sed-I '65d'/usr/local/nginx/conf/nginx. conf & sed-I 'N; 64 alocation ~ \. Php $ {'/usr/local/nginx/conf/nginx. confelse echo "failed to parse PHP !!! "Fitouch/usr/local/nginx/html/yankerp. phpcat <EOF>/usr/local/nginx/html/yankerp. php
 EOFif [! -D/usr/local/nginx/html/yankerp. php] thennginx-s reload & systemctl restart php-fpmelseecho "test directory file failed" fiwget-O/etc/yum. repos. d/epel. repo http://mirrors.aliyun.com/repo/epel-7.repo &>/dev/null & yum install-y sl &>/dev/nullslif [$? -Eq 0] then echo "LNMP is successfully installed. Please visit http: // $ ADDR/yankerp. php" else echo "Installation failed" fiif [$? -Eq 0] thenecho "LNMP is successfully installed. visit http: // $ ADDR/yankerp. php "elseecho" Installation failed "fi ################################ ######################################## ########################### This is a yankerp ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.