This guide shows how to set up Icinga 2 with a MariaDB backend on Ubuntu. It covers preparing MariaDB, resetting a lost root password on a system install or a XAMPP install, writing a working client configuration, and installing Icinga 2, Icinga DB and Icinga Web 2. It fills in the headings above that have no content and fixes the problems in the .my.cnf example.
Xampp installation
MySql Root Password Reset
Ensure Correct Client Configuration
Make sure that your MySQL client is configured to connect to the MariaDB server. This involves specifying the host, port, user, and password that the MariaDB server uses. These configurations can be set in the MySQL client configuration file (typically .my.cnf in your home directory) as follows:
[client]
host = 127.0.0.1
user = root
password = your_password
port = 3306 # default MariaDB/MySQL port
Code language: PHP (php)
What the Icinga stack needs and where XAMPP fits
A current Icinga installation has several parts. Icinga 2 runs the checks. Icinga DB moves the monitoring state into a SQL database. Icinga Web 2 is the PHP web interface. MariaDB holds both the Icinga DB data and the Icinga Web 2 configuration database.
| Component | Package (Ubuntu) | Role |
|---|---|---|
| Icinga 2 | icinga2, monitoring-plugins | Monitoring daemon that runs checks and the REST API |
| Icinga DB Redis | icingadb-redis | Fast state cache, listens on port 6380 |
| Icinga DB | icingadb | Writes state from Redis into MariaDB or MySQL |
| Icinga Web 2 | icingaweb2, icingadb-web, icingacli | Web UI served by Apache and PHP |
| MariaDB | mariadb-server | Databases icingadb and icingaweb2 |
Note: XAMPP is a bundle for local development. It ships its own Apache, PHP and MariaDB under /opt/lampp. The Icinga packages expect the distribution's Apache, PHP and MariaDB, so running XAMPP next to them causes port clashes on 80 and 3306. On an Icinga server, use the distribution packages and keep XAMPP to desktops or labs.
Install and prepare MariaDB
sudo apt update
sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable --now mariadb
sudo mariadb-secure-installation
On Ubuntu, root@localhost logs in with the unix_socket plugin by default. This means sudo mariadb gets you in with no password. Many "forgotten root password" cases are solved simply by running sudo mariadb. Use it to create separate databases and users for Icinga, and never connect Icinga as root:
sudo mariadb <<'SQL'
CREATE DATABASE icingadb;
CREATE USER 'icingadb'@'localhost' IDENTIFIED BY 'ChangeMe_DB1';
GRANT ALL ON icingadb.* TO 'icingadb'@'localhost';
CREATE DATABASE icingaweb2;
CREATE USER 'icingaweb2'@'localhost' IDENTIFIED BY 'ChangeMe_Web1';
GRANT ALL ON icingaweb2.* TO 'icingaweb2'@'localhost';
FLUSH PRIVILEGES;
SQLCode language: JavaScript (javascript)
Reset the MariaDB root password
Use this only when sudo mariadb does not work, for example because root was switched to password-only login and the password is lost. The server restarts with no permission checks and no network access, so nobody else can connect while it is open.
- Stop the service:
sudo systemctl stop mariadb - Create the socket directory if it is missing:
sudo mkdir -p /run/mysqld && sudo chown mysql:mysql /run/mysqld - Start without grant tables:
sudo mysqld_safe --skip-grant-tables --skip-networking & - Connect with
mariadb -u root, then run the SQL below. - Stop the temporary server with
sudo mysqladmin shutdown, then runsudo systemctl start mariadb.
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost'
IDENTIFIED VIA mysql_native_password USING PASSWORD('NewStrongPassword')
OR unix_socket;Code language: JavaScript (javascript)
The first FLUSH PRIVILEGES loads the grant tables again so that ALTER USER is allowed. The OR unix_socket clause keeps sudo mariadb working as well as the new password.
XAMPP on Linux: the root account has no password after a fresh install. Run sudo /opt/lampp/lampp security to set passwords for MariaDB, phpMyAdmin and the XAMPP pages. To reset a lost password, stop the database with sudo /opt/lampp/lampp stopmysql and add skip-grant-tables under [mysqld] in /opt/lampp/etc/my.cnf. Then start it with startmysql, connect with /opt/lampp/bin/mysql -u root, run the same SQL with only the mysql_native_password part, remove the option and restart.
Corrected client configuration
The .my.cnf example above has two problems. host = 127.0.0.1 forces a TCP connection, while the Ubuntu default for root is socket authentication. As a result the file fails with ERROR 1698 or ERROR 1045 even when the password is right. The file also puts the root password in plain text with no protection. The version below uses a dedicated account and locks down the file permissions:
# ~/.my.cnf (read by the mysql and mariadb clients)
[client]
user = icingadb
password = ChangeMe_DB1
# 'localhost' uses the Unix socket; use 127.0.0.1 only when you need TCP
host = localhost
socket = /run/mysqld/mysqld.sock
# For XAMPP use: socket = /opt/lampp/var/mysql/mysql.sockCode language: PHP (php)
chmod 600 ~/.my.cnf
mariadb -e "SELECT CURRENT_USER();"Code language: PHP (php)
Expected output is a single row showing icingadb@localhost. The client ignores the file if it is world-writable, so chmod 600 is required, not just good practice.
Install Icinga 2 and Icinga DB
Add the official Icinga repository. The Ubuntu archive packages are older and do not include Icinga DB. For the full walkthrough, see How to Install Icinga 2 on Ubuntu.
sudo apt install -y wget gnupg apt-transport-https
wget -qO - https://packages.icinga.com/icinga.key \
| sudo gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg
. /etc/os-release
echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/ubuntu icinga-${VERSION_CODENAME} main" \
| sudo tee /etc/apt/sources.list.d/icinga.list
sudo apt update
sudo apt install -y icinga2 monitoring-plugins icingadb-redis icingadb
sudo systemctl enable --now icinga2 icingadb-redis
sudo icinga2 feature enable icingadb
# Import the Icinga DB schema
sudo mariadb icingadb < /usr/share/icingadb/schema/mysql/schema.sqlCode language: PHP (php)
Edit the database block in /etc/icingadb/config.yml so it matches the user created earlier, then start the services:
database:
type: mysql
host: localhost
port: 3306
database: icingadb
user: icingadb
password: ChangeMe_DB1
redis:
host: localhost
port: 6380
sudo systemctl enable --now icingadb
sudo icinga2 api setup
sudo systemctl restart icinga2
Install Icinga Web 2 and run the setup wizard
Icinga Web 2 sends commands, such as rescheduling a check, through the Icinga 2 API. Create an API user for it in /etc/icinga2/conf.d/api-users.conf. The enable the Icinga API guide explains this in more detail.
object ApiUser "icingaweb2" {
password = "ChangeMe_Api1"
permissions = [ "actions/*", "objects/modify/*", "objects/query/*", "status/query" ]
}Code language: JavaScript (javascript)
sudo icinga2 daemon -C && sudo systemctl restart icinga2
sudo apt install -y icingaweb2 icingadb-web icingacli libapache2-mod-php php-mysql
sudo icingacli setup token create
- Open
http://<server-ip>/icingaweb2/setupand paste the token. - Enable the Icinga DB module.
- Configuration database: type MySQL, host
localhost, databaseicingaweb2, usericingaweb2. - Create the first admin user for the web UI.
- Icinga DB resource: database
icingadb, usericingadb. Redis:localhost, port6380. - Command transport: API on
localhost:5665with theicingaweb2API user, then finish and log in.
Verify the installation
sudo systemctl is-active icinga2 icingadb icingadb-redis mariadb apache2
sudo icinga2 daemon -C | tail -n 3
sudo mariadb icingadb -e "SELECT name FROM host LIMIT 5;"Code language: JavaScript (javascript)
All five services should print active. The configuration check should end with Finished validating the configuration file(s). The query should list your local host. If the host table is empty, Icinga DB is not receiving data, so check journalctl -u icingadb.
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
ERROR 1698 (28000): Access denied for user 'root'@'localhost' | root uses unix_socket authentication | Use sudo mariadb, or add password login as shown in the reset section |
ERROR 1045 ... (using password: YES) | Wrong password, or the user exists for localhost but you connected via 127.0.0.1 | Check the .my.cnf values and use host = localhost |
ERROR 2002 Can't connect ... through socket | Server not running, or the client points at the wrong socket (XAMPP vs system) | Start the right server and set socket in .my.cnf |
| MariaDB fails to start: port 3306 in use | XAMPP MariaDB and system MariaDB running together | Stop one: sudo /opt/lampp/lampp stop |
Web UI: Failed to send external Icinga command | API user missing or wrong permissions | Check api-users.conf, restart Icinga 2, then fix the command transport |
Frequently asked questions
Can I run Icinga with XAMPP's MariaDB?
It can work if you point Icinga DB at XAMPP's socket or port, but it is not recommended. Icinga packages are built for the distribution's MariaDB, Apache and PHP, and XAMPP is meant for local development.
Should I still use the IDO MySQL feature?
No, not for new installations. Icinga DB replaces the IDO database backend, which is deprecated, and Icinga Web 2 uses it through the Icinga DB Web module.
What is the default URL for Icinga Web 2?
With the Apache configuration from the package, the UI is at http://<server>/icingaweb2/, and the first-run wizard is at /icingaweb2/setup.
I lost the Icinga Web 2 setup token. How do I get it back?
Run sudo icingacli setup token show to print it again, or sudo icingacli setup token create to make a new one.
Which databases does Icinga DB support?
Icinga DB supports MySQL, MariaDB and PostgreSQL. The schema files are under /usr/share/icingadb/schema/.
Related tutorials
- Icinga: How to Install Icinga 2 on Ubuntu
- icinga2: How to enable Api in icinga?
- icinga: Step by Step installing Icinga Director in ubuntu
- icinga tutorials: How to monitor Mysql server using icinga agent
- More Icinga tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals