Install Zabbix on Rocky Linux 9: Comprehensive Guide

Posted on

Install Zabbix on Rocky Linux 9: Comprehensive Guide

Install Zabbix on Rocky Linux 9: Comprehensive Guide

This comprehensive guide, brought to you by Orcacore, will walk you through the process of installing Install Zabbix on Rocky Linux 9. Zabbix is a powerful open-source monitoring solution designed to oversee a wide range of IT infrastructure components, including servers, networks, cloud services, virtual machines, and other IT elements.

Zabbix excels at providing detailed monitoring metrics, allowing you to track critical performance indicators such as network bandwidth utilization, disk space consumption, and CPU load. Its versatility extends to supporting various operating systems like Mac OS, Solaris, and Linux, making it a valuable tool in diverse IT environments. Zabbix relies on a dedicated database for storing collected data and uses C for its core functionality with PHP powering the web front-end. Let’s begin to Install Zabbix on Rocky Linux 9.

Before you proceed, ensure that you have the following prerequisites in place:

Once you have met these prerequisites, you are ready to begin the installation process of Install Zabbix on Rocky Linux 9.

1. Download Zabbix LTS on Rocky Linux 9

Begin by identifying the latest LTS (Long Term Support) version of Zabbix on the Zabbix Downloads Page.

Next, add the Zabbix repository to your Rocky Linux 9 system using the following commands:

# sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-6.0-4.el9.noarch.rpm
# sudo dnf clean all

2. Install Zabbix LTS on Rocky Linux 9

Now, install the Zabbix monitoring components on your server with this command:

sudo dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent -y

After the installation is complete, you need to create a Zabbix database and user.

3. Create a Zabbix Database and User

Access the MariaDB console with the following command:

sudo mysql -u root -p

From within the MariaDB console, create a dedicated user for Zabbix. Replace zabbixuser with your preferred username and password with a strong, secure password:

MariaDB [(none)]> CREATE USER zabbixuser@localhost IDENTIFIED BY 'password';

Create the database that Zabbix will use to store its data:

MariaDB [(none)]> CREATE DATABASE zabbixdb character set utf8mb4 collate utf8mb4_bin;

Grant the newly created user full privileges over the Zabbix database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON zabbixdb.* TO zabbixuser@localhost;

Finally, flush the privilege tables to apply the changes and exit the MariaDB console:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Import Database Schema

Import the Zabbix database schema using the following command. You will be prompted for the Zabbix user’s password.

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

Change Database Settings on Zabbix Configuration File

Edit the Zabbix server configuration file to reflect your database settings:

sudo vi /etc/zabbix/zabbix_server.conf

Locate the following lines and modify them to match your database configuration:

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

Ensure that the DBHost and DBPassword lines are uncommented by removing the # character at the beginning of each line. Save and close the file.

4. Configure PHP-FPM on Rocky Linux 9

Specify the correct timezone within the PHP-FPM configuration file for Zabbix:

sudo vi /etc/php-fpm.d/zabbix.conf

Uncomment the php_value[date.timezone] line and set it to your desired timezone. For example:

php_value[date.timezone] = America/New_York

Save and close the file.

Restart the necessary services to apply the changes:

sudo systemctl restart zabbix-server zabbix-agent httpd php-fpm

Enable the services to start automatically at boot time:

sudo systemctl enable zabbix-server zabbix-agent php-fpm

5. Configure SELinux and Firewall on Rocky Linux 9

Configure SELinux to allow access to the Zabbix frontend:

# sudo setenforce 0
# sudo sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config

Allow traffic on ports 10050 and 10051 through the firewall:

# sudo firewall-cmd --add-service=http --permanent
# sudo firewall-cmd --add-port={10051,10050}/tcp --permanent

Reload the firewall to apply the changes:

sudo firewall-cmd --reload

6. Access the Zabbix Monitoring Dashboard

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

http://server-ip/zabbix

You will be guided through the Zabbix web-based setup wizard. Follow the on-screen instructions, providing the necessary database credentials and configuration details. The default username is Admin and the default password is zabbix.

Zabbix Welcome screen

check for the Zabbix prerequisites

Zabbix database details Rocky Linux 9

Zabbix theme and server name

check the Zabbix pre-installation summary – Install Zabbix on Rocky Linux 9

Install Zabbix Rocky Linux

Zabbix Log in screen

Zabbix dashboard

Conclusion

You have successfully learned how to Install Zabbix on Rocky Linux 9 and accessed the dashboard through the web interface. You can now configure Zabbix to monitor your infrastructure.

Here are some additional articles you may find helpful:

Alternative Solutions for Installing Zabbix on Rocky Linux 9

While the above guide provides a standard method for installing Zabbix, alternative approaches exist that may be more suitable depending on your specific needs and environment. Here are two such alternatives:

1. Using Docker Compose

Docker Compose allows you to define and manage multi-container Docker applications. This is a great method to Install Zabbix on Rocky Linux 9. You can deploy Zabbix and its database (MySQL or PostgreSQL) as separate containers, simplifying the installation and management process.

Explanation:

This approach isolates Zabbix and its dependencies within containers, reducing conflicts with other system software and making upgrades easier. It also provides a consistent environment regardless of the underlying host operating system.

Steps:

  1. Install Docker and Docker Compose: If you haven’t already, install Docker and Docker Compose on your Rocky Linux 9 server.

    sudo dnf install docker -y
    sudo systemctl start docker
    sudo systemctl enable docker
    
    sudo dnf install docker-compose -y
  2. Create a docker-compose.yml file: Create a docker-compose.yml file in a directory of your choice.

    version: "3.8"
    
    services:
      db:
        image: mysql:8.0 # Or postgres:14
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: root_password
          MYSQL_USER: zabbixuser
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: zabbixdb
        volumes:
          - db_data:/var/lib/mysql # Or /var/lib/postgresql/data for postgres
    
      zabbix-server:
        image: zabbix/zabbix-server-mysql:latest # Or zabbix/zabbix-server-pgsql:latest
        ports:
          - "10051:10051"
        volumes:
          - zabbix_server_conf:/etc/zabbix/zabbix_server.conf.d
          - zabbix_server_data:/var/lib/zabbix
        environment:
          DB_SERVER_HOST: db
          DB_SERVER_PORT: 3306 # Or 5432 for postgres
          MYSQL_USER: zabbixuser
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: zabbixdb
          ZBX_SERVERNAME: ZabbixServer
        depends_on:
          - db
        restart: always
    
      zabbix-web-apache:
        image: zabbix/zabbix-web-apache-mysql:latest # Or zabbix/zabbix-web-apache-pgsql:latest
        ports:
          - "80:80"
          - "443:443"
        environment:
          PHP_TZ: America/New_York # Set your timezone
          ZBX_SERVER_HOST: zabbix-server
          MYSQL_USER: zabbixuser
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: zabbixdb
        depends_on:
          - zabbix-server
        restart: always
    
      zabbix-agent:
        image: zabbix/zabbix-agent:latest
        ports:
          - "10050:10050"
        privileged: true
        pid: "host"
        restart: always
        environment:
          ZBX_SERVER_HOST: zabbix-server
    
    volumes:
      db_data:
      zabbix_server_conf:
      zabbix_server_data:
  3. Run Docker Compose: Start the Zabbix stack using Docker Compose.

    docker-compose up -d
  4. Access Zabbix Web Interface: Open your web browser and navigate to http://server-ip. The Zabbix web interface should be accessible.

This method greatly simplifies the installation of Install Zabbix on Rocky Linux 9.

2. Using Ansible Automation

Ansible is an open-source automation tool that can be used to automate the installation and configuration of Zabbix. This is beneficial for deploying Zabbix across multiple servers consistently and efficiently.

Explanation:

