美文网首页
安装nginx脚本

安装nginx脚本

作者: 黑客不黑_ | 来源:发表于2019-04-15 09:08 被阅读0次
    #!/bin/bash
    
    #================================================================
    #   Copyright (C) 2019  All rights reserved.
    #   
    #   File::nginx_install.sh
    #   Author:RoES
    #   Date:2019/04/12
    #   Description:install nginx
    #
    #================================================================
    
    dir=/home/data
    nginx_download_path="http://nginx.org/download/nginx-1.8.0.tar.gz"
    nginx_install_dir="/usr/local/nginx"
    nginx_name="nginx-1.8.0.tar.gz"
    
    [ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1
    
    # create file download dir
    create_dir(){
      if [ ! -e $dir ]
        then
          mkdir $dir
      else
        echo "file download dir is exit!"
      fi
    }
    
    # install nginx-1.8.0
    install_nginx(){
      # yum install something
      wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
      yum install -y pcre pcre-devel openssl openssl-devel gcc make gcc-c++
      # download nginx
      [ -e $dir ] && cd $dir
      wget $nginx_download_path
      if [ -f $nginx_name ]
        then
          echo 'nginx download success'
          # tar nginx
          tar zxf $nginx_name && cd nginx-1.8.0
          # add user nginx
          useradd nginx -s /sbin/nologin -M
          # install nginx
          ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
          [ $(echo $?) -eq 0 ] && make && make install
          [ $(echo $?) -eq 0 ] && echo "nginx install success"    
      fi
    }
    # start nginx
    start_nginx(){
     # check syntax
     $nginx_install_dir/sbin/nginx -t 
     # start
     if [ $(echo $?) -eq 0 ]
       then
         $nginx_install_dir/sbin/nginx
         if [ $(netstat -lutnp|grep 80|wc -l) -eq 1 ]
           then
             action "nginx starting success..."  /bin/true
         else
             echo "nginx starting fail,plaese check the service!"
         fi
     fi
    }
    
    # main function
    main(){
       #create dir
       create_dir
       # install
       install_nginx
       sleep 3
       # start
       start_nginx
       sleep 2
    }
    main
    

    相关文章

      网友评论

          本文标题:安装nginx脚本

          本文链接:https://www.haomeiwen.com/subject/tseywqtx.html