Install and Configure Zabbix 6.0 on Ubuntu 22.04: Powerful Monitoring Tool

Posted on

Install and Configure Zabbix 6.0 on Ubuntu 22.04: Powerful Monitoring Tool

Install and Configure Zabbix 6.0 on Ubuntu 22.04: Powerful Monitoring Tool

This tutorial will guide you through the process of installing and configuring Zabbix 6.0 on Ubuntu 22.04. Zabbix is a robust, user-friendly, and open-source monitoring solution. It excels at monitoring a wide array of infrastructure components, including servers, networks, IT equipment, cloud platforms, and virtualized environments.

The key features that make Zabbix a popular choice for monitoring include:

  • Open-Source: Free to use and modify, fostering community-driven development.
  • Scalability: Capable of handling large and complex environments with ease.
  • Flexibility: Supports a wide range of monitoring methods and metrics.
  • Comprehensive Visualization: Offers dashboards, graphs, and reports for insightful data analysis.
  • Alerting and Notifications: Provides customizable alerts based on predefined thresholds.
  • Auto-Discovery: Automatically detects and adds new devices to the monitoring system.
  • Agent-Based and Agentless Monitoring: Supports both agent-based and agentless monitoring approaches.

In this guide, we’ll walk through installing and configuring Zabbix 6.0 on Ubuntu 22.04 step-by-step.

Before you begin, ensure you have the following prerequisites:

  • Access to an Ubuntu 22.04 server with a non-root user account with sudo privileges. A basic firewall should also be configured. Refer to a guide like the Initial Server Setup with Ubuntu 22.04 for assistance.
  • A LAMP stack (Apache, MariaDB, PHP) installed on your server. Follow the How To Install LAMP Stack on Ubuntu 22.04 tutorial for instructions.

Once you have these prerequisites in place, you can proceed with the Zabbix 6.0 installation using the following steps:

Step 1 – Configure PHP for Zabbix 6.0 on Ubuntu 22.04

First, install the necessary PHP extensions for Zabbix using the following command:

sudo apt install php-mbstring php-gd php-xml php-bcmath php-ldap php-mysql -y

Next, edit the php.ini file to adjust PHP settings for Zabbix. Open the file using your preferred text editor (e.g., vi):

sudo vi /etc/php/8.1/apache2/php.ini

Locate the following lines and modify their values as indicated:

memory_limit = 256M
upload_max_filesize = 16M
post_max_size = 16M
max_execution_time = 300
max_input_time = 300

Also, find and uncomment the following lines (remove the semicolon at the beginning) and set their values:

max_input_vars = 10000
date.timezone = Etc/UTC

Important: Set the date.timezone to your correct timezone.

Save and close the file. Then, restart Apache to apply the changes:

sudo systemctl restart apache2

Step 2 – Create Zabbix Database and Database User

Create a dedicated database and user account for Zabbix within MariaDB.

Log in to the MariaDB console as the root user:

sudo mysql -u root -p

From the MariaDB shell, execute the following commands to create the Zabbix database:

CREATE DATABASE zabbixdb character set utf8 collate utf8_bin;

Next, create a new user with a strong password:

CREATE USER 'zabbixuser'@'localhost' IDENTIFIED BY 'password';

Grant all privileges on the Zabbix database to the newly created user and enable the log_bin_trust_function_creators option:

GRANT ALL PRIVILEGES ON zabbixdb.* TO 'zabbixuser'@'localhost' WITH GRANT OPTION;
set global log_bin_trust_function_creators = 1;

Finally, flush the privileges and exit the MariaDB console:

FLUSH PRIVILEGES;
EXIT;

Step 3 – Download and Install Zabbix 6.0 on Ubuntu 22.04

Download the Zabbix repository package. Find the latest LTS version on the Zabbix Downloads page.

Add the Zabbix 6.0 LTS repository using these commands:

# sudo wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu22.04_all.deb
# sudo dpkg -i zabbix-release_6.0-4+ubuntu22.04_all.deb

Update the system’s package list:

sudo apt update

Install the Zabbix server, frontend, and agent components:

sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent -y

Step 4 – Start and Enable Zabbix Server on Ubuntu 22.04

Start the Zabbix server and enable it to start automatically on system boot:

