- Published on
How to install zabbix server on Ubuntu
- Authors
- Name
- Marcio Moreira Junior
Are you looking to enhance your IT monitoring capabilities? Installing Zabbix Server on Ubuntu can be a game changer. In this guide, we will walk through the installation process step-by-step, ensuring that you are well-equipped to monitor your systems efficiently.
Prerequisites
Before you begin the installation, ensure you have the following prerequisites in place:
- A clean installation of Ubuntu (20.04 LTS or newer recommended).
- Root or sudo access.
- Basic familiarity with the Linux command line.
- A basic understanding of MySQL or PostgreSQL.
Step 1: Update Your System
Start by updating your operating system to ensure all packages are up to date. Open your terminal and run:
sudo apt update && sudo apt upgrade -y
Expected Output:
... (a list of packages that are being updated)
This command fetches the latest package lists and upgrades outdated packages, which is a good practice before installing new software.
Step 2: Install Required Packages
Zabbix requires a few packages, including a web server, database server, and PHP. For this guide, we will install Apache, MySQL, and PHP. Run the following command:
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-gd php-xml php-mbstring php-bcmath php-json -y
Expected Output:
... (a list of packages that are being installed)
After installing these packages, you will need to start and enable the Apache and MySQL services:
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql
Expected output (for each service):
... (there won't be explicit output, but the command prompt will return)
Step 3: Create Zabbix Database
Next, you need to create a database and user for Zabbix in MySQL. Log into the MySQL prompt:
sudo mysql -u root -p
Expected Output:
Enter password for user root:
Once logged in, run the following commands to create a database named zabbix
and a user zabbix_user
:
CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'zabbix_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace 'your_password'
with a strong password of your choice. The output confirms the successful execution of these commands.
Step 4: Install Zabbix Server
To install Zabbix, first, you need to add the Zabbix repository. Use the following commands:
wget https://cdn.zabbix.com/zabbix/6.0/zabbix-official-repo-6.0-ubuntu22.04_all.deb
sudo dpkg -i zabbix-official-repo-6.0-ubuntu22.04_all.deb
sudo apt update
Expected Output after each command:
... (a series of confirmations showing repository setup and package list updates)
Now, install the Zabbix server, frontend, and agent:
sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent -y
Expected Output:
... (package installation confirmations)
Step 5: Configure Zabbix Server
Now it’s time to configure Zabbix Server. Open the Zabbix server configuration file:
sudo nano /etc/zabbix/zabbix_server.conf
Find and edit the database section:
DBName=zabbix
DBUser=zabbix_user
DBPassword=your_password
Make sure to replace your_password
with the password you defined.
Step 6: Initialize the Database Schema
Next, import the initial schema and data to the zabbix
database using the following command:
sudo zcat /usr/share/doc/zabbix-server-mysql*/create/schema.sql.gz | mysql -uzabbix_user -p zabbix
Expected Output:
... (no output is displayed, returns to command prompt)
Step 7: Configure Apache
Next, configure the Apache web server. You need to create a virtual host configuration for Zabbix:
sudo nano /etc/apache2/sites-available/zabbix.conf
Add the following content:
<VirtualHost *:80>
ServerName your_domain_or_IP
DocumentRoot /usr/share/zabbix
<Directory /usr/share/zabbix>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/zabbix_error.log
CustomLog ${APACHE_LOG_DIR}/zabbix_access.log combined
</VirtualHost>
Set your domain or IP accordingly. Save and exit, then enable the new site and restart Apache:
sudo a2ensite zabbix
sudo systemctl reload apache2
Step 8: Start Zabbix Server and Agent
Now that everything is set up, start the Zabbix Server and Agent and enable them to run at boot:
sudo systemctl start zabbix-server zabbix-agent
sudo systemctl enable zabbix-server zabbix-agent
Troubleshooting Common Issues
- Zabbix Web Interface Doesn't Load: Ensure Apache and Zabbix Server are running. Check error logs for hints:
sudo tail -f /var/log/apache2/zabbix_error.log
sudo tail -f /var/log/zabbix/zabbix_server.log
- Error Connecting to the Database: Verify your MySQL credentials and that MySQL is running:
sudo systemctl status mysql
- Firewall Blocks Access: If you cannot access the Zabbix web interface, check your firewall settings and allow HTTP traffic:
sudo ufw allow 80/tcp
Conclusion
Installing Zabbix Server on Ubuntu is a straightforward task that can greatly enhance your system monitoring capabilities. With this guide, you've learned not just the installation steps but also how to troubleshoot common issues. As you become familiar with Zabbix, you can explore its powerful features to create an efficient monitoring solution tailored to your needs.