开发shell脚本检查Nginx实战分享
生活随笔
收集整理的這篇文章主要介紹了
开发shell脚本检查Nginx实战分享
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
開發(fā)shell腳本檢查Nginx實(shí)戰(zhàn)分享
點(diǎn)這里查看視頻講解
一、本腳本實(shí)現(xiàn)功能:
1、自動(dòng)檢查Nginx下面的代理節(jié)點(diǎn)是否正常
2、通過頁面顯示狀態(tài),有問題的節(jié)點(diǎn)給出頁面報(bào)警及聲音報(bào)警。
3、增加新節(jié)點(diǎn),頁面自動(dòng)載入新節(jié)點(diǎn),無需修改程序。
二、守護(hù)檢查腳本
三、相關(guān)文件
status.html.ori
<!doctype?html> <html> <head> <meta?charset="utf-8"> <meta?http-equiv="refresh"?content="5"> <title>Nginx?http?upstream?check?status</title> </head><body> <div?align="center"><table?width="1171"?height="682"?border="1"><tr><td?background="20150516194115.jpg"?><table?align="center"?style="background-color:white"?cellspacing="0"?cellpadding="3"?border="1"><tr?bgcolor="#C0C0C0"><th>Index</th><th>Upstream</th><th>Name</th><th>Status</th></tr></td></tr></table> </div> </body> </html>status.html
<!doctype?html> <html> <head> <meta?charset="utf-8"> <meta?http-equiv="refresh"?content="5"> <title>Nginx?http?upstream?check?status</title> </head><body> <div?align="center"><table?width="1171"?height="682"?border="1"><tr><td?background="20150516194115.jpg"?><table?align="center"?style="background-color:white"?cellspacing="0"?cellpadding="3"?border="1"><tr?bgcolor="#C0C0C0"><th>Index</th><th>Upstream</th><th>Name</th><th>Status</th></tr></td> <tr?bgcolor=#90EE90><th>1</th><th>dynamic_pools</th><th>10.0.0.6:80</th><th>up</th></tr><tr?bgcolor=#90EE90><th>2</th><th>static_pools</th><th>10.0.0.5:80</th><th>up</th></tr><tr?bgcolor=#90EE90><th>3</th><th>static_pools</th><th>10.0.0.6:80</th><th>up</th></tr></tr></table> </div> </body> </html>四、nginx.conf站點(diǎn)配置
worker_processes??1; events?{worker_connections??1024; } http?{include???????mime.types;default_type??application/octet-stream;sendfile????????on;keepalive_timeout??65;include?extra/static_pools;include?extra/dynamic_pools;server?{listen???????80;server_name???www.etiantian.org;location?/?{if?($http_user_agent?~*?"MSIE"){rewrite?^/?http://10.0.0.6/ie.html;??}root???html;index??index.html?index.htm;}location?/image/?{?proxy_pass??http://static_pools;include?proxy.conf;}location?/dynamic/?{proxy_pass??http://dynamic_pools;include?proxy.conf;}} }extra/dynamic_pools包含文件 upstream?dynamic_pools?{server?10.0.0.6:80?weight=5; } extra/static_pools包含文件 upstream?static_pools?{server?10.0.0.5:80?weight=5;server?10.0.0.6:80?weight=5; }站點(diǎn)下健康檢查文件:check.html
ok
五、效果
正常狀態(tài)效果:
報(bào)警效果節(jié)點(diǎn)故障條目變紅,并且有聲音報(bào)警(也可以實(shí)現(xiàn)郵件、短信報(bào)警)
謝謝大家!本文內(nèi)容來自21期學(xué)員張耀!
總結(jié)
以上是生活随笔為你收集整理的开发shell脚本检查Nginx实战分享的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。