环境:centos 6.5,mysql 5.6,zabbix 2.4.4
1、在mysql中添加zabbix用户
1
2
3
|
mysql -uroot -p -e "GRANT USAGE ON *.* TO 'zabbix'@'127.0.0.1' IDENTIFIED BY 'zabbix'" ;
mysql -uroot -p -e "GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix'" ;
mysql -uroot -p -e "flush privileges"
|
2、新建.my.cnf文件
1
2
3
4
5
6
7
8
9
10
11
|
vim /usr/local/zabbix/etc/ .my.cnf
[mysql] host=127.0.0.1 user=zabbix password=zabbix socket= /tmp/mysql .sock
[mysqladmin] host=127.0.0.1 user=zabbix password=zabbix socket= /tmp/mysql .sock
|
3、复制并修改mysql的key值文件,将HOME指定到.my.cnf文件所在文件的路径,mysql和mysqladmin命令使用绝对路径
1
2
3
4
5
6
|
cp /root/zabbix-2 .4.5 /conf/zabbix_agentd/userparameter_mysql .conf /usr/local/zabbix/etc/zabbix_agentd .conf.d/
vim /usr/local/zabbix/etc/zabbix_agentd .conf.d /userparameter_mysql .conf
UserParameter=mysql.status[*], echo "show global status where Variable_name='$1';" | HOME= /usr/local/zabbix/etc /usr/local/mysql/bin/mysql -N | awk '{print $$2}'
UserParameter=mysql.size[*], 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= /usr/local/zabbix/etc /usr/local/mysql/bin/mysql -N
UserParameter=mysql. ping ,HOME= /usr/local/zabbix/etc /usr/local/mysql/bin/mysqladmin ping | grep -c alive
UserParameter=mysql.version, /usr/local/mysql/bin/mysql -V
|
4、修改agentd配置文件
1
2
3
4
5
6
7
8
|
vim /usr/local/zabbix/etc/zabbix_agentd .conf
LogFile= /tmp/zabbix_agentd .log
Server=192.168.100.161 ServerActive=192.168.100.161 Hostname=Zabbix server Include= /usr/local/zabbix/etc/zabbix_agentd .conf.d/
EnableRemoteCommands=1 UnsafeUserParameters=1 |
5、使用zabbix_get获取key值,zabbix_get在zabbix server上使用有返回值,在zabbix agent使用无返回值,要查看agent的key值,可以把127.0.0.1改为agent的ip或主机名
1
|
zabbix_get -s 127.0.0.1 -p 10050 -k "mysql.version"
|
6、添加mysql模板
7、查看数据
本文转自1321385590 51CTO博客,原文链接:http://blog.51cto.com/linux10000/1727905,如需转载请自行联系原作者