Schulung-Teil5-Zabbix aufsetzen

From revampedia
Jump to: navigation, search

Vorwort


This training sessioin took place on 02-02-17. If you have serveral servers it's advisable to monitor them. For that you need a Netzwerk-Management-Tool. In our case we chose Zabbix, as we're already using that on our productive server.
The installation requires a web server, in our case an Apache and also a MySQL-database. As the links show, they are building on our past training sessions.
This documentation was the base for our installation. Some things are outdated that the synthax is no longer correct. We chose version 3.0, as that is the LTS-version of the program.
For our training purposes we created the username "zabbix" in the MySQL-database. For security purposes, you should pick a different name in a productive system.

If there are still questions open after these instructions, please go to "Views" and then "Discussion" to leave your feedback, so I can add more Details to this page. jr



Installation of the program

Installing the package

As we're installing the LTS version in our training session, we have to add an additional repository in Debian Jessie. To do that we need to modify the file /etc/apt/sources.list on our virtual machine.

user1@vm1:~$ sudo nano /etc/apt/sources.list
# jessie-backports
deb     http://debian.ethz.ch/debian/     jessie-backports main contrib non-free


You simply copy the line under Jessie and add it a second time to the file. Then you need to change "jessie" into "jessie-backports". Alternatively you create a new file under /etc/apt/sources.list.d/ with the new repository.

To be able to use the repository from jessie-backports, we have to update the package listin apt:

user1@vm1:~$ sudo apt update


The following command shows us why we've added the repository from jessie-backports. The regular jessie repository only has version 2.2 and we want to use version 3.0.

user1@vm1:~$ apt-cache policy zabbix-server-mysql
zabbix-server-mysql:
 Installed: (none)
 Candidate: 1:2.2.7+dfsg-2+deb8u1
 Version table:
    1:3.0.7+dfsg-1~bpo8+1 0
       100 http://debian.ethz.ch/debian/ jessie-backports/main amd64 Packages
    1:2.2.7+dfsg-2+deb8u1 0
       500 http://debian.ethz.ch/debian/ jessie/main amd64 Packages


To be able to install the desired version of the program, we need to set the parameter "-t jessie-backports":

user1@vm1:~$ sudo apt -t jessie-backports install zabbix-server-mysql zabbix-frontend-php


Configuration in the CLI

Our next step is to activate the configuration of zabbix-frontend-php on our apache2 server. To do this, we enter the following command:

user1@vm1:~$ sudo a2enconf zabbix-frontend-php


If we would restart the web server now, we could access the configuration of our new program under http://"VM-IP-address"/zabbix, but we're still missing some steps to be able to do that.
There are two options to restart the web server:

user1@vm1:/etc/apache2/conf-available$ sudo apache2ctl restart
user1@vm1:~$ sudo systemctl restart apache2

The difference between the two commands is that apache2ctl also checks the configuration files of the web server.
First we go to the directory /etc/, where configurations files are stored in linux.

user1@vm1:~$ cd /etc/


Next we search for "date.timezone" in this directory and it's subdirectories. We also tell the search to ignore lower and upper case writing

user1@vm1:/etc$ grep -ri 'date.timezone'


The file we're looking for is in /etc/apache2/conf-available/, so we change to that directory and make a copy of the file:

user1@vm1:/etc/apache2/conf-available$ sudo cp zabbix-frontend-php.conf zabbix-frontend-php.conf_2017-03-02


Next we edit the file:

user1@vm1:/etc/apache2/conf-available$ sudo nano zabbix-frontend-php.conf
       php_value date.timezone Europe/Zurich


Add user to MySQL database and create a new database

Fortunately we can copy most of it from the documentation of Zabbix that we don't need to know the commands in advance. For a list of MySQL commands you best visit the link. We learned in the training session that MySQL commands need to be finished with a ";". Otherwise the database doesn't know that the command has ended.
So, first we login to the database. We've installed MySQL in a previous training session.

user1@vm1:~$ mysql -uroot -p*****


With the first line we create a new database and tell it that we wish to use the UTF-8-character encoding.

mysql> create database zabbix character set utf8 collate utf8_bin;


With the second command we give the user "zabbix" all rights to the database "zabbix" with the password "*****" (pick your own password here)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '*****';


To leave the MySQL database we type "quit". This command would also work without the ";".

mysql> quit;


