Installing and Configuring Zabbix Server 3.2 on Debian Jessie with PostgreSQL

WORKING ON IT

Here I'll show you how to install and configure the Zabbix Server 3.2 and client, the Zabbix server will installed on Debian Jessie.

Let's roll up our sleeves and start to work.

  • Debian Jessie Zabbix Server ip: 10.0.0.136

Here I will use the following repositories, use the ones that fits better you.

vim /etc/apt/sources.list
# /etc/apt/sources.list
deb http://ftp.br.debian.org/debian/ jessie main
deb-src http://ftp.br.debian.org/debian/ jessie main

deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main

# jessie-updates, previously known as 'volatile'
deb http://ftp.br.debian.org/debian/ jessie-updates main
deb-src http://ftp.br.debian.org/debian/ jessie-updates main

Let's start installing the Database

aptitude install postgresql postgresql-client postgresql-common postgresql-contrib postgresql-doc \
postgresql-server-dev-all -y

Now let's change the postgres password into the database

Let's change the user to postgres

su - postgres

Now let's access the psql

psql

Now let's set the password.

ALTER USER postgres WITH PASSWORD 'McW1k8v020E9VqA';

Now to exit from the psql

\q

If you don't have a way to create a good password use the following web link to create a good one: Strong Password Generator

Now we can login again with the new password

psql -h localhost -U postgres -W
Password for user postgres:
psql (9.4.7)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=# \q

Now let's create a new user into postgresql, the zabbix user will use the following password: AwX2O0k83mU40TS

psql -h localhost -U postgres -W
CREATE USER zabbix WITH PASSWORD 'AwX2O0k83mU40TS';

Now we need to create the database that will be used by the Zabbix

CREATE DATABASE zabbix WITH OWNER zabbix;

Now we can exit from psql

\q

We need to get the repository to install Zabbix with the lastest version is always the best way to install the Zabbix because we always will have more features and new resources to work.

cd /tmp && wget -c http://repo.zabbix.com/zabbix/3.2/debian/pool/main/z/zabbix-release/zabbix-release_3.2-1+jessie_all.deb

Now we need to install the repository like this

dpkg -i zabbix-release_3.2-1+jessie_all.deb

Now we need to update the repositories cache with the follow command

aptitude update

Now let's install the Zabbix Server with PostgreSQL support and its dependencies.

aptitude install zabbix-server-pgsql zabbix-sender snmp -y

Now we need to access the directory that store the database structure

cd /usr/share/doc/zabbix-server-pgsql

Now we need to decompress the file

gunzip create.sql.gz

Now we need to export a variable to the environment to avoid getting warnings about the password

export PGPASSWORD="AwX2O0k83mU40TS"

Now we can import the database structure

psql -h localhost -U zabbix -d zabbix -f create.sql

Now we need to configure the zabbix server configuration file

vim /etc/zabbix/zabbix_server.conf
[...]
DBName=zabbix
[...]
DBUser=zabbix
[...]
DBPassword=AwX2O0k83mU40TS

Now we need to restart the Zabbix Server like this

systemctl status zabbix-server

Now we're able to see the logs with the follow command

tail -f /var/log/zabbix/zabbix_server.log
  7425:20150316:103253.365 server #3 started [poller #1]
  7424:20150316:103253.367 server #2 started [db watchdog #1]
  7423:20150316:103253.368 server #1 started [configuration syncer #1]
  7459:20150316:103253.376 server #20 started [history syncer #1]
  7462:20150316:103253.376 server #23 started [history syncer #4]
  7461:20150316:103253.377 server #22 started [history syncer #3]
  7464:20150316:103253.377 server #25 started [proxy poller #1]
  7465:20150316:103253.377 server #26 started [self-monitoring #1]
  7463:20150316:103253.377 server #24 started [escalator #1]
  7460:20150316:103253.377 server #21 started [history syncer #2]

We can double check to see if the zabbix_serer is running

ps -C zabbix_server
  PID TTY          TIME CMD
 7420 ?        00:00:00 zabbix_server
 7423 ?        00:00:00 zabbix_server
 7424 ?        00:00:00 zabbix_server
 7425 ?        00:00:00 zabbix_server
 7426 ?        00:00:00 zabbix_server
 7427 ?        00:00:00 zabbix_server
 7428 ?        00:00:00 zabbix_server
 7429 ?        00:00:00 zabbix_server
 7430 ?        00:00:00 zabbix_server
 7431 ?        00:00:00 zabbix_server
 7432 ?        00:00:00 zabbix_server
 7433 ?        00:00:00 zabbix_server
 7434 ?        00:00:00 zabbix_server
 7435 ?        00:00:00 zabbix_server
 7436 ?        00:00:00 zabbix_server
 7437 ?        00:00:00 zabbix_server
 7438 ?        00:00:00 zabbix_server
 7439 ?        00:00:00 zabbix_server
 7440 ?        00:00:00 zabbix_server
 7441 ?        00:00:00 zabbix_server
 7459 ?        00:00:00 zabbix_server
 7460 ?        00:00:00 zabbix_server
 7461 ?        00:00:00 zabbix_server
 7462 ?        00:00:00 zabbix_server
 7463 ?        00:00:00 zabbix_server
 7464 ?        00:00:00 zabbix_server
 7465 ?        00:00:00 zabbix_server

