1、web页面添加mysql模版
Configuration > Hosts > 选择主机或添加新主机 > Tempaltes,搜索MySQL,添加弹出的模板,然后更新
2、配置userparameter_mysql.conf
找出配置文件
[[email protected] ~]# find / -name userparameter_mysql.conf /usr/share/doc/zabbix22-agent-2.2.16/userparameter_mysql.conf
在/etc/zabbix建一个目录放配置文件
[[email protected] ~]# mkdir /etc/zabbix/zabbix_agentd.d/
把配置文件拷贝到该目录下
[[email protected] ~]#cp /usr/share/doc/zabbix22-agent-2.2.16/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/
创建一个用户来获取mysql的相关数据
mysql>GRANT USAGE ON *.* TO ‘zabbix‘@‘localhost‘ IDENTIFIED BY ‘123‘; mysql>FLUSH PRIVILEGES;
添加用来关联mysql的配置文件my.cnf
[[email protected] ~]# vim /etc/zabbix/.my.cnf [mysql] host = localhost user = zabbix password = 123 socket = /tmp/mysql.sock [mysqladmin] host = localhost user = zabbix password = 123 socket = /tmp/mysql.sock
修改userparameter_mysql.conf:HOME目录为新增.my.cnf文件所在目录
[[email protected] ~]#sed -i ‘[email protected]/var/lib/[email protected]/etc/zabbix/@g‘ /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[[email protected] ~]# grep -v "^#" /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf UserParameter=mysql.status[*],echo "show global status where Variable_name=‘$1‘;" | HOME=/etc/zabbix mysql -N | awk ‘{print $$2}‘ UserParameter=mysql.size[*],bash -c ‘echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/etc/zabbix mysql -N‘ UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive UserParameter=mysql.version,mysql -V
修改zabbix_agentd.conf文件,添加一行,为userparameter_mysql.conf所在目录
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf Include=/etc/zabbix/zabbix_agentd.conf.d/
重启zabbix-agentd
[[email protected] ~]# service zabbix-agentd restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ]
测试
[[email protected] ~]#zabbix_get -s 192.168.1.102 -p 10050 -k mysql.ping 1 [[email protected] ~]# zabbix_get -s 192.168.1.102 -p 10050 -k mysql.version mysql Ver 14.14 Distrib 5.1.71, for redhat-linux-gnu (x86_64) using readline 5.1
时间: 2024-12-25 17:44:38