5 min,  mysql,  Zabbix

Zabbix 6 good practice 2022 + Azure install 2 VM’s (zabbix and mysql)

Note:

Install Zabbix Server package without installing MySQL server : zabbix (reddit.com)

apt-get install zabbix-server-mysql --no-install-recommends

# Install Zabbix server without MySQL (MySql will be on remote host)

apt install zabbix-server-mysql --no-install-recommends zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent

software installation – What are the implications of –no-install-recommends (apt-get install)? – Ask Ubuntu

Note check mysql installed

dpkg --get-selections | grep mysql

It must be the last package

Does MySQL get installed, is zabbix-server-mysql MySql:

sudo service mysql status
sudo ps aux | grep mysql
sudo lsof -i :3306
# lsof lists many connections so it does

Getting Zabbix 6, there are 4 ways, 5 with Azure market.

Microsoft Azure Marketplace

Robust and durable, allowing to efficiently process up to 100,000 new metrics per second

Read the above link if you need if you need.

Must also look at cost 2 VM’s vs Market

What the best?

Actual configuration depends on the number of active items and refresh rates very much (see database size section of this page for details). It is highly recommended to run the database on a separate box for large installations.

4.1 Getting Zabbix

1 Getting Zabbix

Install it from the distribution packages =
Download the latest source archive and compile it yourself =
Install it from the containers =
Download the virtual appliance =

4.2 Requirements

2 Requirements (zabbix.com)

# get OS information
cat /etc/os-release)



# edit file: nano file_name
# when done: ctrl + x)

Memory

# get memory information
vmstat -s (in kilobyte))

The amount of required disk memory obviously depends on the number of hosts and parameters that are being monitored. If you’re planning to keep a long history of monitored parameters, you should be thinking of at least a couple of gigabytes to have enough space to store the history in the database. Each Zabbix daemon process requires several connections to a database server. The amount of memory allocated for the connection depends on the configuration of the database engine.

The more physical memory you have, the faster the database (and therefore Zabbix) works!

CPU

# get CPU information
lscpu

Zabbix and especially Zabbix database may require significant CPU resources depending on number of monitored parameters and chosen database engine.

Disk or mount point

Linux Check Disk Space Command To View System Disk Usage (df and du) | blog.imm.cnr.it

# human readble
df -h

Default port numbers

Database size

Zabbix database size mainly depends on these variables, which define the amount of stored historical data:

  • Number of processed values per second
    This is the average number of new values Zabbix server receives every second. For example, if we have 3000 items for monitoring with a refresh rate of 60 seconds, the number of values per second is calculated as 3000/60 = 50.

It means that 50 new values are added to Zabbix database every second.

  • Housekeeper settings for history
    Zabbix keeps values for a fixed period of time, normally several weeks or months. Each new value requires a certain amount of disk space for data and index.

So, if we would like to keep 30 days of history and we receive 50 values per second, the total number of values will be around (30243600)* 50 = 129.600.000, or about 130M of values.

Depending on the database engine used, type of received values (floats, integers, strings, log files, etc), the disk space for keeping a single value may vary from 40 bytes to hundreds of bytes. Normally it is around 90 bytes per value for numeric items2. In our case, it means that 130M of values will require 130M * 90 bytes = 10.9GB of disk space.

  • Housekeeper setting for trends
    Zabbix keeps a 1-hour max/min/avg/count set of values for each item in the table trends. The data is used for trending and long period graphs. The one hour period can not be customized.

Zabbix database, depending on the database type, requires about 90 bytes per each total. Suppose we would like to keep trend data for 5 years. Values for 3000 items will require 300024365* 90 = 2.2GB per year, or 11GB for 5 years.

So, the total required disk space can be calculated as:
Configuration + History + Trends + Events
The disk space will NOT be used immediately after Zabbix installation. Database size will grow then it will stop growing at some point, which depends on housekeeper settings.

4.2 Requirements

Best practices for secure Zabbix setup

HTTPS

4. 4 Windows agent installation from MSI

4 Windows agent installation from MSI (zabbix.com)

Zabbix Windows agent can be installed from Windows MSI installer packages (32-bit or 64-bit) available for download.

A 32-bit package cannot be installed on a 64-bit Windows.

All packages come with TLS support, however, configuring TLS is optional.

Both UI and command-line based installation is supported.

6 Sender (zabbix.com)

An example of running Zabbix UNIX sender:

shell> cd bin
shell> ./zabbix_sender -z zabbix -s “Linux DB3” -k db.connections -o 43

where:

z – Zabbix server host (IP address can be used as well)
s – technical name of monitored host (as registered in Zabbix frontend)
k – item key
o – value to send

Zabbix sender can be used to send multiple values from an input file. See the Zabbix sender manpage for more information.

If a configuration file is specified, Zabbix sender uses all addresses defined in the agent ServerActive configuration parameter for sending data. If sending to one address fails, the sender tries sending to the other addresses. If sending of batch data fails to one address, the following batches are not sent to this address.

