用Monit監(jiān)測(cè)Linux 服務(wù)器
發(fā)布日期:2022-04-26 13:02 | 文章來(lái)源:源碼之家
monit用 Monit 監(jiān)測(cè) linux 服務(wù)器
Monit 是一個(gè)用來(lái)監(jiān)測(cè)系統(tǒng)狀態(tài)的工具,不但可以用來(lái)監(jiān)視進(jìn)程、服務(wù)、文件、目錄、文件系統(tǒng),還可以在服務(wù) down 掉的時(shí)候自動(dòng)重啟服務(wù)或者當(dāng)某個(gè)進(jìn)程占用過(guò)多的資源的時(shí)候自動(dòng)停掉進(jìn)程,并且支持 Email 報(bào)警功能、遠(yuǎn)程服務(wù)器監(jiān)測(cè)、web 管理界面等,功能很多很強(qiáng)大。VPSee 用 monit 來(lái)監(jiān)測(cè)多個(gè) VPS 和獨(dú)立服務(wù)器,如果某個(gè) VPS down 了、某個(gè)服務(wù)器資源緊張,就能第一時(shí)間知道,而且某個(gè)服務(wù)停了的話可以自動(dòng)重啟服務(wù)。
安裝 monit
在 CentOS 下安裝和配置文件:
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# yum install monit
# vi /etc/monit.conf
配置 monit
修改 monit 的配置文件,/etc/monit.conf(CentOS)或者 /etc/monit/monitrc(Debian),每隔120秒檢查一次系統(tǒng),如果 httpd/mysql/sshd 服務(wù)停掉了就重新啟動(dòng)相應(yīng)服務(wù)。對(duì)于 httpd 服務(wù)器,當(dāng)發(fā)現(xiàn) CPU/MEM 占用過(guò)大、loadavg 太高時(shí)就執(zhí)行相應(yīng)的報(bào)警、重啟服務(wù)指令。如果使用 Email 報(bào)警功能,需要配置 Email 地址、郵件服務(wù)器等信息:
set daemon 120
check process sshd with pidfile /var/run/sshd.pid
start program “/etc/init.d/sshd start”
stop program “/etc/init.d/sshd stop”
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = “/etc/init.d/mysqld start”
stop program = “/etc/init.d/mysqld stop”
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
check process nginx with pidfile /var/run/nginx.pid
start program = “/etc/init.d/nginx start”
stop program = “/etc/init.d/nginx stop”
if failed host www.yanghengfei.com port 80 protocol http
then restart
check process php_cgi with pidfile /var/run/php_cgi.pid
start program = “/etc/init.d/php_cgi start”
stop program = “/etc/init.d/php_cgi stop”
if failed host 127.0.0.1 port 9000 then restart
if 5 restarts within 5 cycles then timeout
check process apache with pidfile /var/run/httpd.pid
group www
start program = “/etc/init.d/httpd start”
stop program = “/etc/init.d/httpd stop”
if failed host www.yanghengfei.com port 8080 protocol http
then restart
if cpu is greater than 80% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 512 MB for 5 cycles then restart
if children > 200 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout
更多詳細(xì)信息可以參考配置文件,里面注釋寫得很詳細(xì)。
啟動(dòng) monit
在 CentOS 下啟動(dòng)并加入到系統(tǒng)啟動(dòng)腳本:
# /etc/init.d/monit start
# /sbin/chkconfig monit on
Monit 是一個(gè)用來(lái)監(jiān)測(cè)系統(tǒng)狀態(tài)的工具,不但可以用來(lái)監(jiān)視進(jìn)程、服務(wù)、文件、目錄、文件系統(tǒng),還可以在服務(wù) down 掉的時(shí)候自動(dòng)重啟服務(wù)或者當(dāng)某個(gè)進(jìn)程占用過(guò)多的資源的時(shí)候自動(dòng)停掉進(jìn)程,并且支持 Email 報(bào)警功能、遠(yuǎn)程服務(wù)器監(jiān)測(cè)、web 管理界面等,功能很多很強(qiáng)大。VPSee 用 monit 來(lái)監(jiān)測(cè)多個(gè) VPS 和獨(dú)立服務(wù)器,如果某個(gè) VPS down 了、某個(gè)服務(wù)器資源緊張,就能第一時(shí)間知道,而且某個(gè)服務(wù)停了的話可以自動(dòng)重啟服務(wù)。
安裝 monit
在 CentOS 下安裝和配置文件:
復(fù)制代碼
代碼如下:# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# yum install monit
# vi /etc/monit.conf
配置 monit
修改 monit 的配置文件,/etc/monit.conf(CentOS)或者 /etc/monit/monitrc(Debian),每隔120秒檢查一次系統(tǒng),如果 httpd/mysql/sshd 服務(wù)停掉了就重新啟動(dòng)相應(yīng)服務(wù)。對(duì)于 httpd 服務(wù)器,當(dāng)發(fā)現(xiàn) CPU/MEM 占用過(guò)大、loadavg 太高時(shí)就執(zhí)行相應(yīng)的報(bào)警、重啟服務(wù)指令。如果使用 Email 報(bào)警功能,需要配置 Email 地址、郵件服務(wù)器等信息:
復(fù)制代碼
代碼如下:set daemon 120
check process sshd with pidfile /var/run/sshd.pid
start program “/etc/init.d/sshd start”
stop program “/etc/init.d/sshd stop”
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = “/etc/init.d/mysqld start”
stop program = “/etc/init.d/mysqld stop”
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
check process nginx with pidfile /var/run/nginx.pid
start program = “/etc/init.d/nginx start”
stop program = “/etc/init.d/nginx stop”
if failed host www.yanghengfei.com port 80 protocol http
then restart
check process php_cgi with pidfile /var/run/php_cgi.pid
start program = “/etc/init.d/php_cgi start”
stop program = “/etc/init.d/php_cgi stop”
if failed host 127.0.0.1 port 9000 then restart
if 5 restarts within 5 cycles then timeout
check process apache with pidfile /var/run/httpd.pid
group www
start program = “/etc/init.d/httpd start”
stop program = “/etc/init.d/httpd stop”
if failed host www.yanghengfei.com port 8080 protocol http
then restart
if cpu is greater than 80% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 512 MB for 5 cycles then restart
if children > 200 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout
更多詳細(xì)信息可以參考配置文件,里面注釋寫得很詳細(xì)。
啟動(dòng) monit
在 CentOS 下啟動(dòng)并加入到系統(tǒng)啟動(dòng)腳本:
復(fù)制代碼
代碼如下:# /etc/init.d/monit start
# /sbin/chkconfig monit on
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章