1. 程式人生 > >[Z3001] connection to database 'zabbix' failed: [2003] Can't connect to MySQL server on 'x.x.x.x' (13)

[Z3001] connection to database 'zabbix' failed: [2003] Can't connect to MySQL server on 'x.x.x.x' (13)

  公司使用者逐漸增加,伺服器的執行需要監控起來了。看到網上說伺服器監控流行Zabbix,就摸索著安裝試用下。

  安裝是按照官網文件來的,地址:https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/rhel_centos。

  按照步驟執行到啟動 Zabbix server 程序時,看了下日誌一直重複連不上指定資料庫的錯誤: [Z3001] connection to database 'zabbix' failed: [2003] Can't connect to MySQL server on '192.168.5.119' (13)。邊做其它工作邊解決這個問題,網上搜了很多次,有的說zabbix_server.conf中配置的DBName等值是否符合實際,有的說DBSocket也需要配置上,但每次重啟服務這個錯誤依舊堅挺。直到今天在 https://www.zabbix.com/forum/zabbix-troubleshooting-and-problems/48343-connection-to-database-zabbix-failed 這篇文章裡發現了這句話:

        

  於是馬上到"/var/log/messages"這個檔案中看看到底有什麼乾坤,結果就發現了提示:

Dec 29 10:34:40 localhost setroubleshoot: SELinux is preventing /usr/sbin/zabbix_server_mysql from name_connect access on the tcp_socket port 3306. For complete SELinux messages run: sealert -l 06e750b0-8d08-4615-b204-a644538de17a
Dec 
29 10:34:40 localhost python: SELinux is preventing /usr/sbin/zabbix_server_mysql from name_connect access on the tcp_socket port 3306.#012#012***** Plugin catchall_boolean (89.3 confidence) suggests ******************#012#012If you want to allow zabbix to can network#012Then you must tell SELinux about this by enabling the '
zabbix_can_network' boolean.#012#012Do#012setsebool -P zabbix_can_network 1#012#012***** Plugin catchall (11.6 confidence) suggests **************************#012#012If you believe that zabbix_server_mysql should be allowed name_connect access on the port 3306 tcp_socket by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'zabbix_server' --raw | audit2allow -M my-zabbixserver#012# semodule -i my-zabbixserver.pp#012

  看樣子似乎是SELinux阻止了mysql的連線。關掉SELinux測試了下,反正連不上資料庫的提示不存在了。