Zabbix sender accepts strings in UTF-8 encoding (for both UNIX-like systems and Windows) without byte order mark (BOM) first in the file.

Zabbix sender on Windows can be run similarly:

zabbix_sender.exe [options]

7 Configuration

7.3 History and trends

3 History and trends (zabbix.com)

The general strong advice is to keep history for the smallest possible number of days and that way not to overload the database with lots of historical values.

Instead of keeping a long history, you can keep longer data of trends. For example, you could keep history for 14 days and trends for 5 years.

Cache

Zabbix agent cache (Windows Server) – ZABBIX Forums

Zabbix Top 5 Mistakes

  • Choose DB depending on your experience
  • Tune Zabbix configuration file carefully.
  • Do not maximize number of pollers, trappers and etc. In order to optimize your Zabbix conf->have a look at Zabbix server graphs first
  • Use template instead of manually adding metrics/items to hosts.
  • Do not mess with HA if your Zabbix instance is small
  • Create more complex triggers in order to avoid unnecessary problems/alerts (i.e use avg, sum, max, min inside your trigger expression)

Ryan Armstrong – Monitoring More Than 6000 Devices in Zabbix | Zabbix Conference 2016 – YouTube

Download and install Zabbix

Download and install Zabbix 6.0 LTS for Ubuntu 20.04 (Focal), MySQL, Apache

Script findings and repository

azure-arm-104/10_zabbix at master · spawnmarvel/azure-arm-104 · GitHub

We can test to use Azure Database for MySql servers also.

But for this test it will be 2 clean Ubuntu VM’s

VM info

All traffic from the internet will be blocked by default. We will change inbound port rules on the VM->Networking page after it has been created to use Putty on port 22

