Monday, October 7, 2024

How to Install Zabbix on Ubuntu 22.04/24.10

Zabbix is a powerful, open-source monitoring solution that provides real-time insights into the health and performance of your IT infrastructure. This guide will walk you through a complete Zabbix installation and configuration process on both CentOS and Ubuntu servers, empowering you to gain comprehensive control over your network, servers, and cloud services.

Prerequisites for a Successful Zabbix Deployment

Before embarking on the installation journey, ensure you have the following essential components in place:

  • Server Environment: A CentOS 7/8 or Ubuntu 20.04/22.04 server ready to host your Zabbix installation. This server should have a dedicated user with sudo privileges for administrative tasks.

  • Memory Capacity: Allocate at least 2 GB of RAM for the Zabbix server to ensure smooth operation and efficient monitoring.

  • Unique Identification: Assign a fully qualified domain name (FQDN) or a static IP address to your Zabbix server for seamless communication.

  • Database Foundation: A pre-installed and configured MySQL or MariaDB database server to store Zabbix data and configurations.

Installation on CentOS: A Step-by-Step Walkthrough

1. Prepare the CentOS Environment:

Begin by updating the system packages and installing Apache, the web server that will host the Zabbix frontend:

      sudo yum update
sudo yum install httpd
    

2. Enable Zabbix Repository for Easy Installation:

Zabbix isn't included in the default CentOS repositories, so we need to add it:

      # For CentOS 7
sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm

# For CentOS 8
sudo rpm -Uvh https://repo.zabbix.com/zabbix/7.0/centos/8/x86_64/zabbix-release-7.0-5.el8.noarch.rpm
    

Update the package list to reflect the new repository:

      sudo yum update
    

3. Install the Essential Zabbix Components:

Now, install the core Zabbix components, including the server, frontend, and agent:

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

4. Set Up MariaDB for Zabbix Data Storage:

Install the MariaDB database server:

      sudo yum install mariadb-server
    

Start and enable the MariaDB service to ensure it's always running:

      sudo systemctl start mariadb
sudo systemctl enable mariadb
    

5. Secure and Configure MariaDB for Zabbix:

Secure your MariaDB installation by setting a strong root password:

      sudo mysql_secure_installation
    

Log in to the MariaDB shell as the root user:

      mysql -u root -p
    

Create a dedicated database and user for Zabbix:

      CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
set global log_bin_trust_function_creators = 1;
FLUSH PRIVILEGES;
EXIT;
    

Import the Zabbix database schema and data:

      zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql - default-character-set=utf8mb4 -uzabbix -p Zabbix
    

Disable the log_bin_trust_function_creators option:

      mysql -u root -p
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
    

6. Fine-Tune the Zabbix Server Configuration:

Edit the Zabbix server configuration file:

      sudo nano /etc/zabbix/zabbix_server.conf
    

Configure the database connection parameters:

      DBName=Zabbix  # Database name
DBUser=Zabbix  # Database user
DBPassword=your_password  # Database password
    

Save the changes to the configuration file.

7. Start and Enable Zabbix Services for Continuous Monitoring:

Start the Zabbix server, agent, and Apache web server:

      sudo systemctl start zabbix-server zabbix-agent httpd
    

Enable these services to start automatically at system boot:

      sudo systemctl enable zabbix-server zabbix-agent httpd
    

8. Configure Firewall Rules for Secure Access (Optional):

If your server has a firewall enabled, allow HTTP traffic for the Zabbix frontend:

      sudo firewall-cmd -permanent - add-service=http
sudo firewall-cmd - reload
    

Allow Zabbix agent traffic:

      sudo firewall-cmd - permanent - add-port=10050/tcp
sudo firewall-cmd - permanent - add-port=10051/tcp
sudo firewall-cmd - reload
    

9. Complete the Zabbix Web Installer Setup:

Access the Zabbix web installer through your web browser:

      http://your_server_ip_or_domain/zabbix
    

Follow the on-screen instructions to complete the setup, including configuring the database connection and reviewing the settings.

10. Log In to Zabbix with Default Credentials:

Use the following credentials to log in to the Zabbix web interface:

      Username: Admin
Password: zabbix
    

Installation on Ubuntu: A Seamless Process

