SHELL編寫NGINX自動部署腳本

来源:http://www.cnblogs.com/XuHoo/archive/2016/09/28/5917069.html
-Advertisement-
Play Games

1、功能描述 1. 安裝支持包,從軟體源下載自定義的NGINX包,創建NGINX用戶和用戶組。 2. 安裝並初始化NGINX配置。 3. 運行NGINX並檢測運行狀態。 2、實現 源碼如下: ...


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 1

function 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 1

function 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 1

function 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 1

function 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

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Configure Amazon RDS mysql to store Chinese Characters https://dev.mysql.com/doc/refman/5.7/en/charset-applications.html http://docs.aws.amazon.com/AW ...
  • 本文重點介紹在Ubuntu中使用apt-get安裝LAMP(Ubuntu 16.04,Apache2.4.18,mysql5.7.12,php7.0.4)環境,所以不再介紹如何安裝Ubuntu。 安裝Apache: 查看Apache版本: 上面信息說明Apache安裝成功,通過瀏覽器訪問Apache ...
  • Intro Sometime we want to record cmd and outputs in the interactive shell sessions. However history cmd cannot do this. So we need cmd line recording ...
  • 其實還是這個老問題: 記一次文件下載丟包填坑之旅 http://www.cnblogs.com/syjkfind/p/5281677.html 即使現在只有haproxy-nginx-磁碟文件 比較少的轉發,但文件特別大,還是偶有文件不完整的問題。 從現象上看,瀏覽器響應是200沒問題,curl命令 ...
  • 介紹 本篇文章主要介紹sudo配置和用法,為了給某個用戶控制許可權比如執行某個命令或者關機操作等,伺服器管理員通常會給這個用戶配置sudo,接下來就來詳細介紹具體的配置方法。 環境:centos6.7 結構說明 可以通過編輯文件/etc/sudoers來配置,通常使用visudo命令來進行修改,因為如 ...
  • 首先貼出出錯提示信息: jello@kali:/usr/local/arm/2.95.3/bin$ arm-linux-arm-linux-addr2line arm-linux-gasp arm-linux-protoizearm-linux-ar arm-linux-gcc arm-linux- ...
  • 介紹 我們的生產伺服器經常會做raid存儲,但是單單做了raid就能保證性能高效和數據安全嗎?答案是否定的,我們一般建議使用帶電池保護的RAID卡,這樣既能保證性能有能保證數據安全,但是也需要經常對電池進行維護;由於成本原因一般的RAID卡會使用鋰電池,因為鋰電池有較強的惰性,它在非充電狀態下會緩慢 ...
  • 本來申請這個博客是為了寫一些Java學習筆記的,但是鑒於我半年內無數次重裝系統的慘痛經歷,所以把win10系統的一些問題總結一些 1.win10取消開機密碼: http://jingyan.baidu.com/article/90bc8fc87bd7e3f652640c49.html 2.讓打開圖片 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...