博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Centos7下一键安装LNMP环境脚本
阅读量:6503 次
发布时间:2019-06-24

本文共 10126 字,大约阅读时间需要 33 分钟。

#!/bin/bashread -p 'The installation process takes about 5 to 10 minutes, depending on the performance of your server. To confirm the installation of the lnmp environment, press the Enter key.'function red(){    echo -e "\t\033[31m$1\033[0m"}function green(){    echo -e "\t\033[32m$1\033[0m"}yum clean all &> /dev/nullyum -y install epel-release  &> /dev/nullwhile :do    cat /etc/ld.so.conf | grep lib64 &> /dev/null     if [ $? -ne 0 ];then        echo  '''/usr/local/lib/usr/local/lib64/usr/lib/usr/lib64''' >> /etc/ld.so.conf        ldconfig -v &> /dev/null    fi        libzip_stat=`rpm -qa |grep libzip &> /dev/null && echo 'yes' || echo 'no'`        mariadb_stat=`rpm -qa |grep mariadb &> /dev/null && echo 'yes' || echo 'no'`    yum_stat=`yum repolist |tail -1 |awk '{print $2}'`        if [ $libzip_stat = yes ];then                rpm -e --nodeps `rpm -qa | grep libzip`        continue        elif [ $mariadb_stat = yes ];then                rpm -e --nodeps `rpm -qa | grep mariadb`        continue    elif [ $yum_stat = 0 ];then        red 'Yum error,Check your yum source!!!(maybe network,yum configure...)'        exit    else            echo -e "\033[05m\033[35mStart testing the environment...\033[0m"        echo -e "\t\033[32mStart testing the environment...   [ OK ]\033[0m"        break    fi        donefunction need_rpm(){    yum -y install make    yum -y install gmake     yum -y install gcc    yum -y install gcc-c++    yum -y install wget    yum -y install openssl    yum -y install openssl-devel    yum -y install curl    yum -y install curl-devel    yum -y install libjpeg    yum -y install libjpeg-devel    yum -y install libpng    yum -y install libpng-devel    yum -y install freetype    yum -y install freetype-devel    yum -y install pcre    yum -y install pcre-devel    yum -y install libxslt    yum -y install libxslt-devel    yum -y install bzip2    yum -y install bzip2-devel    yum -y install libxml2    yum -y install libxml2-devel}function down_app(){        wget -P /lnmp/ https://nginx.org/download/nginx-1.14.2.tar.gz   &> /dev/null && echo -e "\t\033[32mNginx Download completed!\033[0m" || echo -e "\t\033[31mNginx Download Faild!\033[0m"        wget -P /lnmp/ http://cn2.php.net/get/php-7.3.0.tar.gz/from/this/mirror   &> /dev/null && echo -e "\t\033[32mPHP Download completed!\033[0m" || echo -e "\t\033[31mPHP Download Faild!\033[0m"          wget -P /lnmp/ https://nih.at/libzip/libzip-1.2.0.tar.gz   &> /dev/null && echo -e "\t\033[32mLibzip Download completed!\033[0m" ||  echo -e "\t\033[31mLibzip Download Faild!\033[0m"    wget -P /lnmp/ https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz    &> /dev/null && green 'Mysql Download completed!' || red 'Mysql Download Faild!'}function nginx_install_configure(){    id nginx &> /dev/null && userdel nginx    useradd -M -s /sbin/nologin nginx &>/dev/null    cd /lnmp / && tar -xf nginx-1.14.2.tar.gz && cd nginx-1.14.2/        ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream &>> /tmp/.nginx.configure.log    if [ $? -ne 0 ];then        red 'Nginx configure error!!! See /tmp/.nginx.configure.log'         exit    else        echo ''' Configuration summary:              nginx path prefix: "/usr/local/nginx"               nginx binary file: "/usr/local/nginx/sbin/nginx"               nginx modules path: "/usr/local/nginx/modules"               nginx configuration prefix: "/usr/local/nginx/conf"               nginx configuration file: "/usr/local/nginx/conf/nginx.conf"               nginx pid file: "/usr/local/nginx/logs/nginx.pid"               nginx error log file: "/usr/local/nginx/logs/error.log"               nginx http access log file: "/usr/local/nginx/logs/access.log"               nginx http client request body temporary files: "client_body_temp"               nginx http proxy temporary files: "proxy_temp"               nginx http fastcgi temporary files: "fastcgi_temp"               nginx http uwsgi temporary files: "uwsgi_temp"               nginx http scgi temporary files: "scgi_temp"            '''    fi    make &>> /tmp/.nginx.make.log    if [ $? -ne 0 ];then        red 'Nginx make error!!! See /tmp/.nginx.make.log'    fi    make install &>> /tmp/.nginx.makeinstall.log    if [ $? -ne 0 ];then        red 'Nginx make install error!!! See /tmp/.nginx.makeinstall.log'    fi        cd /usr/local/nginx/    cp -p conf/nginx.conf conf/nginx.conf.bak    sed -i '65,68s/#//g' conf/nginx.conf    sed -i '70,71s/#//g' conf/nginx.conf    sed -i 's/fastcgi_params/fastcgi.conf/g' conf/nginx.conf        green 'Nginx installed and configure successful.'    /usr/local/nginx/sbin/nginx -t &> /dev/null && /usr/local/nginx/sbin/nginx    netstat -nutlp |grep 80 &> /dev/null    if [ $? -ne 0 ];then        red 'Nginx start error!!!'    else        green 'Nginx started.'    fi}function mysql_install_configure(){        id mysql &> /dev/null && userdel mysql        useradd -M -s /sbin/nologin mysql &> /dev/null        cd /lnmp/        tar -xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz        mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql        cd /usr/local/mysql/        mkdir data && chown -R mysql:mysql /usr/local/mysql/        ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize &>> /tmp/.mysql.initialize.log        if [ $? -ne 0 ];then                red 'Mysql initialize error!!! See /tmp/.mysql.initialize.log'    else        pass=`tail -1 /tmp/.mysql.initialize.log | awk '{print $NF}'`        green 'Mysql initialize successful.)'        green  "Initial password: $pass"        echo ''' Configuration summary:              Mysql path prefix: "/usr/local/mysql"              Mysql data path: "/usr/local/mysql/data"            '''        fi        ./support-files/mysql.server start &>> /tmp/.mysql.start.log        netstat -nutlp | grep mysql &> /dev/null        if [ $? -ne 0 ];then                red  'Mysql start error!!! See /tmp/.mysql.start.log'        else                green  'Mysql started.'        fi}function libzip_install_configure(){    cd /lnmp/    tar -xf libzip-1.2.0.tar.gz    cd libzip-1.2.0    ./configure &> /dev/null    make    &> /dev/null    make install    &> /dev/null    cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h    green 'Libzip installed.'}function php_install_configure(){        cd /lnmp/        tar -xf mirror        cd  php-7.3.0/        while :        do                ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip  &>> /tmp/.php.configure.log                if [ $? -ne 0 ];then                        red 'PHP configure error!!! See /tmp/.php.configure.log'                           exit                 else                        green 'PHP configure is ok'                   while :                   do                           make  &>> /tmp/.php.make.log                           if [ $? -ne 0 ];then                                   red 'PHP make error!!! See /tmp/.php.make.log'                                      exit                            else                                   green 'PHP make is ok'                        while :                        do                        cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h                                make install &>> /tmp/.php.makeinstall.log                                if [ $? -ne 0 ];then                                        red 'PHP makeinstall error!!! See /tmp/.php.makeinstall.log'                            exit                                else                                        green 'PHP Installed.'                            break                                fi                        done                    break                           fi                   done            break                fi        done        cp php.ini-development /usr/local/php/lib/php.ini        cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf        cp sapi/fpm/php-fpm /usr/local/bin        sed -i 's/; cgi.fix_pathinfo=1/ cgi.fix_pathinfo=0/g' /usr/local/php/lib/php.ini        groupadd www-data &> /dev/null        useradd -g www-data www-data &> /dev/null        cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf        sed -i 's/user = nobody/user = www-data/g' /usr/local/php/etc/php-fpm.d/www.conf        sed -i 's/group = nobody/group = www-data/g' /usr/local/php/etc/php-fpm.d/www.conf        /usr/local/bin/php-fpm        netstat -nutlp |grep 9000        if [ $? -ne 0 ];then                red 'PHP-FPM start error!!!'        else                green 'PHP-FPM started'        fi}#start executeecho -e "\033[05m\033[35mInstall dependent software...\033[0m"need_rpm &> /dev/nullgreen "Install dependent software...\t\t[ OK ]" echo -e "\033[05m\033[35mStart download apps...\033[0m"down_appecho -e "\033[05m\033[35mStart install nginx and configure it...\033[0m"nginx_install_configureecho -e "\033[05m\033[35mStart install mysql and configure it...\033[0m"mysql_install_configureecho -e "\033[05m\033[35mStart install Libzip and configure it...\033[0m"libzip_install_configureecho -e "\033[05m\033[35mStart install php and configure it...\033[0m"php_install_configure/usr/local/nginx/sbin/nignx -s stop &> /dev/null && /usr/local/nginx/sbin/nginx echo '''
''' >> /usr/local/nginx/html/test.phpcurl http://127.0.0.1/test.phpif [ $? -eq '0'];then green 'LNMP is ok !!!'else red 'Access PHP Faild!!!'fi

转载地址:http://dfqyo.baihongyu.com/

你可能感兴趣的文章
复杂度归纳--小结
查看>>
PHP学习笔记 第八讲 Mysql.简介和创建新的数据库
查看>>
【git】git入门之把自己的项目上传到github
查看>>
js获取鼠标位置
查看>>
2016.8.11 DataTable合并及排除重复方法
查看>>
php 魔术方法 说明
查看>>
Mysql
查看>>
POJ-1860-Currency Exchange
查看>>
跨越企业的“中等收入陷阱”
查看>>
Android 开发者必知的开发资源
查看>>
软件工程技术基础-(软件复用技术)
查看>>
给django视图类添加装饰器
查看>>
简述 clearfix 的原理
查看>>
【Project Euler】530 GCD of Divisors 莫比乌斯反演
查看>>
luogu P1280 尼克的任务 序列DP
查看>>
iphone UIView的一些基本方法理解
查看>>
sys.check_constraints
查看>>
vue问题
查看>>
ThinkPHP 框架学习
查看>>
css3箭头效果
查看>>