Friend , recently
I configured Zabbix with postgresql in my office infrastructure.
We have one zabbix
master server (192.168.0.1) and one pgsql database server (192.168.0.2)
Below are the step
that I performs on configuring zabbix.
Step 1) Download and install RPM’s for postgresql in database
server (192.168.0.2)
[root@localhost ~]#wget http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgdg-redhat91-9.1-5.noarch.rpm
[root@localhost ~]#rpm -ivh pgdg-redhat91-9.1-5.noarch.rpm
[root@localhost ~]#yum install postgresql91-server postgresql91-contrib
[root@localhost ~]#/etc/init.d/postgresql-9.1 restart
[root@localhost ~]#service
postgresql-9.1 initdb
Step 2) Configure Postgresql on (192.168.0.2)
[root@localhost ~]# su – postgres
-bash-4.1$ psql
postgres=# CREATE DATABASE zabbix WITH ENCODING='UTF-8';
postgres=# CREATE USER zabbix WITH PASSWORD 'zabbix';
postgres=# GRANT ALL ON DATABASE zabbix TO zabbix;
postgres=# GRANT ALL PRIVILEGES ON DATABASE zabbix to postgres;
postgres=# ALTER USER Postgres WITH PASSWORD 'redhat';
postgres=# \q
-bash-4.1$
-bash-4.1$ logout
[root@localhost ~]#vi /var/lib/pgsql/9.1/data/pg_hba.conf
****************
# "local" is for Unix domain socket connections
only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 10.10.2.0/16 md5
******************
[root@localhost ~]#vi /var/lib/pgsql/9.1/data/ postgresql.conf
**************
listen_addresses = '192.168.0.2' # what IP address(es) to listen on;
#
comma-separated list of addresses;
# defaults to 'localhost', '*' = all
#
(change requires restart)
port = 5432
**************
[root@localhost ~]#/etc/init.d/postgresql-9.1 restart
Step 3) Configure php.ini in Zabbix server (192.168.0.1)
[root@localhost ~]#yum -y install gcc net-snmp-devel curl-devel gcc make
curl-devel httpd php php-pgsql php-bcmath php-gd php-mbstring net-snmp-devel
fping e2fsprogs-devel zlib-devel libgssapi-devel krb5-devel openssl-devel
libidn-devel iksemel-devel libXpm openssh-clients php-xmlrpc sharutils OpenIPMI-devel libssh2-devel
php-xml
[root@localhost ~]#vi /etc/php.ini
*******
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Kolkata
*******
Step 4) Download and install zabbix from source code for
zabbix frontend (192.168.0.1)
[root@localhost ~]#groupadd zabbix
[root@localhost ~]#useradd -g zabbix –s /sbin/nologin zabbix
[root@localhost ~]#wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz
[root@localhost ~]#mv zabbix-2.0.6.tar.gz /opt/;cd /opt
[root@localhost ~]#tar -xvzf /opt/zabbix-2.0.6.tar.gz
[root@localhost ]#cd zabbix-2.0.0.6
[root@localhost ]#./configure --prefix=/opt/zabbix --enable-server
--enable-agent --with-net-snmp --with-postgresql=/usr/pgsql-9.1/bin/pg_config
--with-ssh2 --with-openipmi --with-libcurl
[root@localhost ]#make;make install
Step 5) Configure frontend
[root@localhost ~]#cp -R /opt/zabbix-2.0.6/frontends/php /var/www/html/zabbix
[root@localhost ~]#Service httpd restart
Step 5) Configure zabbix config files (192.168.0.1)
[root@localhost ]#vi /opt/zabbix/etc/zabbix_server.conf
*********
ListenPort=10051
LogFile=/opt/zabbix/log/zabbix_server.log
PidFile=/opt/zabbix/log/zabbix_server.pid
DBHost=192.168.0.2
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
StartPollers=10
DisableHousekeeping=1
CacheSize=128M
HistoryCacheSize=128M
TrendCacheSize=64M
HistoryTextCacheSize=128M
Timeout=30
***********
[root@localhost ]#vi /opt/zabbix/etc/zabbix_agentd.conf
************
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
************
Step 6) Import zabbix database to postgresql server
[root@localhost ]#cd /opt/zabbix-2.0.6/database/postgresql
[root@localhost ]# psql -U zabbix -h 192.168.0.2 -d zabbix -f
schema.sql
[root@localhost ]#psql -U zabbix -h 192.168.0.2 -d zabbix -f
images.sql
[root@localhost ]#psql -U zabbix -h 192.168.0.2 -d zabbix -f
data.sql
Step 7) Installing Zabbix through web
Go to web browser and type below link
Download the config file and paste it to the location /var/www/html/zabbix/conf/zabbix.conf.php
Step 7) Copy init script for zabbix_server and zabbix_agentd
[root@localhost ]#cp /root/zabbix.2.0.6/misc/init.d/fedora/core/zabbix_server
/etc/init.d/
[root@localhost ]#cp /root/zabbix.2.0.6/misc/init.d/fedora/core/zabbix_agentd
/etc/init.d/
[root@localhost ]#vi /etc/init.d/ zabbix_server
**************
# Zabbix-Directory
BASEDIR=/opt/zabbix
# Binary File
BINARY_NAME=zabbix_server
# Full Binary
File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME
# PID file
PIDFILE=/opt/zabbix/log/$BINARY_NAME.pid
******************
[root@localhost ]#vi /etc/init.d/ zabbix_agentd
*****************
#
Zabbix-Directory
BASEDIR=/opt/zabbix
# Binary File
BINARY_NAME=zabbix_agentd
# Full Binary
File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME
# PID file
PIDFILE=/tmp/$BINARY_NAME.pid
************
[root@localhost ]# service zabbix_server restart
[root@localhost ]# service zabbix_agentd restart
Now You have done your installation part. Try to login with credentials
URL: http://192.168.0.1/zabbix
User: Admin
Password: zabbix





