码迷,mamicode.com
首页 > 其他好文 > 详细

一键搭建LNMP环境

时间:2018-02-27 10:58:12      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:LNMP   linux系统服务   

    #!/bin/bash

    #This Shell Is To Install LNMP
    language(){   #判断环境语言
    echo $LANG |grep -q zh
        if [ $? -eq 0 ];then
        return 0
        else
        return 1
        fi
    }
    error_yum(){
    language
        if [ $? -eq 0 ];then
            clear
            echo
            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            echo "错误:本机YUM不可用,请正确配置YUM后重试."
            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            echo
            exit
        else
            clear
            echo
            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            echo "ERROR:Yum is disable,please modify yum repo file then try again."
            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            echo
            exit
        fi
    }
    #判断本机yum,不可用直接退出脚本!
    #运行脚本请先配置好yum!
    test_yum(){
    repolist=yum repolist 2>/dev/null |awk '/repolist:/{print $2}'|sed 's/,//'
        if [ $repolist -le 0 ];then
        error_yum
        fi
    }
    #安装nginx依赖包
    install_depaned(){
    language
        if [ $? -eq 0 ];then
            echo -en "\033[1;34m正在安装依赖包,请稍后...\033[0m"
        else
            echo -e "\033[1;34mInstalling dependent software,please wait a moment...\033[0m"
        fi
    rpmlist="gcc pcre-devel openssl-devel zlib-devel make"
    for i in $rpmlist
    do
        #判断依赖包是否已经安装
        rpm -q $rpmlist &>/dev/null
        if [ $? -ne 0 ];then
            yum install -y $rpmlist
        fi
    done
    }
    error_nofile(){
    language
    if [ $? -eq 0 ];then
        clear
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo -e "\033[1;34m错误:未找到软件包,请下载软件包至当前目录.\033[0m"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        exit
    else
        clear
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo -e "\033[1;34mERROR:Not found package in current directory, please download it.\033[0m"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        exit
    fi
    }

    #安装nginx
    install_nginx(){
    test_yum
    install_depaned
    nginx_version=nginx-1.8.0
    format1=tar.gz
    #判断用户是否存在
    grep -q nginx /etc/passwd
    if [ $? -ne 0 ];then
        useradd -s /sbin/nologin nginx
    fi
    #当前目录下是否有nginx-1.8.0.tar.gz,无则报错退出脚本
    if [ -f ${nginx_version}.${format1} ];then
        tar -xf ${nginx_version}.${format1}
        cd $nginx_version
        ./configure --prefix=/usr/local/nginx --with-http_ssl_module
        make
        make install
        #作符号连接,可用ngnix启动服务或用nginx -s stop/reload停止重启
        ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
        cd ..
    else
        error_nofile
    fi
    }
    #安装php
    install_php(){
    yum install -y php-mysql php
    #判断当前目录有无此软件包,无则报错退出脚本
    if [ -f php-fpm-5.4.16-36.el7_1.x86_64.rpm ];then
        rpm -ivh php-fpm-5.4.16-36.el7_1.x86_64.rpm
    else
        error_nofile
    fi
    }
    #安装mariadb

    install_mariadb(){
    yum -y install mariadb-server mariadb mariadb-devel
    }
    #启动服务
    service_start(){
    nginx
    systemctl start mariadb
    if [ -f /usr/lib/systemd/system/php-fpm.service ];then
        systemctl start php-fpm.service
    fi    
    }

install_nginx
install_php
install_mariadb
service_start

            

一键搭建LNMP环境

标签:LNMP   linux系统服务   

原文地址:http://blog.51cto.com/13476315/2073346

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!