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的就行


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