hello, You hav done a great job. thnks. but i have issues after following your instrutions.
ReplyDeleteSee error message--; zabbix_server [2270]: user zabbix does not exist
zabbix_server [2270]: cannot run as root!
thnks
Probably you missed to create a user zabbix.
ReplyDeletePlease create a system user zabbix.
Amit,
DeleteI have a problem when i try to do this.
postgres=# GRANT ALL ON DATABASE *.* TO postgres WITH PASSWORD 'redhat';
it says that there is some error in here (*)
Any advice?
Hi,
DeleteThank you for correcting my typo. Please find correct syntax.
postgres=# GRANT ALL PRIVILEGES ON DATABASE zabbix to postgres;
what about this line?
Deletepostgres=# ALTER USER Postgres WITH PASSWORD 'redhat';
it's ok?
thanks!
And the last question is:
Deletethe network 10.10.2.0 in that line its pinting to what ? cause the db and the master server are in the 192.168.0.0/24 network.
host all all 10.10.2.0/16 md5
pointing*
Delete@Invasorenlaciudad :
Deletepostgres=# ALTER USER Postgres WITH PASSWORD 'redhat';
is for changing password for user postgres.
I have another network of 10.10.2.0/16. That I was allowed as well.
For the single network of 192.168.0.0/24 this line should not required.
thanks a lot!
Deletehello i have my issues too,
ReplyDelete[root@zabbix ~]# service zabbix_server start
Starting zabbix_server: [ OK ]
[root@zabbix ~]# zabbix_server [8129]: cannot open [/opt/zabbix/log/zabbix_server.log]: [2] No such file or directory
when i start the zabbix_server an error will pop out. please help me solve this. thank you!
It shows that you have not created log file location. Please create file /opt/zabbix/log/zabbix_server.log and restart Zabbix service.
ReplyDeletethank you! :D how about the port that i will allow in iptables? do you have any idea how can i allow it? because the code i enter did not works, i entered "iptables -A INPUT -i eth0 -p tcp -s 0/0 --dport 10050:10051 -d xx.xx.xx.xx (ip add of the zabbix server) -m state --state NEW,ESTABLISHED -j ACCEPT
ReplyDeletethank you!appreciate your help!
Hi Jordan,
ReplyDeleteJust to inform you that Zabbix supports both polling and trapping feature.
1) Pulling - Master/Proxy server could pull data from agent server.
2) Trapping - Agent will give data to Master/Proxy Zabbix Server.
Here I configured Zabbix with pulling feature.
So, please try below command on your firewall/Agent
iptables -A INPUT -i eth0 -p tcp -s xx.xx.xx.xx (ip add of the zabbix server) --dport 10050:10051 -d 0.0.0.0 -m state --state NEW,ESTABLISHED -j ACCEPT
Please do let me know for farther assistance(If required.)
Hello Amit,
ReplyDeleteThank you for the idea. I tried your command and it worked but the zabbix server GUI will pop a msg that the zabbix server is not running. but in the terminal the status of the server is running. if i stop the iptables the zabbix GUI will start but if the iptables is started it will back to "zabbix server is not running".
these are the port that i allow in my zabbix server 22,80,443,53,10050,100051 and 5432, they are able to telnet,here is my iptables
[root@zabbix ~]# iptables -L
ReplyDeleteChain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW,ESTABLISHED /* allow incoming ssh */
ACCEPT udp -- anywhere localhost udp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT tcp -- anywhere localhost tcp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT udp -- localhost anywhere udp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT tcp -- localhost anywhere tcp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT tcp -- anywhere zabbix.centos tcp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT udp -- anywhere zabbix.centos udp dpts:zabbix-agent:zabbix-trapper state NEW,ESTABLISHED
ACCEPT tcp -- 192.168.21.202 anywhere tcp spt:postgres state RELATED,ESTABLISHED
ACCEPT udp -- 192.168.21.202 anywhere udp spt:postgres state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED /* allow apache */
ACCEPT udp -- anywhere anywhere udp dpt:http state NEW,ESTABLISHED /* allow apache */
ACCEPT udp -- localhost anywhere udp spt:postgres state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:http state RELATED,ESTABLISHED /* allow outgoing http */
ACCEPT tcp -- anywhere anywhere tcp spt:https state RELATED,ESTABLISHED /* allow outgoing https */
ACCEPT icmp -- anywhere anywhere icmp any /* allow ping */
ACCEPT udp -- anywhere anywhere udp spt:domain state RELATED,ESTABLISHED /* allow outgoing dns */
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT udp -- localhost anywhere udp spts:zabbix-agent:zabbix-trapper state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:ssh state ESTABLISHED /* allow incoming ssh */
ACCEPT tcp -- localhost anywhere tcp spts:zabbix-agent:zabbix-trapper state ESTABLISHED
ACCEPT tcp -- zabbix.centos anywhere tcp spts:zabbix-agent:zabbix-trapper state ESTABLISHED
ACCEPT udp -- zabbix.centos anywhere udp spts:zabbix-agent:zabbix-trapper state ESTABLISHED
ACCEPT udp -- anywhere 192.168.21.202 udp dpt:postgres state NEW,ESTABLISHED
ACCEPT tcp -- anywhere 192.168.21.202 tcp dpt:postgres state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:http state RELATED,ESTABLISHED /* allow apache */
ACCEPT udp -- anywhere anywhere udp spt:http state RELATED,ESTABLISHED /* allow apache */
ACCEPT tcp -- anywhere localhost tcp dpt:postgres state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED /* allow outgoing http */
ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW,ESTABLISHED /* allow outgoing https */
ACCEPT icmp -- anywhere anywhere icmp any /* allow ping */
ACCEPT udp -- anywhere anywhere udp dpt:domain state NEW,ESTABLISHED /* allow outgoing fns */
can you show your iptables too? thank you for the assistance!very appreciated it!
i just let you know that my approaches in setting up firewall "Rejecting all and accepting exceptions" thank you!
ReplyDeletehi Amit i resolved my problem thank you again.
ReplyDeleteHello Amit. Can you tell me how to configure the pulling and trapping? thank you!
ReplyDeletei tried this line but its showing error
ReplyDeleteGRANT ALL ON DATABASE *.* TO postgres WITH PASSWORD 'redhat';
i have the same issue, did you fix the problem?
DeleteHi,
DeleteThank you for correcting my typo. Please find correct syntax.
postgres=# GRANT ALL PRIVILEGES ON DATABASE zabbix to postgres;
I read that Post and got it fine and informative. PostgreSQL trigger
ReplyDelete