Zabbix cannot connect to a PostgreSQL database
First off I am running CentOS 6.5 and attempting to use Zabbix 2.2.4. Any hostnames have been replaced with examples.
I have installed the following RPMs onto my Zabbix machine ( hostname will be zbx-hostname ):
zabbix-java-gateway-2.2.4-1.el6.x86_64
zabbix-web-2.2.4-1.el6.noarch
zabbix-agent-2.2.4-1.el6.x86_64
zabbix-server-2.2.4-1.el6.x86_64
zabbix-2.2.4-1.el6.x86_64
zabbix-web-pgsql-2.2.4-1.el6.noarch
zabbix-server-pgsql-2.2.4-1.el6.x86_64
My PostgreSQL machine has postgreSQL 9.2 installed with the RPMS ( hostname will be db-hostname ):
postgresql92-9.2.8-1PGDG.rhel6.x86_64
postgresql92-libs-9.2.8-1PGDG.rhel6.x86_64
postgresql92-server-9.2.8-1PGDG.rhel6.x86_64
My zabbix_server.conf file looks like:
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=db-hostname
DBName=zabbix-dbname
DBUser=zabbix-user
DBPassword=zabbix-password
DBSocket=
DBPort=5432
My zabbix php configuration looks like:
$DB['TYPE'] = 'POSTGRESQL';
$DB['SERVER'] = 'db-hostname';
$DB['PORT'] = '5432';
$DB['DATABASE'] = 'zabbix-dbname';
$DB['USER'] = 'zabbix-user';
$DB['PASSWORD'] = 'zabbix-password';
// SCHEMA is relevant only for IBM_DB2 database
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
I am able to run the following and successfully connect to my database:
export PGPASSWORD=zabbix; psql -U zabbix-user -d zabbix-dbname -h db-hostname
export PGPASSWORD=zabbix; psql -U zabbix-user -d zabbix-dbname -h 192.168.0.1
But zabbix refuses to connect printing out (192.168.0.1 being the correctly resolved IP Address) :
25015:20150205:112656.236 [Z3001] connection to database 'zabbix-dbname' failed: [0] could not connect to server: Permission denied
Is the server running on host "db-hostname" (192.168.0.1) and accepting
TCP/IP connections on port 5432?
25015:20150205:112656.236 Database is down. Reconnecting in 10 seconds.
But on the DB host when I monitor incomming TCP traffic I do not see any incoming connections ( using both tcpdump & iptables ). It appears that zabbix is not even attempting to make a request to the database box?
I have torndown my zabbix box and rebuit it to get the same error twice so it would appear to be a problem with my configuration, does anybody know of any solutions?
Solution 1:
From previous comment:
I've managed to resolve the issue, SE Linux was enabled incorrectly and was blocking zabbix from networking. To solve the issue I ran:
setsebool -P zabbix_can_network 1
The topic discussing this can be found at (Warning: In russian): http://zabbix.com/forum/showthread.php?t=47247
Solution 2:
In my situation I need to grant network access for httpd too. (CentOS 7, zabbix 3)
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_can_network_connect 1
If you have error "setsebool, command not found" install policycoreutils-python
yum install policycoreutils-python