Ansible uses playbooks written in YAML to define the desired state of the system. By creating an Ansible playbook, you can automate the entire installation process, from installing dependencies to configuring the Zabbix server and agent.

Steps:

  1. Install Ansible: If you don’t have Ansible installed, install it using pip:

    sudo dnf install python3-pip
    pip3 install ansible
  2. Create an Ansible Playbook: Create a YAML file (e.g., zabbix_install.yml) with the following content (adjust variables as needed):

    ---
    - hosts: all
      become: true
      vars:
        zabbix_repo_url: "https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-6.0-4.el9.noarch.rpm"
        db_name: "zabbixdb"
        db_user: "zabbixuser"
        db_password: "password"
        db_root_password: "root_password" #Only needed for initial database setup
        timezone: "America/New_York"
    
      tasks:
        - name: Download Zabbix repo
          get_url:
            url: "{{ zabbix_repo_url }}"
            dest: /tmp/zabbix-release.rpm
    
        - name: Install Zabbix repo
          dnf:
            name: /tmp/zabbix-release.rpm
            state: present
    
        - name: Install Zabbix server, web interface, agent
          dnf:
            name:
              - zabbix-server-mysql
              - zabbix-web-mysql
              - zabbix-apache-conf
              - zabbix-sql-scripts
              - zabbix-selinux-policy
              - zabbix-agent
            state: present
    
        - name: Start mariadb and enable at boot.
          systemd:
            name: mariadb
            enabled: yes
            state: started
    
        - name: Create Zabbix database
          mysql_db:
            name: "{{ db_name }}"
            state: present
            login_user: root
            login_password: "{{ db_root_password }}"
            encoding: utf8mb4
    
        - name: Create Zabbix user
          mysql_user:
            name: "{{ db_user }}"
            password: "{{ db_password }}"
            priv: "{{ db_name }}.*:ALL"
            host: localhost
            state: present
            login_user: root
            login_password: "{{ db_root_password }}"
    
        - name: Import Zabbix database schema
          shell: zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -u {{ db_user }} -p{{ db_password }} {{ db_name }}
          args:
            executable: /bin/bash
          become: true
    
        - name: Update Zabbix server config
          replace:
            path: /etc/zabbix/zabbix_server.conf
            regexp: 'DBPassword='
            replace: 'DBPassword={{ db_password }}'
    
        - name: Update Zabbix server config - DBUser
          replace:
            path: /etc/zabbix/zabbix_server.conf
            regexp: 'DBUser=.*'
            replace: 'DBUser={{ db_user }}'
    
        - name: Update Zabbix server config - DBName
          replace:
            path: /etc/zabbix/zabbix_server.conf
            regexp: 'DBName=.*'
            replace: 'DBName={{db_name}}'
    
        - name: Configure PHP timezone
          replace:
            path: /etc/php-fpm.d/zabbix.conf
            regexp: ';php_value[date.timezone] ='
            replace: 'php_value[date.timezone] = {{ timezone }}'
    
        - name: Restart Zabbix server, agent, httpd, php-fpm
          systemd:
            name: "{{ item }}"
            state: restarted
            enabled: yes
          loop:
            - zabbix-server
            - zabbix-agent
            - httpd
            - php-fpm
    
        - name: Configure SELinux (permissive)
          selinux:
            policy: targeted
            state: permissive
    
        - name: Allow HTTP service
          firewalld:
            service: http
            permanent: true
            state: enabled
            immediate: true
    
        - name: Allow Zabbix ports
          firewalld:
            port: "{{ item }}"
            permanent: true
            state: enabled
            immediate: true
          loop:
            - 10050/tcp
            - 10051/tcp
  3. Run the Playbook: Execute the Ansible playbook against your target Rocky Linux 9 server. Ensure you have properly configured your Ansible inventory file.

    ansible-playbook zabbix_install.yml

These alternative methods provide different ways to Install Zabbix on Rocky Linux 9. Choose the method that best suits your environment and requirements.

Leave a Reply

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