We need to install the Zabbix frontend that will be used to manager the zabbix and their clients

aptitude install zabbix-frontend-php php5-pgsql -y

Now we need to create the Virtualhost that will be used by the Zabbix Frontend

vim /etc/apache2/sites-available/zabbix.conf
<VirtualHost *:80>
    ServerAdmin webmaster@douglasqsantos.com.br
    ServerName zabbix.douglasqsantos.com.br
    DocumentRoot /usr/share/zabbix

<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_php5.c>
	    php_value max_execution_time 300
	    php_value memory_limit 128M
	    php_value post_max_size 16M
	    php_value upload_max_filesize 2M
	    php_value max_input_time 300
	    php_value always_populate_raw_post_data -1
	    php_value date.timezone America/Sao_Paulo
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Require all denied
    <files *.php>
      Require all denied
    </files>
</Directory>

<Directory "/usr/share/zabbix/app">
    Require all denied
    <files *.php>
      Require all denied
    </files>
</Directory>

<Directory "/usr/share/zabbix/include">
    Require all denied
    <files *.php>
      Require all denied
    </files>
</Directory>

<Directory "/usr/share/zabbix/local">
    Require all denied
    <files *.php>
     Require all denied
    </files>
</Directory>
   ErrorLog /var/log/apache2/zabbix.douglasqsantos.com.br-error.log
   LogLevel warn
   CustomLog /var/log/apache2/zabbix.douglasqsantos.com.br-access.log combined
</VirtualHost>

Now we need to disable the default virtual host, the default zabbix configuration and enable the zabbix's virtual host

a2dissite 000-default.conf
a2disconf zabbix.conf
a2ensite zabbix.conf

Now restart the apache server like this

systemctl restart apache2

Now we need to configure the frontend access http://192.168.25.150 or http://zabbix.douglasqsantos.com.br

  • In the first page click on Next
  • If the all prerequisites is ok click on Next or configure the ones that need to be fixed
  • Here we need to configure the Database:
    • Database type: PostgreSQL
    • Database host: localhost
    • Database port: 0
    • Database name: zabbix
    • User: zabbix
    • Password: AwX2O0k83mU40TS
    • Click in Next
  • Now we need to only to click on Next because the default configuration is ok
  • Now click on Next again
  • Now click on Finish

Now we can login as user: Admin password: zabbix

Let's install the packets to enable the Zabbix Client, here needs to install the zabbix-get too to get information about the clients and to troubleshooting the problems.

aptitude install zabbix-agent zabbix-get  -y

Now let's create the PSK agent key.

openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk

Now needs to configure the client the configuration is very simple we need to change only two lines

vim /etc/zabbix/zabbix_agentd.conf
[...]
Server=127.0.0.1
[...]
Hostname=Zabbix server
[...]
TLSConnect=psk
[...]
TLSAccept=psk
[...]
TLSPSKIdentity=PSK_Zabbix_Server
[...]
TLSPSKFile=/etc/zabbix/zabbix_agentd.psk

Now we need to remove the current file on the zabbix_agentd.d

rm -rf /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

Now needs to restart the Zabbix client service like this

systemctl restart zabbix-agent

Let's double check if the zabbix-agent is working properly as we need

ps -C zabbix_agentd
  PID TTY          TIME CMD
 9930 ?        00:00:00 zabbix_agentd
 9932 ?        00:00:00 zabbix_agentd
 9933 ?        00:00:00 zabbix_agentd
 9934 ?        00:00:00 zabbix_agentd
 9935 ?        00:00:00 zabbix_agentd
 9936 ?        00:00:00 zabbix_agentd

Let's get the kernel version from the client

zabbix_get -s127.0.0.1 -p10050 -ksystem.uname --tls-connect psk --tls-psk-identity "PSK_Zabbix_Server" --tls-psk-file /etc/zabbix/zabbix_agentd.psk
Linux noc01 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64

Now getting the agent version like this

