zabbix企业应用之监控mysql 5.6版本

最近很多人都问我如何为什么使用我之前博客的模板不能监控了,经过沟通发现对方的mysql版本是5.6,在进行命令行查看数据的实话,使用mysql -uxxx -pxxx -Pxxx的时候,会如下报错

Warning: Using a password on the command line interface can be insecure

报错原因是mysql 5.6版本增加了密码安全策略,之前版本可以使用的命令行里加上密码就会强制报错,所以使用zabbix lld监控mysql的时候,就会由于收到此报错导致没办法监控。

解决的方法为:

第一种:使用mysql 5.5的客户端

第二种:使用--login-path(推荐)

一、mysql配置

下面是介绍如何使用--login-path设置

mysql_config_editor set --login-path=local --host=localhost --user=zabbix -p

命令解释:

--login-path是设置访问的名字,我设置的local;

--host是指定允许访问的host地址,这个地址是你grant的时候配置的;

--user是用户名,也是grant时候配置的;

-p是指定密码,同样是grant配置。

运行上面命令后,会要求你属于密码,输入后会什么反馈都没有,可以使用下面命令查看

15:35:38 # mysql_config_editor print --all[local]
user = zabbix
password = *****
host = localhost

测试

15:35:40 # mysql --login-path=localWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 741Server version: 5.6.19-67.0-log Percona Server (GPL), Release 67.0, Revision 618Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit

上面就配置好了mysql安全模式访问

二、zabbix agentd配置

下面介绍zabbix客户端配置文件里key的情况

默认客户端的key是

UserParameter=mysql_stats[*],mysql -h localhost -P $1 -uzabbix -pzabbix -e "show global status"|grep "\<$2\>"|cut  -f2
UserParameter=mysql_stats_slave[*],mysql -h localhost -P $1 -uzabbix -pzabbix  -e "show slave status\G"|grep "\<$2\>"|awk '{if($NF=="Yes") {print 1} else {print 0}}'

修改为

UserParameter=mysql_stats_5.6[*],sudo mysql --login-path=local -P $1  -e "show global status"|grep "\<$2\>"|cut  -f2
UserParameter=mysql_stats_slave_5.6[*],sudo mysql --login-path=local -P $1  -e "show slave status\G"|grep "\<$2\>"|awk '{if($NF=="Yes") {print 1} else {print 0}}'

然后配置sudo,在/etc/sudoers里添加

zabbix ALL=(root) NOPASSWD:/usr/bin/mysql

其中/usr/bin/mysql是mysql程序地址,可以根据你自身情况修改。

完成后重启zabbix agentd

ps -ef|grep zabbix|grep -v grep|awk '{print $2}'|xargs kill -9/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf

其他的配置参考之前监控mysql的就行


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章