标签:agent param mysql-bin event pass 定义 for 模板 connect
1)判断Mysql主从是否正常,是通过主从上面的SQL和IO线程都为yes状态判断(通过awk取值,grep过滤和统计yes的个数,如果为2则为正常值)
,随后我们取值得脚本或者命令写入zabbix-agent端的配置文件中的“Userparamenter”,格式 为:Userparamenter [自定义 键值] ,[脚本或者命令参数]。
2)我们需要自己定义添加监控mysql主从的模板和item监控项,创建监控项和图形都是可以的
3)创建完成之后,我们可以为zabbix主从状态定义监控报警
主从配置:
mysql-master端:
[root@mysql-master]# vim /etc/my.cnf (大致配置,如果需要详细的请看mysql篇)
server-id =1
log-bin=/var/lib/mysql/mysql-bin
root@mysql-master # /etc/init.d/mysqld restart
mysql> grant replication slave on *.* to ‘xiaoyu‘@‘192.168.10.138‘ identified by ‘123.com‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 339 | | |
+------------------+----------+--------------+------------------+
row in set (0.00 sec)
mysql-slave端
[root@mysql-slave]# vim /etc/my.cnf
server-id =2
log-bin=/var/lib/mysql/mysql-bin
[root@mysql-slave~]# /etc/init.d/mysqld restart
mysql> slave stop;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to
-> master_host=‘192.168.17.129‘,
-> master_user=‘xiaoyu‘,
-> master_password=‘123.com‘,
-> master_log_file=‘mysql-bin.000001‘,
-> master_log_pos=339;
Query OK, 0 rows affected (0.06 sec)
mysql> slave start;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.17.129
Master_User: xiaoyu
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 339
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
一:首先在Mysql-slave端创建mysql主从项取值
通过grep过滤出关键词"Running"状态,awk打印出第二列的"Yes",最后由grep -c统计“Yes”的个数
[root@mysql-slave ~]# mysql -u root -p123456 -e "show slave status\G" | grep "Running" |awk "{print $2}" | grep -c "Yes"
2 将这条语句写入agent.conf配置文件中
[root@mysql-slave ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=mysql.replication,mysql -u root -p123456 -e "show slave status\G" | grep "Running" |awk ‘{print $2}‘ | grep -c "Yes"
[root@mysql-slave ~]# /etc/init.d/zabbix_agent restart
最后在zabbix-server端抓取mysql-slave端的数据
[root@zabbix-server ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.17.138 -k mysql.replication #抓取mysql-slave端的键值,如果返回数值2.则表明IO和SQL线程状态都为yes状态,则表明主从正常
二:二:【Zabbix-server-web端配置】
2.1:创建一个监控项作为mysql主从二:【Zabbix-server-web端配置】
标签:agent param mysql-bin event pass 定义 for 模板 connect
原文地址:https://www.cnblogs.com/luoyan01/p/9733850.html