[MySQL] 黑名單與 unauthenticated users

5/30 當天,由我負責的專案上線了,由於專案時間較趕沒有做壓力測試,結果上線當日 9:30 之後就面臨連線數過多,導致諸多問題發生。其中比較值得注意的是持續發生 Web Server 無法連接至 MySQL 的窘境。


可以確定的是 MySQL 是正常運作的,其它電腦也都可以正常連線至 MySQL,而且速度也都很快,就唯有 Web Server 不行。於是 MySQL 重新啟動後,Web Server 的確可以勉強連線進去,但是沒多久就被 MySQL 全部踢出去。
(MySQL 出現的訊息就是 Can’t Connect ….)

由於 Web Server 跟MySQL 是用 Private IP 連線,於是我想改用 Public IP 連線試試,果然也是順個幾秒鐘又掛了,但是這次的訊息是:

Host ‘web.xxxx.com.tw’ is blocked because of many connection errors. Unblock with ‘mysqladmin flush-hosts’

看起來是錯誤連線數過多,被 MySQL 列為黑名單了,依照官方的說法,除了 mysqladmin flush-hosts 之外,也將 max_connect_errors 加到 10000,雖然這個訊息沒再出現了,但是最後還是變回 Can’t Connect ….

問題又回到了原點,也很感謝 Mark 很熱心的提供了他的意見及參數,但是這種狀況實在罕見,加上在 Navicat 上看到的 Process 完全沒有線索,所以實在很難處理。最後是在 phpMyadmin 的 process 看到一堆 unauthenticated users 才為這個問題露出一絲曙光。

因為有訊息就好辦,在 MySQL Bugs: #8945 看到:

I had a similar situation on my setup where the database lived on a different host than the webserver. I found the “unauthenticated users” were connections from the webserver that were hanging on DNS lookups. Don’t know if this is a mysql bug or a bug with my firewall / other setup, but a couple of fixes I found were…

1) start mysql with –skip-name-resolve (you may have to change your mysql
permission tables to have the host’s IP instead of hostname, including
localhost)

or 2) add the connecting host to your /etc/hosts file.

我採用方法2,加入 Web Server 的 Private IP 後,果然跟 MySQL 就通了。

註: 本文不小心讓文章消失了一半,所以懶的寫太多了 Orz

3 comments On [MySQL] 黑名單與 unauthenticated users

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar