Deploying NGINX-based web server | Part 3 – Monitoring with Zabbix

Since our WordPress site is now live, it’d be nice to know it’s state, how well it’s handling the load and, if necessary, give ourselves a heads up in case things go south and our blog suddenly skyrockets in popularity, exhausting all available resources and making it unusable for majority of visitors.

This is what monitoring is for. In this article, we’re going to look at Zabbix. To get most out of Zabbix, we will need to deploy another server (N2-STUB-ZABBIX) alongside to our already deployed N2-STUB-WEB-SRV and set up a Zabbix server so it can gather information about agents. Agents are basically hosts reporting to the mothership (in our case, N2-STUB-ZABBIX).

Let’s deploy another Debian VM real quick. Make sure it’s on the same network as our N2-STUB-WEB-SRV so we don’t have to worry about any of the networking stuff.

Note: I’m going to assume sudo and vim are installed. You might have to install them to execute commands as superuser (if you prefer not to use root account). Instructions can be found at the beginning of this article.

Now that our VM is up and running, we will need to get ourselves Zabbix repository. Repository will extend the pool of packets we can download using APT, allowing us to download latest Zabbix release.

Following official documentation, to install Zabbix’s repo, do:

wget https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb # download a .deb package that's going to add zabbix repo to list of available repositories on our system
dpkg -i zabbix-release_4.0-2+stretch_all.deb # install the downloaded .deb
apt update # update package lists

And now we’re going to install our Zabbix server with MySQL support. Luckily, we’ve gained some experience with SQL from my last article 🙂

sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent

This should will show us quite a few packets to be installed:

MariaDB, we meet again! Let’s make sure all the (unsafe) defaults are disabled:

sudo mysql_secure_installation

Pop in your root password, and say no to the first question and yes to the rest of them. All the questions are explained in the application.

Now, let’s create a database that our Zabbix server will use to store records:

sudo mysql # login as root to mariadb server

And now, let’s redo procedure from my last article, changing it accordingly:

CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin; # create database zabbix with utf8 encoding
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_password'; # change your_password to an actual password
GRANT ALL ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
EXIT;

And now import initial schema to our new database (make sure you’re back to bash):

sudo sh -c 'zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix -p zabbix'

sudo sh -c ‘zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix -p zabbix

This will import contents of create.sql.gz file into our MariaDB database ‘zabbix’ as user ‘zabbix’. You will be asked for password you chose just a second ago in SQL.

If that’s been done, let’s configure Zabbix so it’s able to connect to our new database:

sudo nano /etc/zabbix/zabbix_server.conf # This will open zabbix_server.conf config file in Nano text editor. You're free to replace nano with, for example, Vim/Emacs

To the bottom of the file, add:

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password> # replace with your actual password

and save the file. Let’s head to /etc/apache2/conf-enabled/zabbix.conf and set our timezone:

sudo nano /etc/apache2/conf-enabled/zabbix.conf

and uncomment (remove #) and edit following line:

# php_value date.timezone Europe/Riga

to:

php_value date.timezone Europe/London

Additionally, head to /etc/php/7.0/apache2/php.ini and edit following line:

;date.timezone = 

to:

date.timezone = Europe/London

If you’re not from UK, change the timezone to match your country.

One of our last steps is to configure the agent running on our Zabbix server. Edit zabbix_agentd.conf file by opening it first:

 sudo nano /etc/zabbix/zabbix_agentd.conf

and under line that says:

Server=127.0.0.1

add:

ListenPort=10050

That will point our agent at the Zabbix server (itself) and listen on port 10050. Save the file and move to the next step.

We’re done configuring our Zabbix Agent/Server (at least from the terminal). Let’s restart Zabbix processes for changes to take effect

sudo systemctl restart zabbix-server zabbix-agent apache2

Above should produce no errors. Let’s open our browser now and head to the IP address of our VM plus “/zabbix”:

Tadaaaa!

Let’s head to the next step. Ideally, everything should be green:

Let’s go to next step again. We will be now asked to provide details of the database we’ve created at the beginning of this article. Let’s fill all the fields out and press Next Step:

In the next field we can leave everything as default, although I’ll name my installation to match my VM name (N2-STUB-ZABBIX) and proceed to next step:

Next screen gives us a nice summary of (almost) all provided information. Review them quickly and, if everything looks fine, press Next Step:

If you’re welcomed with following screen, congratulations! If not, please review the article again and see if your configs are missing some lines mentioned in this post or if you made some spelling mistakes.

You will be taken to login screen. To log in, use following credentials:
Login: Admin
Password: zabbix

Bear in mind these are created by default and I strongly encourage you to change the password to something more complicated.

In next article, we will add some simple alerts to our Zabbix server. In future, we will be looking at creating multiple WordPress servers with a load-balancer in front of them and various techniques of eliminating single-points-of-failure. Eventually, we are going to switch to using hostnames that our DNS server will resolve for us.

It’s 21:37 and I’ve just realized I have nothing ready for tomorrow. Well, at least I’ll get more than 6 hours of sleep, ha!

Stay tuned and have a lovely evening! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Navigation