Apache狀態監測集重啟

來源:互聯網
上載者:User

標籤:etc   資訊   介面   url   超過   原理   start   www   str   

註:此文摘自:http://www.111cn.net/sys/linux/63718.htm

原理:通過伺服器本地訪問自身Apache服務(與使用者訪問網站類似),如超過15s沒有返回正常的220頭代碼資訊,說明Apache服務已經停止運行了,則立即重啟httpd服務。

1、在Linux伺服器上執行vi編輯一個新指令碼,並把下面指令碼代碼複製進去,然後退出並儲存

  [[email protected] /]# vi /opt/autorshttpd
    #!/bin/bash
    URL="http://127.0.0.1/"
    curlit()
    {
    curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep ‘200‘
    }
    doit()
    {
    if ! curlit; then
    /etc/init.d/httpd restart > /dev/null
    fi
    }
    while true; do
    doit > /dev/null
    sleep 10
    done

2、給指令碼賦予可執行許可權

[[email protected] /]# chmod 755 /opt/autorshttpd

3、執行指令碼

  [[email protected] /]# sh /opt/autorshttpd &

註:在這裡sh命令後面要加個&符號,是為了方便我們遠程SSH操作的,如果不加&符號,那關閉SSH遠程介面,此進程也就隨之結束了,加上&符號,即使關閉SSH遠程也可以讓程式在後台運行,別忘了用exit命令退出登陸後,再關閉SSH遠程介面

4、讓指令碼開機自動運行

  [[email protected] /]# vi /etc/rc.local

  在最後面加上sh /opt/autorshttpd這一行即可。

Apache狀態監測集重啟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.