zoukankan      html  css  js  c++  java
  • shell脚本一键部署nginx

    一键部署nginx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    #!/bin/bash
    systemctl stop firewalld && setenforce 0
    #首先安装nginx的依赖环境
    yum -y install gcc pcre-devel zlib-devel net-tools wget
    #解压nginx的安装包
    if [ ! -d "/root/nginx-1.16.1" ]; then
             wget http://nginx.org/download/nginx-1.16.1.tar.gz
             tar -zxf nginx-1.16.1.tar.gz
            echo "压缩包已解压"
    else
            echo "此文件已存在"
            continue
    fi
    #进去文件开始检查环境 编译安装
    if [ ! -d /usr/local/nginx ]; then
            cd /root/nginx-1.16.1 && ./configure && make && make install
    else
            continue
    fi
    #判断是否nginx的端口被占用
    pid_file="/usr/local/nginx/logs/nginx.pid"
    if [ ! -e ${pid_file} ]; then
            echo "被占用的pid是:`cat ${pid_file}`"       
            kill `cat ${pid_file}`
            echo "服务被占用,已删掉"
    else
            echo "服务没有被占用"
            continue
    fi
     
    nginx=/usr/local/nginx/sbin/nginx
    #开始启动nginx
    read -p "请输入你接下来要做的操作:" action
    check(){
            netstat -anptu | grep nginx
            if [ $? -eq 0 ];then
                    continue
            fi
    }
    case $action in
            start)
                    netstat -anptu | grep nginx
                    if [ $? -eq 0 ]; then
                            continue
                    else
                            $nginx
                    fi
            ;;
            stop)
                    netstat -anptu | grep nginx
                    if [ $? -eq 0 ]; then
                            echo "nginx-server is already running  nginx-server begin stop"
                            $nginx -s stop
                    else
                            echo "nginx-server is not start"
                    fi
            ;;
            reload)
                    netstat -anptu | grep nginx
                    if [ $? -eq 0 ]; then
                            echo "nginx-server is already running  nginx-server begin reload"
                            $nginx -s reload
                    else
                            echo "nginx-server is not running now begin start nginx-server"
                            $nginx
                            $nginx -s reload
                    fi
            ;;
            statue)
                    check
            ;;
            *)
                    echo "please enter{start|stop|reload|statue}"
            ;;
    esac
    ip=`/sbin/ifconfig -a|awk '{print $2}'|sed -n '2p'`
    code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://${ip}`
    if [ $code -eq 200 ]; then
            echo "nginx-server is ok"
    else
            echo "nginx-server is not ok"
    fi
  • 相关阅读:
    ubuntu安装ActiveMQ
    UTF-8和GBK区别
    MapReduce实现二次排序(温度年份排序)
    MapReduce实现倒排索引
    MapReduce实现多表链接
    MapReduce实现单表链接
    Linux服务器的性能调优实战篇CentOS6最小化安装后的优化
    Linux服务器的性能调优理论篇
    Windows中安装bash Cygwin工具
    shell基础知识
  • 原文地址:https://www.cnblogs.com/xianglei_/p/12072273.html
Copyright © 2011-2022 走看看