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

來源:互聯網
上載者:User

標籤:

 

1,My.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 ~]#

本文章來源blog地址:http://blog.csdn.net/mchdba/article/details/51344063,謝絕轉載。

 

 

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.cnf,OK

在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:感謝網友木木指點

參考文章:http://dev.mysql.com/doc/refman/5.6/en/password-security-user.html

 

 

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.