1. 程式人生 > >zabbix3.0 監控mysql服務免使用者名稱密碼登入的問題故障處理詳細過程

zabbix3.0 監控mysql服務免使用者名稱密碼登入的問題故障處理詳細過程

1My.cnf中使用者名稱密碼無效

在azure雲上面,使用Zabbix監控mysql中,發現在/usr/local/mysql/my.cnf裡面設定的預設使用者名稱密碼無效,出不來資料,而且在zabbix伺服器上,使用zabbix_get也報錯failed,如下

[[email protected]_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)'

[[email protected]_serv_121_12 ~]#

2,嘗試[client]無效

在/usr/local/mysql/my.cnf裡面新增所有客戶端都可以使用的[client]選項卡配額好mysql的使用者名稱密碼

[[email protected]_test_dbm2_3_13 mysql]# vim.my.cnf

[client]

MYSQL_USER=zabbix

password=ys_test0418

再去zabbix伺服器上,使用get來測試下,

[[email protected]_serv_121_12 ~]#

[[email protected]_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'

[[email protected]_serv_121_12 ~]#

3,繼續嘗試mysqladmin本地除錯一下

Zabbix監控mysql是通過遠端呼叫mysql伺服器的本地的mysqladmin元件來獲取mysql資料庫資訊的,這樣只要在本地mysql伺服器除錯通過了,那麼就應ok了。先在本地免密碼登入除錯通過吧。

嘗試本地mysqladmin,無效:

[[email protected]_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,無效:

[[email protected]_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)

[[email protected]_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)

[[email protected]_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)

[[email protected]_test_dbm2_3_13 zabbix]#

問題在哪裡呢?

4,找到mysql元件識別的my.cnf所在的路徑

看來預設的/usr/local/mysql/my.cnf裡面的配置對於登入來說無效了,那麼我們需要去看下mysqladmin識別哪些my.cnf以及他們的路徑地址:

[[email protected]_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

……

[[email protected]_test_dbm2_3_13 mysql]#

再ll下看是否能找到這些配置檔案:

[[email protected]_test_dbm2_3_13 mysql]# ll/etc/my.cnf

ls: cannot access /etc/my.cnf: No such fileor directory

[[email protected]_test_dbm2_3_13 mysql]# ll/etc/mysql/my.cnf

ls: cannot access /etc/mysql/my.cnf: Nosuch file or directory

[[email protected]_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

[[email protected]_test_dbm2_3_13 mysql]# ll~/.my.cnf

ls: cannot access /root/.my.cnf: No suchfile or directory

[[email protected]_test_dbm2_3_13 mysql]# ll/usr/local/mysql/etc

ls: cannot access /usr/local/mysql/etc: Nosuch file or directory

[[email protected]_test_dbm2_3_13 mysql]#

一個也沒用找到,原來我的mysql是原始碼編譯的,編譯路徑是在/usr/local/mysql/my.cnf,但是mysqladmin不識別了。所以需要安裝提示準備一個新的my.cnf吧

5,準備新的my.cnfOK

在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

[[email protected]_test_dbm2_3_13 mysql]# mkdir /usr/local/mysql/etc

[[email protected]_test_dbm2_3_13 mysql]#

[[email protected]_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使用者訪問許可權

[[email protected]_test_dbm2_3_13 mysql]# chown -R mysql.mysql /usr/local/mysql/etc/my.cnf                                                                                                                                            

 [[email protected]_test_dbm2_3_13 mysql]# chmod u+x /usr/local/mysql/etc/my.cnf

[[email protected]_test_dbm2_3_13 mysql]#

# 重啟下,因為我發現不重啟的話,不生效

[[email protected]_test_dbm2_3_13 mysql]# service mysql restart

Shutting down MySQL.                                       [  OK  ]

Starting MySQL..                                          [  OK  ]

[[email protected]_test_dbm2_3_13 mysql]#

然後去zabbix伺服器上驗證,可以獲取到mysql伺服器的資料資訊:

[[email protected]_test_121_12 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.13.13 -p10050 -k mysql.status[Uptime]                                                                                                

154408

[[email protected]_test_121_12 ~]#

Bty:感謝網友木木指點