SHELL編寫NGINX自動部署指令碼,shellnginx指令碼

來源:互聯網
上載者:User

SHELL編寫NGINX自動部署指令碼,shellnginx指令碼

1、功能描述

  1. 安裝支援包,從軟體源下載自訂的NGINX包,建立NGINX使用者和使用者組。

  2. 安裝並初始化NGINX配置。

  3. 運行NGINX並檢測運行狀態。

 

2、實現

  源碼如下:

#!/bin/bash# eastmoney public tools# version: v1.0.1# create by XuHoo, 2016-9-28#function environment() {    if [[ "$USER" != "root" ]]; then        echo "Current user is not root"        return 1    fi    yum -y install wget curl pcre pcre-devel zlib zlib-devel gcc gcc-c++ &> /tmp/nginx_install.log    # getUrl: Input download source address    # getUrl='http://172.16.1.1\nginx-1.8.1.tar.gz'    wget -P /tmp/ $getUrl/nginx.tar.gz    grep "nginx" /etc/passwd > /dev/null    if [[ $? -ne 0 ]]; then  # check user and group        groupadd nginx        useradd -M -g nginx -s /sbin/nologin nginx    fi    cd /tmp; tar -zxf nginx.tar.gz; cd nginx    return 0}; environment; [ $? -ne 0 ] && exit 1function install() {    # Compile before installation configuration    ./configure --prefix=/usr/local/nginx \                --user=nginx --group=nginx \                --with-http_stub_status_module \                &> /tmp/nginx_install.log    if [[ $? -ne 0 ]]; then        return 1    else        # make && make install        make &> /tmp/nginx_install.log        make install &> /tmp/nginx_install.log        if [[ $? -ne 0 ]]; then            return 1        fi        return 0    fi}; install; [ $? -ne 0 ] && exit 1function optimize() {    ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ > /dev/null    cp -f /tmp/nginx_control.sh /etc/init.d/nginx    cp -f /tmp/nginx.conf /usr/local/nginx/conf/nginx.conf    # The number of CPU cores current server,    # Amend the "worker_processes" field to the value of the processor    processor=`cat /proc/cpuinfo | grep "processor" | wc -l`    sed -i "s/^w.*;$/worker_processes  ${processor};/g" /usr/local/nginx/conf/nginx.conf    chmod +x /etc/init.d/nginx    chkconfig --add nginx    retval=`chkconfig --level 3 nginx on`  # Configure nginx open start service    return $retval}; optimize; [ $? -ne 0 ] && exit 1function run() {    # Test nginx.conf file syntax is correct    /etc/init.d/nginx test &> /tmp/nginx_run.log    if [[ $? -ne 0 ]]; then        retval=$?    else  # Start nginx server        /etc/init.d/nginx start &> /tmp/nginx_run.log        if [[ $? -ne 0 ]]; then            retval=$?        fi    fi    return 0}; run; [ $? -ne 0 ] && exit 1function check() {    # Modified index.html page content    content=$"deployment on $(date "+%Y-%m-%d %H:%M:%S")"    echo $content > /usr/local/nginx/html/index.html    # View the index.html, and the output of the modified index.html page    /etc/init.d/nginx status    echo -n "Index.html: "; curl http://localhost}; check

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.