一.zabbix agentd的安裝
groupadd zabbix useradd -g zabbix -G zabbix -s /sbin/nologin -d /dev/null zabbix tar zxvf zabbix-2.2.2.tar.gz cd zabbix-2.2.2 ./configure --prefix=/data/zabbix --sysconfdir=/data/zabbix/conf --enable-agent make && make install cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ chmod 755 /etc/init.d/zabbix_agentd vim /etc/init.d/zabbix_agentd 修改BASEDIR=/data/zabbix vim /data/zabbix/conf/zabbix_agentd.conf LogFile=/data/zabbix/log/zabbix_agentd.log //日誌的路徑 Server=zabbix.test.com //這裏是zabbix server的地址 ServerActive=zabbix.test.com:10051 //同上 Hostname=Node1 mkdir -p /data/zabbix/log/ chown zabbix.zabbix /data/zabbix/log service zabbix_agentd start chkconfig --level 345 zabbix_agentd on 查看是否正常 netstat -an |grep 10050
二.監控MySQL的複製
原理:利用在slave上運行show slave status獲取Slave_IO_Running和Slave_SQL_Running的值
1.在mysql上新建監控用戶
grant replication client on *.* to 'zabbix'@'localhost' identified by 'zabbix'; flush privileges;
2.在/data/zabbix/sbin下新建check_mysql_replication.sh腳本
#!/bin/bash mysql -uzabbix -pzabbix -e "show slave status\G" |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes
給上述文件授權
chmod +x /data/zabbix/sbin/check_mysql_replication.sh
3.修改/data/zabbix/conf/zabbix_agentd
.conf
文件
UnsafeUserParameters=1 UserParameter=mysql.replication,/data/zabbix/sbin/check_mysql_replication.sh
4.重啓下zabbix_agemtd服務
service zabbix_agentd restart
三.配置zabbix server
1.在zabbix server上測試,這裏zabbix server是安裝在/webserver/zabbix,則運行
/webserver/zabbix/bin/zabbix_get -s 192.168.100.223 -k "mysql.replication"
如果上面返回的是2,那麼是正常(1.mysql的複製正常 2.zabbix_agentd是配置正常),代表Slave_IO_Running和Slave_SQL_Running兩個狀態都是Yes,這裏192.168.100.223是我的slave的IP地址
2.添加監控項目
點擊“configuration”,接着點擊"Host",然後找到要監控的Slave,點擊它的"Items".
2.點擊“create items”
3.填寫監控項目內容
4.創建Triggers,就是創建mysql.replication到什麼時候報警
這個時候我們在Slave機器上,在mysql環境下運行stop slave;