2013年6月1日 星期六

CentOS 6.4 monit Install (CentOS 6.4 安裝 monit 監控)

yum install monit


http://pkgs.repoforge.org/monit/  

Downloading Packages:
monit-5.1.1-4.el6.i686.rpm                                                                                                            | 230 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : monit-5.1.1-4.el6.i686                                                                                                                    1/1
  Verifying  : monit-5.1.1-4.el6.i686                                                                                                                    1/1

Installed:
  monit.i686 0:5.1.1-4.el6

Complete!


Create PEM


openssl req -new -x509 -days 365 -nodes -out /etc/monit.pem -keyout /etc/monit.pem
chmod 600 /etc/monit.pem

好像不用執行
#openssl gendh 512 >> /etc/monit.d/monit.pem
#openssl x509 -subject -dates -fingerprint -noout -in /etc/monit.d/monit.pem
 

vim /etc/monit.conf

set daemon 60   #set 60秒監控一次
set logfile /var/log/monit.log      #不使用syslogd, 直接寫到檔案中

set alert who@email
set alert root@localhost

set httpd port 2812 and
        allow monit:monitpwd

set mailserver 127.0.0.1

        username "username" password "userpassword"   #如果有用dovecot ssl 驗證, 要設定帳密

set mail-format {
 From: monit@$HOST
 Subject: [monitAlert] - $EVENT $SERVICE

 message:$EVENT 監控項目 $SERVICE

        時間:$DATE
        動作:$ACTION
        主機:$HOST
        描述:$DESCRIPTION
}


vim /etc/monit.d/mysqld

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
    start program = "/etc/init.d/mysqld start" with timeout 60 seconds
    stop program  = "/etc/init.d/mysqld stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart

#監控Port

check host Host-MysqlD with address 192.168.1.1
        start program = "/etc/init.d/mysqld start"
        if failed port 3306 protocol mysql with timeout 10 seconds then start


vim /etc/monit.d/httpd

check process httpd with pidfile /var/run/httpd/httpd.pid
    start program = "/etc/init.d/httpd start" with timeout 60 seconds
    stop program  = "/etc/init.d/httpd stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart
    if totalmem > 200.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop


check host Host2-HTTP with address 192.168.1.2

        if failed port 80 protocol http with timeout 10 seconds then alert


vim /etc/monit.d/filesystem
check filesystem ROOTFS with path /
        if space usage > 85% for 5 times within 15 cycles then alert

check filesystem HOME with path /home
        if space usage > 90% for 5 times within 15 cycles then alert


注意:
 filesystem 如果是用mapping的話, 建議直接使用 mount point 當 path
另外實際在  monit 監控到的百分比和df 有落差


vim /etc/monit.d/system
check system 112.121.70.4
        if loadavg (1min) > 4 then alert
        if loadavg (5min) > 2 then alert
        if memory usage > 75% then alert
        if swap usage > 10% then alert
        if cpu usage (user) > 70% then alert
        if cpu usage (system) > 30% then alert
        if cpu usage (wait) > 20% then alert


vim /etc/monit.d/host
check host Web1 with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert
        if failed port 80 type tcp with timeout 30 seconds then alert
        if failed port 22 type tcp protocol ssh with timeout 5 seconds then alert
                else if succeeded for 1 cycles then alert

check host Web1in with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert

check host WebDB with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert
                else if succeeded for 1 cycles then alert
        if failed port 22 type tcp protocol ssh with timeout 5 seconds then alert
                else if succeeded for 1 cycles then alert

check host WebDBin with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert
        if failed port 3306 with timeout 15 seconds then alert

check host Backend1 with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert
        if failed port 53 with timeout 5 seconds then alert
        if failed port 22 type tcp protocol ssh with timeout 5 seconds then alert
                else if succeeded for 1 cycles then alert

check host Backend1in with address IP
        if failed icmp type echo count 3 with timeout 3 seconds then alert


可參考
http://mmonit.com/monit/documentation/monit.html


pem

沒有留言:

張貼留言