• shell自动化下载、安装、配置nginx


    #!/bin/bash
    auto config nginx server 
    #by author www.jfedu.net
    #2018年5月14日17:25:52
    
    N_PAR="vim lrzsz perl perl-devel libxml2 libxml2-devel ncurses ncurses-devel gd gd-deve
    l wget gcc gcc-c++ pcre pcre-devel ntp ntpdate openssl openssl-devel"
    N_URL="http://nginx.org/download/nginx-1.14.0.tar.gz"
    N_DIR="nginx-1.14.0.tar.gz"
    N_PATH="nginx-1.14.0"
    N_PREFIX="/usr/local/nginx"
    N_VHOST=$1
    
    if [ -d $N_PREFIX ];then
        echo -e "33[32mThe nginx server already installd ,please exit.33[0m"
        read -p "Enter the number of installd users:" lists
        service iptables stop
        setenforce 0
        systemctl stop firewalld
        ps -ef |grep nginx
        mkdir -p $N_PREFIX/conf/domains
        mkdir -p $N_PREFIX/html/$lists
    cat >$N_PREFIX/html/$lists/index.html<<EOF
        <html>
         <h1> The first test nginx page.<h1>
         <h1> The www.$lists.com test page.<h1>
        <hr color="red">
        </html>
    EOF
    cat >$N_PREFIX/conf/nginx.conf<<EOF
        worker_processes  1;
        events {
            worker_connections  1024;
        }
        http {
            include       mime.types;
            default_type  application/octet-stream;
            sendfile        on;
            keepalive_timeout  65;
            include   domains/*;
        }
    EOF
    cat >$N_PREFIX/conf/domains/www.$lists.com<<EOF
         server {
                listen       80;
                server_name  www.$lists.com;
                location / {
                    root   html/$lists;
                    index  index.html index.htm;
                }
            }
    EOF
    $N_PREFIX/sbin/nginx -t
    if [ $? -eq 0 ];then
            pkill nginx
            $N_PREFIX/sbin/nginx
    else
            echo -e "33[32m Please check nginx config file33[0m"
            exit
    fi
    else
        echo -e "33[32m Please install nginx server 33[0m"
        yum install -y $N_PAR
        ntpdate 1.cn.pool.ntp.org
        cd /usr/src
        wget -c $N_URL
        tar xzf $N_DIR
        cd $N_PATH
        ./configure --prefix=$N_PREFIX --with-http_ssl_module --with-pcre 
    if [ $? -eq 0 ];then
        make && make install
        echo -e "33[32m The nginx server install successfully.33[0m"
    else
        echo -e "33[32m The nginx server install failed,please check33[0m"
        exit
    fi
        ln -s $N_PREFIX/sbin/nginx /usr/local/sbin
        $N_PREFIX/sbin/nginx -t
    if [ $? -eq 0 ];then
        $N_PREFIX/sbin/nginx -s reload
    else
        echo -e "33[32m Please check nginx config file33[0m"
        exit
    fi
    
    read -p "Enter the number of installd users:" lists
        service iptables stop 
        setenforce 0
        systemctl stop firewalld
        ps -ef |grep nginx
        mkdir -p $N_PREFIX/conf/domains
        mkdir -p $N_PREFIX/html/$lists
    cat >$N_PREFIX/html/$lists/index.html<<EOF
        <html>
         <h1> The first test nginx page.<h1>
         <h1> The www.$lists.com test page.<h1>
        <hr color="red">
        </html>
    EOF
    cat >$N_PREFIX/conf/nginx.conf<<EOF
        worker_processes  1;
        events {
            worker_connections  1024;
        }
        http {
            include       mime.types;
            default_type  application/octet-stream;
            sendfile        on;
            keepalive_timeout  65;
            include   domains/*;
    }
    EOF
    cat >$N_PREFIX/conf/domains/www.$lists.com<<EOF
         server {
                listen       80;
                server_name  www.$lists.com;
                location / {
                    root   html/$lists;
                    index  index.html index.htm;
                }
            }
    EOF
        $N_PREFIX/sbin/nginx -t
    if [ $? -eq 0 ];then
        pkill nginx
            $N_PREFIX/sbin/nginx 
    else
            echo -e "33[32m Please check nginx config file33[0m"
            exit
    fi
    fi
    
    
    
  • 相关阅读:
    语句被终止。完成执行语句前已用完最大递归 100
    Sql日期时间格式转换(转)
    MVC 记录操作日志与过滤特殊字符
    掌握这些,自学效率嗖嗖的!
    正式开始聊聊自学那些事儿!
    《可执行的自学编程方法体系》前言-为什么我要分享自己的自学经验总结?
    系统化的学习才是有效的学习!
    知识学了就忘怎么办?
    “面试”是绝佳的学习方式!
    分水岭:知识的深度拓展
  • 原文地址:https://www.cnblogs.com/jpfss/p/9717303.html
Copyright © 2020-2023  润新知