# sudo systemctl start zabbix-server
# sudo systemctl enable zabbix-server

Verify that the Zabbix server is running:

sudo systemctl status zabbix-server

You should see output similar to this:

Output
● zabbix-server.service - Zabbix Server
     Loaded: loaded (/lib/systemd/system/zabbix-server.service; enabled; vendor>
     Active: active (running) since Wed 2023-05-31 10:39:04 UTC; 21s ago
   Main PID: 15800 (zabbix_server)
      Tasks: 1 (limit: 4575)
     Memory: 3.1M
        CPU: 53ms
     CGroup: /system.slice/zabbix-server.service
             └─15800 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf

Step 5 – How To Import Zabbix Database Schema?

Import the Zabbix database schema into the database you created earlier:

zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -u zabbixuser -p zabbixdb

Enter the password for the zabbixuser when prompted.

After importing the database, disable the log_bin_trust_function_creators option:

sudo mysql -u root -p
MariaDB [(none)]> set global log_bin_trust_function_creators = 0;
MariaDB [(none)]> quit;

Step 6 – Edit Zabbix Configuration File on Ubuntu 22.04

Edit the Zabbix server configuration file to specify the database connection details:

sudo vi /etc/zabbix/zabbix_server.conf

Uncomment and modify the following lines to match your database settings:

DBHost=localhost
DBName=zabbixdb
DBUser=zabbixuser
DBPassword=password

Save and close the file. Restart the Zabbix server and Apache to apply the changes:

# sudo systemctl restart zabbix-server
# sudo systemctl restart apache2

Step 6 – Configure Zabbix 6.0 Agent on Ubuntu 22.04

Configure the Zabbix agent on your Ubuntu 22.04 server:

sudo vi /etc/zabbix/zabbix_agentd.conf

Modify the following lines:

Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix Server

Save and close the file. Start and enable the Zabbix agent:

# sudo systemctl start zabbix-agent
# sudo systemctl enable zabbix-agent

Verify that the Zabbix agent is running:

sudo systemctl status zabbix-agent

You should see output similar to:

Output
● zabbix-agent.service - Zabbix Agent
     Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-05-31 10:38:02 UTC; 19min ago
   Main PID: 15354 (zabbix_agentd)
      Tasks: 6 (limit: 4575)
     Memory: 6.3M
        CPU: 671ms
     CGroup: /system.slice/zabbix-agent.service
             └─15354 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
...

Step 7 – How To Access Zabbix 6.0 Dashboard?

Access the Zabbix web interface by navigating to your server’s IP address followed by /zabbix in your web browser:

http://your-server-ip/zabbix

Follow the on-screen instructions in the Zabbix frontend setup wizard:

  1. Select your desired language.
  2. Verify that all prerequisites are met.
  3. Enter the database connection details.
  4. Configure the Zabbix server details (server name, default theme).
  5. Review the pre-installation summary.
  6. Click "Finish" to complete the installation.

Finally, log in to the Zabbix dashboard using the default credentials:

  • Username: Admin
  • Password: zabbix

Step 8 – How To Change Zabbix Admin User Password?

After logging in, change the default administrator password for security reasons.

  1. Click on "Administration" in the left-hand menu.
  2. Click on "Users."
  3. Click on the "Admin" user.
  4. Click on the "Change password" tab.
  5. Enter your desired new password and click "Update."

Congratulations! You have successfully installed and configured Zabbix 6.0 on Ubuntu 22.04.

Conclusion

This guide has covered the steps to install and configure Zabbix 6.0 LTS Server and Agent on Ubuntu 22.04. Zabbix is a powerful monitoring solution for servers, networks, IT components, cloud services, and virtual machines.

Alternative Solutions

While the above method is a common way to install and configure Zabbix, here are two alternative approaches:

1. Using Docker Compose

Docker Compose provides a simplified way to deploy multi-container applications. This approach involves using a pre-built Zabbix Docker image and configuring it with Docker Compose. This can be faster and cleaner than installing all the components directly on the host system, especially if you’re familiar with Docker.

Explanation:

This method packages all Zabbix dependencies into containers. Docker Compose handles the network and volume configuration. This eliminates the need to manually configure PHP, MariaDB, and other components. You can easily upgrade Zabbix by simply updating the Docker image version.

Steps:

  1. Install Docker and Docker Compose:

    sudo apt update
    sudo apt install docker.io docker-compose -y
  2. Create a docker-compose.yml file:

    version: "3.8"
    services:
      db:
        image: mariadb:10.6
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: root_password
          MYSQL_DATABASE: zabbixdb
          MYSQL_USER: zabbixuser
          MYSQL_PASSWORD: password
        volumes:
          - db_data:/var/lib/mysql
    
      zabbix-server:
        image: zabbix/zabbix-server-mysql:latest
        ports:
          - "10051:10051"
        volumes:
          - ./zabbix_server.conf:/etc/zabbix/zabbix_server.conf
        environment:
          DB_SERVER_HOST: db
          DB_SERVER_PORT: 3306
          MYSQL_USER: zabbixuser
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: zabbixdb
        depends_on:
          - db
        restart: always
    
      zabbix-web-nginx:
        image: zabbix/zabbix-web-nginx:latest
        ports:
          - "8080:8080"
          - "8443:8443"
        environment:
          PHP_TZ: "Etc/UTC"  #Set correct TimeZone
          ZBX_SERVER_HOST: zabbix-server
        depends_on:
          - zabbix-server
        restart: always
    
    volumes:
      db_data:

    Explanation of docker-compose.yml:

    • db: Defines the MariaDB container.
      • image: Uses the official MariaDB image.
      • environment: Sets environment variables for database configuration. Important: Replace root_password, password, and zabbixuser with your desired values.
      • volumes: Creates a volume to persist the database data.
    • zabbix-server: Defines the Zabbix server container.
      • image: Uses the official Zabbix server image with MySQL support.
      • ports: Exposes the Zabbix server port (10051).
      • environment: Sets environment variables to connect to the database.
      • depends_on: Ensures the database container starts before the Zabbix server.
    • zabbix-web-nginx: Defines the Zabbix web interface container using Nginx.
      • image: Uses the official Zabbix web interface image with Nginx.
      • ports: Exposes the web interface ports (8080 and 8443).
      • environment: Set correct timezone
      • depends_on: Ensures the Zabbix server container starts before the web interface.
    • volumes: Defines the named volume for persistent database storage.
  3. Create a custom zabbix_server.conf file (optional): If you need to customize the Zabbix server configuration beyond environment variables, create a zabbix_server.conf file and mount it as a volume (as shown in the docker-compose.yml file). Otherwise, remove the line from the file.

  4. Start the containers:

    docker-compose up -d

    This command will download the necessary images and start the containers in detached mode.

  5. Access the Zabbix web interface: Open your web browser and navigate to http://your-server-ip:8080.

  6. Login: Use the default credentials (Admin/zabbix).

2. Using Ansible Automation

Ansible is an open-source automation tool that can be used to automate the entire Zabbix installation and configuration process. This is particularly useful for deploying Zabbix across multiple servers or for ensuring consistent configurations.

Explanation:

Ansible uses playbooks to define the desired state of your system. You can create an Ansible playbook that automates all the steps outlined in the original article, including installing dependencies, creating the database, configuring the Zabbix server and agent, and starting the services.

Example Playbook (zabbix_install.yml):

---
- hosts: all
  become: true
  vars:
    zabbix_db_name: zabbixdb
    zabbix_db_user: zabbixuser
    zabbix_db_password: password
    zabbix_server_ip: "127.0.0.1"

  tasks:
    - name: Install required packages
      apt:
        name:
          - php-mbstring
          - php-gd
          - php-xml
          - php-bcmath
          - php-ldap
          - php-mysql
        state: present
        update_cache: yes

    - name: Configure PHP
      ini_file:
        path: /etc/php/8.1/apache2/php.ini
        section: PHP
        option: "{{ item.option }}"
        value: "{{ item.value }}"
      loop:
        - { option: memory_limit, value: 256M }
        - { option: upload_max_filesize, value: 16M }
        - { option: post_max_size, value: 16M }
        - { option: max_execution_time, value: 300 }
        - { option: max_input_time, value: 300 }
        - { option: max_input_vars, value: 10000 }
        - { option: date.timezone, value: Etc/UTC }

    - name: Restart Apache
      systemd:
        name: apache2
        state: restarted

    - name: Install MariaDB server
      apt:
        name: mariadb-server
        state: present
        update_cache: yes

    - name: Secure MariaDB installation
      mysql_secure_installation:
        state: present
        mariadb_root_password: root_password #Replace with your desired root password

    - name: Create Zabbix database
      mysql_db:
        name: "{{ zabbix_db_name }}"
        state: present
        login_user: root
        login_password: root_password  #Replace with your MariaDB root password

    - name: Create Zabbix database user
      mysql_user:
        name: "{{ zabbix_db_user }}"
        password: "{{ zabbix_db_password }}"
        priv: "{{ zabbix_db_name }}.*:ALL"
        host: localhost
        state: present
        login_user: root
        login_password: root_password #Replace with your MariaDB root password

    - name: Enable log_bin_trust_function_creators
      mysql_variables:
        name: log_bin_trust_function_creators
        value: "1"
        login_user: root
        login_password: root_password #Replace with your MariaDB root password
        persist: yes

    - name: Install Zabbix repository
      apt:
        deb: "https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu22.04_all.deb"
        state: present

    - name: Install Zabbix server, frontend, and agent
      apt:
        name:
          - zabbix-server-mysql
          - zabbix-frontend-php
          - zabbix-apache-conf
          - zabbix-sql-scripts
          - zabbix-agent
        state: present
        update_cache: yes

    - name: Import Zabbix database schema
      shell: "zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -u{{ zabbix_db_user }} -p{{ zabbix_db_password }} {{ zabbix_db_name }}"

    - name: Disable log_bin_trust_function_creators
      mysql_variables:
        name: log_bin_trust_function_creators
        value: "0"
        login_user: root
        login_password: root_password #Replace with your MariaDB root password
        persist: yes

    - name: Configure Zabbix server
      lineinfile:
        path: /etc/zabbix/zabbix_server.conf
        regexp: '^{{ item.regexp }}'
        line: "{{ item.line }}"
      loop:
        - { regexp: 'DBHost=', line: 'DBHost=localhost' }
        - { regexp: 'DBName=', line: 'DBName={{ zabbix_db_name }}' }
        - { regexp: 'DBUser=', line: 'DBUser={{ zabbix_db_user }}' }
        - { regexp: 'DBPassword=', line: 'DBPassword={{ zabbix_db_password }}' }

    - name: Configure Zabbix agent
      lineinfile:
        path: /etc/zabbix/zabbix_agentd.conf
        regexp: '^{{ item.regexp }}'
        line: "{{ item.line }}"
      loop:
        - { regexp: 'Server=', line: 'Server={{ zabbix_server_ip }}' }
        - { regexp: 'ServerActive=', line: 'ServerActive={{ zabbix_server_ip }}' }
        - { regexp: 'Hostname=', line: 'Hostname=Zabbix Server' }

    - name: Start and enable Zabbix server
      systemd:
        name: zabbix-server
        state: started
        enabled: yes

    - name: Start and enable Zabbix agent
      systemd:
        name: zabbix-agent
        state: started
        enabled: yes

Steps:

  1. Install Ansible:

    sudo apt update
    sudo apt install ansible -y
  2. Create an Ansible inventory file: This file specifies the target servers where Zabbix will be installed. For example, if you are running this on the local machine, add localhost ansible_connection=local to the inventory file.

  3. Run the playbook:

    ansible-playbook -i <inventory_file> zabbix_install.yml

    Replace <inventory_file> with the path to your inventory file.

Important Considerations for Ansible:

  • Idempotency: Ansible playbooks are designed to be idempotent, meaning they can be run multiple times without causing unintended changes.
  • Variables: The playbook uses variables to make it more flexible and reusable. Be sure to update the variables with your specific database credentials and server IP address.
  • Security: Securely manage your database passwords and other sensitive information when using Ansible.
  • Error Handling: Implement proper error handling in your playbook to ensure that the installation process is robust.

These alternative solutions provide flexibility in deploying Zabbix 6.0, depending on your specific environment and preferences. Docker Compose simplifies containerized deployments, while Ansible enables automated and repeatable installations across multiple servers. Choose the method that best fits your needs.

Leave a Reply

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