zabbix_get -s127.0.0.1 -p10050 -kagent.version --tls-connect psk --tls-psk-identity "PSK_Zabbix_Server" --tls-psk-file /etc/zabbix/zabbix_agentd.psk
3.2.4

Now we can access http://10.0.0.136 or http://zabbix.douglasqsantos.com.br inform the user and password

After log in into zabbix webinterface we ned to configure the Zabbix Server as Zabbix Client.

  • Configuration/Hosts
  • Click on Zabbix Server
  • Select Encryption
    • Select in Connetions to hosts: PSK
    • Select in Connections from host: PSK
      • PSK Identity: PSK_Zabbix_Server
      • PSK: Here we need to put the value of (cat /etc/zabbix/zabbix_agentd.psk) it will be something like: 0582bd62e1cc1a257260ea6b99d0cfc4cfd20d3f6a794c9ad830efe8b56a9c30
    • Now Click in Host Inventory
      • Select Automatic
    • Now click Host and Select Enabled
  • Now select Update

Now we need to restart the Zabbix client service like this

systemctl restart zabbix-agent

Let's configure the Zabbix Proxy, sometimes we need to have monitoring inside large organizations and we do not have all the access that we need, so we can configure the Zabbix Proxy inside the organization to send information to Zabbix Server.

Note: The Zabbix Proxy is configured in another host rather than Zabbix Server.

Now we need to install the necessary packages, let's start installing the database, we need the database to get all the information from the client store it and send to Zabbix server.

aptitude install postgresql postgresql-client postgresql-common postgresql-contrib postgresql-doc postgresql-server-dev-all -y

Now we need to configure the password of postgres

su - postgres

Now we need to access the psql

psql

Changing the password

ALTER USER postgres WITH PASSWORD 'McW1k8v020E9VqA';
\q

Now we need to login into postgresql with the new password

psql -h localhost -U postgres -W
CREATE USER zabbix WITH PASSWORD 'AwX2O0k83mU40TS';

Now let's create the database that will be used by the Zabbix Proxy

CREATE DATABASE zabbix WITH OWNER zabbix;

Let's configure the Zabbix Proxy.

Let's install the repo

cd /tmp
wget -c http://repo.zabbix.com/zabbix/3.2/debian/pool/main/z/zabbix-release/zabbix-release_3.2-1+jessie_all.deb
dpkg -i zabbix-release_3.2-1+jessie_all.deb

Now let's install the Zabbix Proxy and the agent

aptitude update && aptitude install zabbix-agent zabbix-get zabbix-sender zabbix-proxy-pgsql snmp -y

Now we need to unzip the database schema

cd /usr/share/doc/zabbix-proxy-pgsql/
gunzip  schema.sql.gz

Now we need to export the password to the environment so we can import the schema without any prompt about the password

export PGPASSWORD="AwX2O0k83mU40TS"

Now let's import the schema

psql -h localhost -U zabbix -d zabbix -f schema.sql

Now let's create the psk that will be used by the Zabbix Proxy

openssl rand -hex 32 > /etc/zabbix/zabbix_proxy.psk

Let's configure the zabbix_proxy.conf

vim /etc/zabbix/zabbix_proxy.conf
[...]
ProxyMode=0
[...]
# Zabbix Server
Server=10.0.0.136
[...]
# This name will be used into the Zabbix server to get information about the Clients
Hostname=zabbix-proxy
[...]
# Database
DBName=zabbix
[...]
# User of Database
DBUser=zabbix
[...]
# Password of database
DBPassword=AwX2O0k83mU40TS
[...]
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
TLSConnect=psk
[...]
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
TLSAccept=psk
[...]
### Option: TLSPSKIdentity
#       Unique, case sensitive string used to identify the pre-shared key.
#
# Mandatory: no
# Default:
TLSPSKIdentity=PSK_Zabbix_Proxy_Server
[...]
### Option: TLSPSKFile
#       Full pathname of a file containing the pre-shared key.
#
# Mandatory: no
# Default:
TLSPSKFile=/etc/zabbix/zabbix_proxy.psk

Now we need to restart the Zabbix Proxy

systemctl restart zabbix-proxy

Now log into the Zabbix Server WebInterface

  • Administration/Proxies
    • Create Proxy
      • Proxy name: zabbix-proxy
      • Proxy mode: Active
    • Encryption
      • Connections from proxy: PSK
      • PSK identity: PSK_Zabbix_Proxy_Server
      • PSK: the value will be the result of (cat /etc/zabbix/zabbix_agentd.psk) will be something like: cafdb6c73f6a63b15ffa65d2e07c23639c5c53c2a860451172402912238b65c2
      • Now Click Update