[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测试了下,反正连不上数据库的提示不存在了。

  

原文地址:https://www.cnblogs.com/GreenMountain/p/10194813.html