1. Update and Install Apache on Ubuntu:

Start by updating the system packages and installing Apache:

      sudo apt update
sudo apt install apache2
    

2. Add the Zabbix Repository for Easy Access:

Download and add the Zabbix repository:

      # For Ubuntu 20.04
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1%2Bubuntu20.04_all.deb
sudo dpkg -i zabbix-release_6.01+ubuntu20.04_all.deb

# For Ubuntu 22.04
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu22.04_all.deb
dpkg -i zabbix-release_7.0-2+ubuntu22.04_all.deb
    

Update the package list:

      sudo apt update
    

3. Install Zabbix Server, Frontend, and Agent:

Install the core Zabbix components:

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

4. Install MariaDB for Zabbix Data Storage:

Install the MariaDB database server:

      sudo apt install mariadb-server
    

Start the MariaDB service:

      sudo systemctl start mariadb
sudo systemctl enable mariadb
    

5. Secure and Configure MariaDB for Zabbix:

Secure your MariaDB installation:

      sudo mysql_secure_installation
    

Log in to the MariaDB shell as the root user:

      mysql -u root -p
    

Create a database and user for Zabbix:

      CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
set global log_bin_trust_function_creators = 1;
FLUSH PRIVILEGES;
EXIT;
    

Import the Zabbix schema and data:

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

Disable the log_bin_trust_function_creators option:

      mysql -u root -p
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
    

6. Fine-Tune the Zabbix Server Configuration:

Edit the Zabbix server configuration file:

      sudo nano /etc/zabbix/zabbix_server.conf
    

Configure the database connection parameters:

      DBName=zabbix  # Database name
DBUser=zabbix  # Database user
DBPassword=your_password  # Database password
    

Save the changes to the configuration file.

7. Start and Enable Zabbix Services for Continuous Monitoring:

Start the Zabbix server, agent, and Apache web server:

      sudo systemctl start zabbix-server zabbix-agent apache2
    

Enable these services to start automatically at system boot:

      sudo systemctl enable zabbix-server zabbix-agent apache2
    

8. Configure Firewall Rules for Secure Access (Optional):

If your server has a firewall enabled, allow HTTP traffic for the Zabbix frontend:

      sudo ufw allow 80/tcp
    

Allow Zabbix agent traffic:

      sudo ufw allow 10050/tcp
sudo ufw allow 10051/tcp
    

Enable the firewall if it's not already enabled:

      sudo ufw enable
    

9. Complete the Zabbix Web Installer Setup:

Access the Zabbix web installer through your web browser:

      http://your_server_ip_or_domain/zabbix
    

Follow the on-screen instructions to complete the setup, including configuring the database connection and reviewing the settings.

10. Log In to Zabbix with Default Credentials:

Use the following credentials to log in to the Zabbix web interface:

      Username: Admin
Password: zabbix
    

Post-Installation Configuration: Mastering Zabbix

1. Log In to the Zabbix Web Interface:

Access the Zabbix web interface using your web browser:

      http://your_server_ip_or_domain/zabbix
    

2. Change the Default Password for Enhanced Security:

Navigate to: Users > Users

Click on the Admin user and enter a strong, unique password in the Password field. Click Update to save the changes.

3. Adding Hosts: The Heart of Zabbix Monitoring:

Hosts represent the devices you want to monitor in Zabbix, including servers, network devices, and virtual machines. Each host can have numerous items (metrics) for monitoring, such as CPU usage, memory utilization, disk space, and more.

3.1 Add a New Host:

  • Navigate to: Monitoring > Hosts

  • Click on Create host.

  • Enter Host Details:

    • Host name: A unique name for the host (e.g., WebServer01).

    • Visible name: (Optional) A user-friendly name to display in the Zabbix UI.

    • Groups: Select or create a group to categorize your hosts (e.g., Linux Servers).

    • Interfaces: Add an interface (e.g., Agent, SNMP) with the IP address or DNS name of the host.

  • Assign Templates for Automated Monitoring:

    • In the Templates tab, click on Select.

    • Choose a template matching the host type (e.g., Template OS Linux for a Linux server).

    • Click Add to assign the template to the host.

  • Click Add to save the host configuration.

