在azure云上面,使用Zabbix监控mysql中,发现在/usr/local/mysql/my.cnf里面设置的默认用户名密码无效,出不来数据,而且在zabbix服务器上,使用zabbix_get也报错failed,如下
[root@zabbix_serv_121_12 ~]#/usr/local/zabbix/bin/zabbix_get -s 192.168.13.13 -p10050 -kmysql.status[Uptime]
/usr/local/mysql/bin/mysqladmin: connect toserver at 'localhost' failed
error: 'Access denied for user'adminuser'@'localhost' (using password: NO)'
[root@zabbix_serv_121_12 ~]#
在/usr/local/mysql/my.cnf里面添加所有客户端都可以使用的[client]选项卡配额好mysql的用户名密码
[root@azure_test_dbm2_3_13 mysql]# vim.my.cnf
[client]
MYSQL_USER=zabbix
password=ys_test0418
再去zabbix服务器上,使用get来测试下,
[root@zabbix_serv_121_12 ~]#
[root@zabbix_serv_121_12 ~]#/usr/local/zabbix/bin/zabbix_get -s 192.168.13.13 -p10050 -kmysql.status[Uptime]
/usr/local/mysql/bin/mysqladmin: connect toserver at 'l27.0.0.1' failed
error: 'Unknown MySQL server host 'l27.0.0.1'(0)'
Check that mysqld is running on l27.0.0.1and that the port is 3317.
You can check this by doing 'telnetl27.0.0.1 3317'
[root@zabbix_serv_121_12 ~]#
本文章来源blog地址:http://blog.csdn.net/mchdba/article/details/51344063,谢绝转载。
Zabbix监控mysql是通过远程调用mysql服务器的本地的mysqladmin组件来获取mysql数据库信息的,这样只要在本地mysql服务器调试通过了,那么就应ok了。先在本地免密码登录调试通过吧。
尝试本地mysqladmin,无效:
[root@azure_test_dbm2_3_13 zabbix]#/usr/local/mysql/bin/mysqladmin -hl27.0.0.1 -uzabbix -pys_test0418 -P3317 -S/usr/local/mysql/mysql.sock extended-status grep -w Com_update
Warning: Using a password on the commandline interface can be insecure.
Got error: Unknown MySQL server host'l27.0.0.1' (0)
尝试本地mysql,无效:
[root@azure_test_dbm2_3_13 zabbix]#/usr/local/mysql/bin/mysql -hl27.0.0.1 -uzabbix -pys_test0418 -P3317
Warning: Using a password on the commandline interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL serverhost 'l27.0.0.1' (0)
[root@azure_test_dbm2_3_13 zabbix]# mysql-hl27.0.0.1 -uzabbix -pys_test0418 -P3317
Warning: Using a password on the commandline interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host'l27.0.0.1' (0)
[root@azure_test_dbm2_3_13 zabbix]#mysql -uzabbix -pys_test0418 -P3317
Warning: Using a password on the commandline interface can be insecure.
ERROR 1045 (28000): Access denied for user'zabbix'@'localhost' (using password: YES)
[root@azure_test_dbm2_3_13 zabbix]#
问题在哪里呢?
看来默认的/usr/local/mysql/my.cnf里面的配置对于登录来说无效了,那么我们需要去看下mysqladmin识别哪些my.cnf以及他们的路径地址:
[root@azure_test_dbm2_3_13 mysql]#mysqladmin --help
……
Default options are read from the followingfiles in the given order:
/etc/my.cnf /etc/mysql/my.cnf/usr/local/mysql/etc/my.cnf ~/.my.cnf
……
[root@azure_test_dbm2_3_13 mysql]#
再ll下看是否能找到这些配置文件:
[root@azure_test_dbm2_3_13 mysql]# ll/etc/my.cnf
ls: cannot access /etc/my.cnf: No such fileor directory
[root@azure_test_dbm2_3_13 mysql]# ll/etc/mysql/my.cnf
ls: cannot access /etc/mysql/my.cnf: Nosuch file or directory
[root@azure_test_dbm2_3_13 mysql]# ll/usr/local/mysql/etc/my.cnf
ls: cannot access/usr/local/mysql/etc/my.cnf: No such file or directory
[root@azure_test_dbm2_3_13 mysql]# ll~/.my.cnf
ls: cannot access /root/.my.cnf: No suchfile or directory
[root@azure_test_dbm2_3_13 mysql]# ll/usr/local/mysql/etc
ls: cannot access /usr/local/mysql/etc: Nosuch file or directory
[root@azure_test_dbm2_3_13 mysql]#
一个也没用找到,原来我的mysql是源码编译的,编译路径是在/usr/local/mysql/my.cnf,但是mysqladmin不识别了。所以需要安装提示准备一个新的my.cnf吧
在mysqladmin识别的my.cnf路径中(/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf )选择一个/usr/local/mysql/etc/my.cnf,然后新建并且在里面录制好用户名密码,然后调试通过
# 在mysql服务器上面准备新的配置文件my.cnf [root@azure_test_dbm2_3_13 mysql]# mkdir /usr/local/mysql/etc [root@azure_test_dbm2_3_13 mysql]# [root@azure_test_dbm2_3_13 mysql]# vim /usr/local/mysql/etc/my.cnf
[mysqladmin] user=zabbix password=ys_test0418 socket=/usr/local/mysql/mysql.sock
# 赋予mysql用户访问权限 [root@azure_test_dbm2_3_13 mysql]# chown -R mysql.mysql /usr/local/mysql/etc/my.cnf [root@azure_test_dbm2_3_13 mysql]# chmod u+x /usr/local/mysql/etc/my.cnf [root@azure_test_dbm2_3_13 mysql]#
# 重启下,因为我发现不重启的话,不生效 [root@azure_test_dbm2_3_13 mysql]# service mysql restart Shutting down MySQL. [ OK ] Starting MySQL.. [ OK ] [root@azure_test_dbm2_3_13 mysql]# |
然后去zabbix服务器上验证,可以获取到mysql服务器的数据信息:
[root@zabbix_test_121_12 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.13.13 -p10050 -k mysql.status[Uptime] 154408 [root@zabbix_test_121_12 ~]# |
Bty:感谢网友木木指点
参考文章:http://dev.mysql.com/doc/refman/5.6/en/password-security-user.html