Basics
  • vm-mysql
    • Resource grouptest-monitor
    • Virtual machine name vm-mysql
    • Region West Europe
    • Availability options No infrastructure redundancy required
    • Security typeStandard
    • Image Ubuntu Server 20.04 LTS – Gen2SizeStandard D2s v3 (2 vcpus, 8 GiB memory)
    • Authentication typePassword
    • Username ladmin
    • Public inbound ports None
    • Azure SpotNo
    • Auto-shutdown 19:00
    • A public IP

    Basics
  • vm-zabbix
    • Resource grouptest-monitor
    • Virtual machine name vm-zabbix
    • Region West Europe
    • Availability options No infrastructure redundancy required
    • Security typeStandard
    • Image Ubuntu Server 20.04 LTS – Gen2SizeStandard D2s v3 (2 vcpus, 8 GiB memory)
    • Authentication typePassword
    • Username ladmin
    • Public inbound ports None
    • Azure SpotNo
    • Auto-shutdown 19:00

    Now add the SSH rule to both VM’s or use a NSG (Global for this)

    Check that you are allowed to connect

    Now test Putty or AZ CLI

    Run the example command below to connect to your VM or get the IP and use in Putty

    Ok, lets create login to the next VM.

    Install MySQL

    # update the vm
    sudo apt update
    
    #  install mysql server
    sudo apt install mysql-server
    
    # secure mysql (SKIP THIS FOR NOW)
    sudo mysql_secure_installation
    
    # In the last step I kept all for the test, pass is the same as for VM.
    # But that is not the correct for secure installation, choose several “YES”, you will see when you do it.
    
    # Test 
    sudo mysql
    
    # query
    select now();
    
    # exit
    exit;
    

    Check that you can ping vm-zabbix

    ping private-ip or hostname

    Do the same from the vm-zabbix to vm-mysql

    Install Zabbix

    Download and install Zabbix 6.0 LTS for Ubuntu 20.04 (Focal), MySQL, Apache

    NOTE: All the cmds for zabbix: wget and dpkg is for zabbix 6.2. Remember that, the link above is changed to 6.0

    # Install Zabbix repository this is for 6.2, change to 6
    wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-1+ubuntu20.04_all.deb
    
    # this is for 6.2, change to 6
    sudo dpkg -i zabbix-release_6.2-1+ubuntu20.04_all.deb
    
    sudo apt update
    
    # Install Zabbix server for mysql, frontend, agent
    sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent

    Now zabbix is up.

    Now back to vm-mysql

    2 Repairing Zabbix database character set and collation

    # Create initial database
    sudo mysql
    # the mb4 gives an empty user table
    # mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
    
    # use
    
    mysql> create database zabbix character set utf8 collate utf8_bin;
    
    
    mysql> create user zabbix@IP-of-vm-zabbix identified by 'password';
    
    # check user and host
    mysql> select user, host from mysql.user;
    
    
    # grant all to zabbix
    mysql> grant all privileges on zabbix.* to zabbix@IP-of-vm-zabbix;
    
    # (on zabbix 6 this it not needed only 6.2)
    mysql> SET GLOBAL log_bin_trust_function_creators = 1;
    mysql> quit;
    

    Copy the create file from vm-zabbix to vm-mysql, Next thing we have to do is upload the correct schemas for the Zabbix installation. For this, we have to copy the schemas from the Zabbix server (the zabbix-mysql-server package)

    You could also use sftp with filezilla or scp (Securely Transfer Files)

    Or you can perform the query from remote:

    On vm-mysql comment out the bind adr with # on the file mysqld.cnf

    
    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    # or navigate to and use sudo nano mysqld.cnf
    
    # ctrl x and yes for saving
    sudo service mysql stop
    sudo service mysql start
    sudo service mysql status

    Now the vm-zabbix host can connect

    
    mysql -u zabbix -h IP-ofmysql -p
    #give the zabbix password

    Now lets import and make schemas

    ladmin@vm-zabbix:/usr/share/doc/zabbix-sql-scripts/mysql$ zcat server.sql.gz | mysql -u zabbix -h IP-of-vm-mysql -p zabbix
    
    # Enter password for zabbix user
    

    On the vm-mysql run (on zabbix 6 this it not needed only 6.2)

    sudo mysql
    SET GLOBAL log_bin_trust_function_creators = 0;
    

    Now check the zabbix database and view all tables

    sudo mysql
    use zabbix;
    show tables;

    Configure the database for Zabbix server

    Edit file /etc/zabbix/zabbix_server.conf

    # take a backup of config
    sudo cp zabbix_server.conf zabbix_server.conf.bck
    
    # edit the file
    sudo nano zabbix_server.conf
    
    sudo service zabbix-server status
    # check that it is running
    
    
    # stop it
    sudo service zabbix-server status
    
    
    
    # DBPassword=password
    # DBHost=IP to MySQL
    # DBName=zabbix
    # DBUser=zabbix
    # DBPort=3306
    
    # ctrl x + y
    

    Hm, zabbix would not start again, view logs

    # Check log file
    tail -f /var/log/zabbix/zabbix_server.log

    Cannot start docker image of zabbix-server-mysql: ‘cannot use database “zabbix”: its “users” table is empty (is this the Zabbix proxy database?)’ – Stack Overflow

    Nice bro, it turns out i was creating MySQL database with utf8mb4 and utf8mb4_bin and after recreating the database with utf8 the problem was solved!

    Ok, let drop the database and recreate it with utf8

    On vm-zabbix stop zabbix

    On vm-mysql drop the database zabbix

    mysql> drop database zabbix;
    
    # the recreate it
    
    mysql> create database zabbix character set utf8 collate utf8_bin;
    
    # check that we have the user
    mysql> select user, host from mysql.user;
    
    # grant again
    mysql> grant all privileges on zabbix.* to zabbix@ip-to-zabbix;
    
    # show databases
    mysql> show databases;
    
    # (on zabbix 6 this it not needed only 6.2)
    SET GLOBAL log_bin_trust_function_creators = 1;
    

    Now we must load the zip file again

    ladmin@vm-zabbix:/usr/share/doc/zabbix-sql-scripts/mysql$ zcat server.sql.gz | mysql -u zabbix -h 10.1.0.4 -p zabbix
    
    Enter password:
    

    That did succseed

    vm-zabbix

    vm-mysql, check the table users

    sudo mysql
    mysql> use zabbix;
    mysql> show tables;
    mysql> select * from users;
    
    # (on zabbix 6 this it not needed only 6.2)
    # Disable log_bin_trust_function_creators option after importing database schema.
    
    SET GLOBAL log_bin_trust_function_creators = 0;

    Ok, start zabbix with the edited configuration

    sudo service zabbix-server start
    
    
    sudo service zabbix-server status
    
    # check log
    tail -f /var/log/zabbix/zabbix_server.log
    # check agent
    
    sudo service zabbix-agent status
    

    Configure Zabbix frontend

    # after config changes restart apache also
    
    sudo service apache2 stop
    sudo service apache2 status
    sudo service apache2 start
    sudo service apache2 status
    

    6 Web interface installation (zabbix.com)

    Navigate to

    http://vm-zabbix-public-ip21-or-private/zabbix

    after you have create a NSG rule for port 80 on the vm-zabbix (we now have two, ssh and http)

    The web should be ready

    get all and go next

    use the vm-mysql private ip

    Name the server, use correct timezone

    And we are done

    Login with default Admin and zabbix

    Restart both vm and see if all is running

    Nope, it was not running, it must be enabled

    sudo systemctl enable zabbix-server zabbix-agent apache2
    
    # restart server
    
    sudo shutdown -r now

    And it is automatic up

    Note

    sudo ufw allow 3306/tcp on vm-mysql maybe I did?
    sudo ufw allow 10051/tcp on vm-zabbix for sending data

    What did we create in Azure

    test-monitor-vnet | Subnets

    Comments Off on Zabbix 6 good practice 2022 + Azure install 2 VM’s (zabbix and mysql)