Zabbix在监控MySQL数据库时,会使用自带的模板Template App MySQL,是不能直接使用的,因为没有key,而获取不到数据,前端会出现如下报错“Warning: Using a password on the command line interface can be insecure.”报错原因是mysql 5.6以后的版本增加了密码安全策略,在命令行里加上密码就会强制报错,而5.6之前版本可以直接使用的。
前边有篇文章是通过mysql --login-path=local来进行无密码验证登录,而本文是通过另一种方法通过修改/etc/my.cnf来进行无密码验证登录。
错误探究: 这个提示在mysql 5.5之后会出现。 而且,这个提示,会被zabbix-servre捕捉到,在zabbix-server.log日志中会出现 24123:20160826:101433.609 error reason for "110:mysql.status[Bytes_sent]" changed: Received value [mysqladmin: [Warning] Using a password on the command line interface can be insecure.8991074] is not suitable for value type [Numeric (float)] 提示参数不符合 在zabbix-server服务器上面,使用zabbix-get命令时 [root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 172.21.100.12 -p10050 -k mysql.status[Uptime] mysqladmin: [Warning] Using a password on the command line interface can be insecure. 522345 也就是说zabbix_key获取的key值是“mysqladmin: [Warning] Using a password on the command line interface can be insecure.”而不是522345,造成服务端的数值类型不对,为解决这个问题必须使用无密码登录才可以,为了安全,只允许localhost进行登录。 (二)背景简介 IP主机名功能172.20.66.110 zabbix_server zabbix 服务端
172. 21.100.12 zabbix_agent zabbix客户端数据库
(三)具体实施步骤
一,zabbix_agentd客户端设置
1.在mysql数据上创建一个普通用户lqb
2.修改/etc/my.cnf文件创建无密码登录
[root@localhost ~]# vim /etc/my.cnf [client] user=lqb password=123456 [mysqladmin] host=localhost user=lqb password=1234563.测试是否可以直接访问,如果输入命令mysql -ulqb直接进去说明已OK。
[root@localhost ~]# mysql -ulqb Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 761 Server version: 5.5.58-log MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> select Host,User,authentication_string from mysql.user; +-----------------------+--------+-------------------------------------------+ | Host | User | authentication_string | +-----------------------+--------+-------------------------------------------+ | localhost | root | | | localhost.localdomain | root | | | 127.0.0.1 | root | | | ::1 | root | | | % | root | NULL | | % | zabbix | NULL | | localhost | lqb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 172.21.100.12 | zabbix | NULL | +-----------------------+--------+-------------------------------------------+ 8 rows in set (0.01 sec) mysql> exit; Bye [root@localhost scripts]# mysqladmin extended-status |grep -w "Bytes_received" |cut -d"|" -f3 ###有数据返回说明正常 10792596272