Now we need to give our database a schema and the first set of data. As the documentation is outdated, the file /usr/share/doc/zabbix-server-mysql/README.Debian tells us the correct synthax:

zcat /usr/share/zabbix-server-mysql/{schema,images,data}.sql.gz    | mysql -uzabbix -p***** zabbix


Configure Zabbix to interact with the MySQL database and what username it should use

First we make a copy of the configuration file:

user1@vm1:~$ sudo cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf_2017-03-02


Next we edit it. Sometimes the # at the beginning of the line needs to be removed.

user1@vm1:~$ sudo nano /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<*****>


Now we start the service, so that our data will be logged:

user1@vm1:/etc/zabbix$ sudo systemctl start zabbix-server


If you want this service to automatically start when the server boots, you also have to enter the following command:

user1@vm1:/etc/zabbix$ sudo systemctl enable zabbix-server


Configure frontend in the browser

Now that we've prepared everything in the CLI we can go and configure the frontend of Zabbix. Also im Browser auf http://"VM-IP-address"/zabbix. The summary at the end looked like this for me:

 Database type       MySQL
 Database server     localhost
 Database port       default
 Database name       zabbix
 Database user       zabbix
 Database password   *****
     
 Zabbix server       localhost
 Zabbix server port  10051
 Zabbix server name  juerg-zabbix


When you finish in the browser, you will receive an error. It's missing a file on the server that it won't have the premission to create. You get the option to download the file an open it in an editor (geany in our case). The content of the file now needs to be entered into an empty file. It is possible that you'll get another error if there is an empty line at the end of the file. So far I haven't been able to get rid of an empty line at the end of the document in the editor nano. To solve this issue, you best use the editor vim. With "Shift+g" you go to the end of the file and with "dd" you delete that empty line. With ":wq" you save the file and exit the editor. This is how the file looked for me in the end. For each installation, the file will look a bit different.

 user1@vm1:/etc/zabbix$ sudo nano /etc/zabbix/zabbix.conf.php
 <?php
 // Zabbix GUI configuration file.
 global $DB;

 $DB['TYPE']     = 'MYSQL';
 $DB['SERVER']   = 'localhost';
 $DB['PORT']     = '0';
 $DB['DATABASE'] = 'zabbix';
 $DB['USER']     = 'zabbix';
 $DB['PASSWORD'] = '*****';

 // Schema name. Used for IBM DB2 and PostgreSQL.
 $DB['SCHEMA'] = '';

 $ZBX_SERVER      = 'localhost';
 $ZBX_SERVER_PORT = '10051';
 $ZBX_SERVER_NAME = 'juerg-zabbix';

 $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;


If the file was added correctly you get the login mask of Zabbix under http://"VM-IP-address"/zabbix. The username is "Admin" and the password "zabbix".
So far, only the virtual machine that has the Zabbix installed will show up here. To see what machines are monitored or to add a new one we go to "Configuration" and then "Hosts".


Monitor an additional server

In our training session we take the physical server as an additional host. For that we need to install the client program of Zabbix.In unserem Beispiel nehmen wir den physischen Server als zusätzlichen Host im Zabbix auf. Dazu braucht es auf dem Server das "Client-Programm" von Zabbix. We didn't add the jessie-backports repository to the server so far, but that isn't necessary, as also an older version of the client program can communicate with the server.
To make sure that the client program is available we enter the following command:

user1@server1:~$ sudo apt-cache policy zabbix-agent


To install the package we need to enter the next command:

user1@server1:~$ sudo apt install zabbix-agent


After the installation we go to the configuration folder of the Zabbix client and create a copy of the configuration file:

user1@server1:~$ cd /etc/zabbix/
user1@server1:/etc/zabbix$ sudo cp zabbix_agentd.conf zabbix_agentd.conf_2017-03-02


Now we have to edit the configuration file and change a few things:

user1@server1:/etc/zabbix$ sudo nano zabbix_agentd.conf
Server="Zabbix-Server-IP" 
ServerActive="Zabbix-Server-IP"
#Hostname=Zabbix server
HostnameItem=system.hostname


As we've made modifications to the configuration file we need to restart the service of the Zabbix client. The second line shows us the status of the service.

user1@server1:/etc/zabbix$ sudo systemctl restart zabbix-agent
user1@server1:/etc/zabbix$ sudo systemctl status zabbix-agent



In the frontend of Zabbix we can now add the new machine under "Configuration" and then "Hosts" so we monitor this machine as well.,