3.2 Verify Host Monitoring:

  • Navigate to: Monitoring > Latest data

  • Select the host from the list and review the collected metrics to confirm successful monitoring.

4. User Groups and Permissions: Controlling Access:

Zabbix allows you to create user groups with specific permissions, ensuring that users have access only to the data and features they need.

4.1 Create a New User Group:

  • Navigate to: Administration > User groups

  • Click on Create user group.

  • Enter Group Details:

    • Name: A descriptive name for the group (e.g., IT Support).

    • Permissions: Set the permission level for each host group (e.g., read-only or read-write).

  • Click Add to save the user group.

4.2 Create and Assign Users to Groups:

  • Navigate to: Users

  • Click on Create user.

  • Enter User Details:

    • Alias: The username for login.

    • Groups: Select the user group created earlier (e.g., IT Support).

    • Password: Set a password for the user.

  • Set User Permissions:

    • In the Permissions tab, specify which host groups the user can access and their level of access.

  • Click Add to create the user.

5. Notifications and Alerts: Staying Informed:

Zabbix can send notifications via email, SMS, or other methods when certain conditions are met, such as a server going down or experiencing high CPU usage.

5.1 Set Up Email Notifications:

  • Navigate to: Alerts > Media types

  • Click on Email to configure email settings.

  • Enter SMTP Settings:

    • Email Provider: Select your email provider (e.g., Gmail, Outlook).

    • SMTP email: The sender's email address (e.g., zabbix@example.com).

  • Click Update to save the settings.

5.2 Create an Action for Notifications:

  • Navigate to: Alerts > Actions

  • Click on Create action.

  • Enter Action Details:

    • Name: A descriptive name for the action (e.g., High CPU Usage Alert).

    • Conditions: Define conditions that trigger the action (e.g., Trigger severity = High).

  • Add an Operation:

    • In the Operations tab, click on Add.

    • Choose Send message as the operation type.

    • Select the user group and the media type (e.g., email).

  • Click Add to save the action.

6. Customize Dashboards: Visualizing Your Infrastructure:

Dashboards in Zabbix provide a visual overview of your monitored environment, displaying key metrics, graphs, and status indicators.

6.1 Create a Custom Dashboard:

  • Navigate to: Dashboards

  • Click on Create dashboard.

  • Enter Dashboard Details:

    • Name: A descriptive name for the dashboard (e.g., Network Overview).

  • Add Widgets:

    • Click on Add widget to add various widgets, such as graphs, maps, or problems.

    • Configure each widget according to your needs.

  • Click Save changes to save the dashboard.

6.2 Customize Widgets:

  • After adding widgets, you can rearrange the dashboard layout by dragging and dropping them.

  • Customize each widget by clicking on the widget’s settings icon and adjusting the parameters (e.g., time period, display options).

7. Set Up Housekeeping and Data Retention: Managing Disk Space:

To manage disk space and maintain performance, configure Zabbix’s housekeeping settings, which control the retention period for historical data and trends.

  • Navigate to: Administration > Housekeeping

  • Configure History and Trend Retention:

    • Set how long historical data (e.g., raw data) is kept (e.g., 90 days).

    • Set how long trends (e.g., daily averages) are kept (e.g., 365 days).

  • Click Update to save the housekeeping settings.

8. Backup and Restore Zabbix Configuration: Ensuring Data Safety:

Regular backups of your Zabbix configuration are essential to prevent data loss.

8.1 Backup Zabbix Database:

  • Create a backup of the Zabbix database:

          mysqldump -u zabbix -p zabbix > /backup/zabbix_backup.sql
        
  • Automate Backups:

    • Schedule the backup script using cron to automate the backup process.

8.2 Restore Zabbix Database:

  • Restore the Zabbix database from a backup:

          mysql -u zabbix -p zabbix < /backup/zabbix_backup.sql
        

Conclusion: Unleash the Power of Zabbix

By following this comprehensive installation and configuration guide, you've equipped yourself with a powerful Zabbix infrastructure capable of providing real-time insights into the health and performance of your IT environment. With Zabbix, you can proactively address potential issues, improve system stability, and gain a clear understanding of your infrastructure's overall well-being.

0 comments:

Post a Comment