最近很多人都问我如何为什么使用我之前博客的模板不能监控了,经过沟通发现对方的mysql版本是5.6,在进行命令行查看数据的实话,使用mysql -uxxx -pxxx -Pxxx的时候,会如下报错
1
|
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设置
1
|
mysql_config_editor
set
--login-path=
local
--host=localhost --user=zabbix -p
|
命令解释:
--login-path是设置访问的名字,我设置的local;
--host是指定允许访问的host地址,这个地址是你grant的时候配置的;
--user是用户名,也是grant时候配置的;
-p是指定密码,同样是grant配置。
运行上面命令后,会要求你属于密码,输入后会什么反馈都没有,可以使用下面命令查看
1
2
3
4
5
|
15:35:38
# mysql_config_editor print --all
[
local
]
user = zabbix
password = *****
host = localhost
|
测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
15:35:40
# mysql --login-path=local
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 741
Server version: 5.6.19-67.0-log Percona Server (GPL), Release 67.0, Revision 618
Copyright (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是
1
2
|
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}}'
|
修改为
1
2
|
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里添加
1
|
zabbix ALL=(root) NOPASSWD:
/usr/bin/mysql
|
其中/usr/bin/mysql是mysql程序地址,可以根据你自身情况修改。
完成后重启zabbix agentd
1
2
|
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的就行
三、zabbix web配置
A、模板导入
把Template Mysql 5.6 Auto Discovery导入到zabbix里(模板在附件),具体操作不介绍。
B.主机关联模板
把需要监控mysql 5.6版本的主机管理模板即可监控,默认是3600秒后自动更新。
附件:http://down.51cto.com/data/2365948
本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1677545,如需转载请自行联系原作者