监控mysql
zabbix自带mysql模板监控mariadb,更全面的监控可以自行编写脚本或才通过第三方模板,如http://www.fromdual.com/mpm-installation-guide
在要监控的mysql主机上
1.安装zabbix客户端
2.创建具有监控权限的数据库用户
GRANT USAGE ON *.* TO
'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;
3.创建数据库连接配置文件
root@jlive:~#cat
>/usr/local/zabbix/etc/.my.cnf <<HERE
[mysql]
host
= localhost
user
= zabbix
password = zabbix
socket =
/tmp/mysql.sock
[mysqladmin]
host
= localhost
user
= zabbix
password = zabbix
socket =
/tmp/mysql.sock
HERE
可根据环境不同作相应调整
4.使用zabbix
mysql模板配置文件userparameter_mysql.conf
cp
/usr/local/src/zabbix-3.0.2/conf/zabbix_agentd/userparameter_mysql.conf
/usr/local/zabbix/etc/zabbix_agentd.conf.d
sed -i
's#/var/lib/zabbix#/usr/local/zabbix/etc#g'
/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
在agentd主配置文件中Include进来
sed -i '$ a
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d'
/usr/local/zabbix/etc/zabbix_agentd.conf
5.重启zabbix_agentd
/etc/init.d/zabbix_agentd restart
6.测试
root@jlive:~#zabbix_agentd
-c /usr/local/zabbix/etc/zabbix_agentd.conf -t
mysql.status[uptime]
mysql.status[uptime]
[t|11914]
root@jlive:~#zabbix_get
-s localhost -p 10050 -k 'mysql.status[Bytes_received]'
sh: mysql: command not found
日志里也一直提示mysql命令not found
61652:20160430:223023.549
item "Zabbix server:mysql.status[Bytes_received]" became not
supported: Received value [sh: mysql: command not found] is not
suitable for value type [Numeric (float)]
61650:20160430:223024.550
item "Zabbix server:mysql.status[Bytes_sent]" became not supported:
Received value [sh: mysql: command not found] is not suitable for
value type [Numeric (float)]
61652:20160430:223025.552
item "Zabbix server:mysql.status[Com_begin]" became not supported:
Received value [sh: mysql: command not found] is not suitable for
value type [Numeric (float)]
61653:20160430:223026.552
item "Zabbix server:mysql.status[Com_commit]" became not supported:
Received value [sh: mysql: command not found] is not suitable for
value type [Numeric (float)]
61650:20160430:223027.554
item "Zabbix server:mysql.status[Com_delete]" became not supported:
Received value [sh: mysql: command not found] is not suitable for
value type [Numeric (float)]
61653:20160430:223028.555
item "Zabbix server:mysql.status[Com_insert]" became not supported:
Received value [sh: mysql: command not found] is not suitable for
value type [Numeric (float)]
61652:20160430:223029.557
item "Zabbix server:mysql.status[Com_rollback]" became not
supported: Received value [sh: mysql: command not found] is not
suitable for value type [Numeric (float)]
61646:20160430:223501.719
executing housekeeper
61646:20160430:223501.742
housekeeper [deleted 0 hist/trends, 1 items, 0 events, 0 sessions,
0 alarms, 0 audit items in 0.021534 sec, idle for 1
hour(s)]
但实际上mysql命令是存在的,只是非标准路径,mariadb安装在/opt/mariadb下,故mysql命令的绝对路径是/opt/mariadb/bin/mysql,但我己经在/etc/profile中作了全局申明,export
PATH=/opt/mariadb/bin:$PATH,但还是报mysql not
found,于是百度了下,还真有朋友碰到相同的问题,试了下
解决方案
A./usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf中的所有mysql,mysqladmin替换为绝对路径
或者
B.将mysql,mysqladmin软链到/usr/bin下
ln -s
/opt/mariadb/bin/{mysql,mysqladmin} /usr/bin
注意:软链到/usr/local/bin下无效,只能呵呵了
推荐B方案,软链后立马就生效了
root@jlive:~#zabbix_get
-s localhost -p 10050 -k 'mysql.status[Bytes_received]'
17963712
61653:20160430:223522.880
item "Zabbix server:mysql.ping" became supported
61650:20160430:223523.882
item "Zabbix server:mysql.status[Bytes_received]" became
supported
61651:20160430:223524.883
item "Zabbix server:mysql.status[Bytes_sent]" became
supported
61652:20160430:223525.884
item "Zabbix server:mysql.status[Com_begin]" became
supported
61650:20160430:223526.887
item "Zabbix server:mysql.status[Com_commit]" became
supported
61651:20160430:223527.888
item "Zabbix server:mysql.status[Com_delete]" became
supported
61653:20160430:223528.889
item "Zabbix server:mysql.status[Com_insert]" became
supported
61652:20160430:223529.891
item "Zabbix server:mysql.status[Com_rollback]" became
supported
61653:20160430:223530.892
item "Zabbix server:mysql.status[Com_select]" became
supported
61650:20160430:223531.894
item "Zabbix server:mysql.status[Com_update]" became
supported
61651:20160430:223532.895
item "Zabbix server:mysql.status[Questions]" became
supported
61652:20160430:223533.895
item "Zabbix server:mysql.status[Slow_queries]" became
supported
61653:20160430:223534.896
item "Zabbix server:mysql.status[Uptime]" became
supported