如何在 Debian 12 上安装 Icinga 2 监控软件
Icinga 2 是一个开源监控系统,用于检查网络资源的可用性、通知用户中断并生成性能数据以进行报告。您可以使用 Icinga2 监控网络服务(SMTP、POP3、HTTP、NNTP、ping)、主机资源(CPU 使用情况、磁盘使用情况)和网络组件(交换机、路由器、温度和湿度传感器)。它可以与 Nagios 插件集成。
在以下教程中,您将学习如何在 Debian 12 服务器上安装 Icinga2 并将其连接到客户端节点。我们将使用 Nginx 来运行 Icinga2 Web,而不是默认的 Apache 服务器。
先决条件
两台运行 Debian 12 的机器。其中一台作为主服务器,另一台作为监控客户端。
在两台服务器上都具有 sudo 权限的非 root 用户。
主服务器 icinga.example.com
和客户端节点 client.example.com
的完全限定域名 (FQDN)。
确保一切都已更新。
$ sudo apt update && sudo apt upgrade
您的系统需要的软件包很少。
$ sudo apt install wget curl nano software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release debian-archive-keyring ufw unzip -y
其中一些软件包可能已经安装在您的系统上。
步骤 1 - 在主服务器上配置防火墙
第一步是配置防火墙。 Debian 默认带有 ufw(简单防火墙)。
检查防火墙是否正在运行。
$ sudo ufw status
您应该得到以下输出。
Status: inactive
允许 SSH 端口,以便防火墙在启用它时不会中断当前连接。
$ sudo ufw allow OpenSSH
允许 Icinga2 客户端连接到服务器所需的端口 5665。
$ sudo ufw allow 5665
还允许 HTTP 和 HTTPS 端口。
$ sudo ufw allow http
$ sudo ufw allow https
启用防火墙
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
再次检查防火墙的状态。
$ sudo ufw status
您应该看到类似的输出。
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443 ALLOW Anywhere
5665 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
5665 (v6) ALLOW Anywhere (v6)
第 2 步 - 安装 MariaDB 服务器
Debian 12 附带最新版本的 MariaDB。您可以使用单个命令安装它。
$ sudo apt install mariadb-server
检查MySQL的版本。
$ mysql --version
mysql Ver 15.1 Distrib 10.11.4-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
运行 MariaDB 安全安装脚本。
$ sudo mariadb-secure-installation
系统会要求您输入 root 密码。按Enter键,因为我们还没有为其设置任何密码。
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
接下来,系统会询问您是否要切换到 Unix 套接字身份验证方法。 unix_socket
插件允许您使用操作系统凭据连接到 MariaDB 服务器。由于您已经拥有受保护的 root 帐户,因此输入 n
继续。
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
接下来,系统会询问您是否要更改 root 密码。在 Debian 12 上,root 密码与自动化系统维护密切相关,因此应该保留它。输入 n
继续。
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] n
接下来,系统将询问您某些问题以提高 MariaDB 的安全性。键入Y 以删除匿名用户、禁止远程 root 登录、删除测试数据库并重新加载权限表。
... skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
您可以通过在命令行上输入 sudo mysql
或 sudo mariadb
进入 MariaDB shell。
第 3 步 - 配置 MariaDB
登录 MariaDB shell。出现提示时输入您的 root 密码。
$ sudo mysql
创建 Icinga 数据库。
MariaDB [(none)]> CREATE DATABASE icinga2;
为 Icinga2 创建 SQL 用户帐户。不要更改数据库和用户名,因为它们已默认设置。如果您想更改它们,则需要在步骤 5 中安装 MySQL 驱动程序时执行一些额外的步骤。输入密码,您将收到错误消息,然后系统会要求您重新配置可以指定自定义数据库名称和用户的位置。
MariaDB [(none)]> CREATE USER 'icinga2'@'localhost' IDENTIFIED BY 'Your_password2';
向用户授予数据库的所有权限。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON icinga2.* TO 'icinga2'@'localhost';
由于我们不修改 root 用户,因此您应该创建另一个 SQL 用户来执行使用密码身份验证的管理任务。为此选择一个强密码。
MariaDB> GRANT ALL ON *.* TO 'navjot'@'localhost' IDENTIFIED BY 'Yourpassword32!' WITH GRANT OPTION;
刷新用户权限。
MariaDB [(none)]> FLUSH PRIVILEGES;
退出外壳。
MariaDB [(none)]> exit
第 4 步 - 在主服务器上安装 Icinga2 和监控插件
我们将使用 Icinga2 官方存储库进行安装。下载并导入 Icinga2 GPG 密钥。
$ wget -O - https://packages.icinga.com/icinga.key | sudo gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg
运行以下命令创建 Icinga2 存储库信息并将其添加到 APT 源列表。
$ echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/debian icinga-`lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/$(lsb_release -cs)-icinga.list
$ echo "deb-src [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] http://packages.icinga.com/debian icinga-`lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list.d/$(lsb_release -cs)-icinga.list
更新系统存储库列表。
$ sudo apt update
安装 Icinga2、Icingacli 和监控插件。
$ sudo apt install icinga2 monitoring-plugins -y
第 5 步 - 在主服务器上安装 IDO MySQL 驱动程序
为了让 Icinga2 工作,它需要一个数据库。为此,我们需要安装 IDO MySQL 驱动程序并设置数据库连接。运行以下命令安装MySQL驱动。
$ sudo apt install -y icinga2-ido-mysql
接下来,系统会要求您启用 ido-mysql 功能。选择是继续。
接下来,系统将提示您设置驱动程序并使用 dbconfig-common 实用程序创建数据库。选择是继续。
接下来,系统将要求您输入 icinga2 数据库的 MySQL 密码。输入步骤 3 中配置的密码以继续。
系统将要求您再次确认密码。
您可以在 /etc/icinga2/features-available/ido-mysql.conf
文件中查看数据库详细信息。
$ sudo cat /etc/icinga2/features-available/ido-mysql.conf
/**
* The db_ido_mysql library implements IDO functionality
* for MySQL.
*/
library "db_ido_mysql"
object IdoMysqlConnection "ido-mysql" {
user = "icinga2",
password = "Your_password2",
host = "localhost",
database = "icinga2"
}
启用 ido-mysql 功能。
$ sudo icinga2 feature enable ido-mysql
Enabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect.
重新启动 Icinga2 服务。
$ sudo systemctl restart icinga2
验证服务状态。
$ sudo systemctl status icinga2
? icinga2.service - Icinga host/service/network monitoring system
Loaded: loaded (/lib/systemd/system/icinga2.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/icinga2.service.d
??limits.conf
Active: active (running) since Mon 2024-01-08 07:35:29 UTC; 4s ago
Process: 15404 ExecStartPre=/usr/lib/icinga2/prepare-dirs /etc/default/icinga2 (code=exited, status=0/SUCCESS)
Main PID: 15411 (icinga2)
Status: "Startup finished."
Tasks: 14
Memory: 13.6M
CPU: 858ms
CGroup: /system.slice/icinga2.service
??15411 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
??15433 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
??15438 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
第 6 步 - 配置 Icinga2 API
要通过 HTTP 管理和配置 Icinga2 监控,您需要配置 Icinga2 API。运行以下命令以启用 Icinga2 API、为 Icinga2 生成 TLS 证书并更新 Icinga2 配置。
$ sudo icinga2 api setup
您将得到类似的输出。
information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca//ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca//ca.crt'.
information/cli: Generating new CSR in '/var/lib/icinga2/certs//icinga.example.com.csr'.
information/base: Writing private key to '/var/lib/icinga2/certs//icinga.example.com.key'.
information/base: Writing certificate signing request to '/var/lib/icinga2/certs//icinga.example.com.csr'.
information/cli: Signing CSR with CA and writing certificate to '/var/lib/icinga2/certs//icinga.example.com.crt'.
information/pki: Writing certificate to file '/var/lib/icinga2/certs//icinga.example.com.crt'.
information/cli: Copying CA certificate to '/var/lib/icinga2/certs//ca.crt'.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Reading '/etc/icinga2/icinga2.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Updating 'NodeName' constant in '/etc/icinga2/constants.conf'.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating 'ZoneName' constant in '/etc/icinga2/constants.conf'.
information/cli: Backup file '/etc/icinga2/constants.conf.orig' already exists. Skipping backup.
Done.
Now restart your Icinga 2 daemon to finish the installation!
上述命令创建一个 /etc/icinga2/conf.d/api-users.conf
文件,默认用户 root
拥有 Icinga2 API 的所有权限。我们需要一个具有 Icinga Web 所需的最低权限的新用户。
打开 api-users.conf 文件进行编辑。
$ sudo nano /etc/icinga2/conf.d/api-users.conf
在文件末尾添加以下代码。为 API 选择一个强密码。
/** api for icingaweb2 */
object ApiUser "icingaweb2" {
password = "PassWordApiIcingaWeb2"
permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}
记下稍后访问该网站所需的凭据。 Icinga2 API 服务器默认侦听端口 5665。重新启动服务以使更改生效。
$ sudo systemctl restart icinga2
下一步是安装 Icinga Web 界面。它已针对 Apache 进行了预先配置,但我们将使用 Nginx 服务器。因此,首先我们需要安装 Nginx 和 SSL 证书。
第 7 步 - 安装 Nginx
Debian 12 附带旧版本的 Nginx。要安装最新版本,您需要下载官方 Nginx 存储库。
导入 Nginx 的签名密钥。
$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
添加 Nginx 主线版本的存储库。
$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
更新系统存储库。
$ sudo apt update
安装 Nginx。
$ sudo apt install nginx
验证安装。在 Debian 系统上,以下命令仅适用于 sudo
。
$ sudo nginx -v
nginx version: nginx/1.25.3
启动 Nginx 服务器。
$ sudo systemctl start nginx
检查服务状态。
$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Mon 2024-01-08 07:43:24 UTC; 4s ago
Docs: https://nginx.org/en/docs/
Process: 16330 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 16331 (nginx)
Tasks: 3 (limit: 2299)
Memory: 2.9M
CPU: 16ms
CGroup: /system.slice/nginx.service
??16331 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
??16332 "nginx: worker process"
??16333 "nginx: worker process"
Jan 08 07:43:24 icinga systemd[1]: Starting nginx.service - nginx - high performance web server...
Jan 08 07:43:24 icinga systemd[1]: Started nginx.service - nginx - high performance web server.
第 8 步 - 安装 SSL
我们需要安装 Certbot 来生成 SSL 证书。您可以使用 Debian 的存储库安装 Certbot 或使用 Snapd 工具获取最新版本。我们将使用 Snapd 版本。
Debian 12 并未安装 Snapd。安装 Snapd 软件包。
$ sudo apt install snapd
运行以下命令以确保您的 Snapd 版本是最新的。
$ sudo snap install core && sudo snap refresh core
安装证书机器人。
$ sudo snap install --classic certbot
使用以下命令确保可以通过创建到 /usr/bin
目录的符号链接来运行 Certbot 命令。
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
验证 Certbot 是否正常运行。
$ certbot --version
certbot 2.8.0
运行以下命令生成 SSL 证书。
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email -d icinga.example.com
上述命令会将证书下载到服务器上的 /etc/letsencrypt/live/icinga.example.com
目录中。
生成 Diffie-Hellman 组证书。
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
检查 Certbot 续订调度程序服务。
$ sudo systemctl list-timers
您会发现 snap.certbot.renew.service
是计划运行的服务之一。
NEXT LEFT LAST PASSED UNIT ACTIVATES
-----------------------------------------------------------------------------------------------------------------------------------------
Mon 2024-01-08 09:47:46 UTC 1h 56min left Sun 2024-01-07 09:47:46 UTC 22h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2024-01-08 13:35:00 UTC 5h 43min left - - snap.certbot.renew.timer snap.certbot.renew.service
Tue 2024-01-09 00:00:00 UTC 16h left Mon 2024-01-08 00:00:01 UTC 7h ago dpkg-db-backup.timer dpkg-db-backup.service
对该过程进行一次演练,以检查 SSL 续订是否正常工作。
$ sudo certbot renew --dry-run
如果没有看到任何错误,则一切都已准备就绪。您的证书将自动更新。
步骤 9 - 配置 Nginx 和 PHP
由于 Icinga 是为 Apache 配置的,因此默认情况下不会安装 PHP-FPM 包。如果您想将图表导出为 PDF,您还需要 PHP Imagick 模块。运行以下命令安装 PHP-FPM 和 PHP Imagick 库。
$ sudo apt install php-fpm php-imagick
配置 PHP-FPM
打开文件 /etc/php/8.2/fpm/pool.d/www.conf
。
$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf
我们需要将 PHP 进程的 Unix 用户/组设置为 nginx。在文件中找到 user=www-data
和 group=www-data
行,并将其更改为 nginx
。
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nginx
group = nginx
...
在文件中找到 listen.owner=www-data
和 listen.group=www-data
行,并将其更改为 nginx
。
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nginx
listen.group = nginx
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
重新启动 PHP-FPM 服务。
$ sudo systemctl restart php8.2-fpm
配置 Nginx
创建并打开文件 /etc/nginx/conf.d/icinga.conf
进行编辑。
$ sudo nano /etc/nginx/conf.d/icinga.conf
将以下代码粘贴到其中。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name icinga.example.com;
access_log /var/log/nginx/icinga.access.log;
error_log /var/log/nginx/icinga.error.log;
# SSL
ssl_certificate /etc/letsencrypt/live/icinga.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/icinga.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/icinga.example.com/chain.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
resolver 8.8.8.8;
location ~ ^/index\.php(.*)$ {
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Depends On The PHP Version
fastcgi_index index.php;
# try_files $uri =404;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/icingaweb2/public/index.php;
fastcgi_param ICINGAWEB_CONFIGDIR /etc/icingaweb2;
fastcgi_param REMOTE_USER $remote_user;
}
location ~ ^/(.*)? {
alias /usr/share/icingaweb2/public;
index index.php;
rewrite ^/$ /dashboard;
try_files $1 $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
return 404;
}
}
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name icinga.example.com;
return 301 https://$host$request_uri;
}
请注意,Nginx 配置中使用的根目录是 /usr/share/icingaweb2/public
。
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
打开文件 /etc/nginx/nginx.conf
进行编辑。
$ sudo nano /etc/nginx/nginx.conf
在 include /etc/nginx/conf.d/*.conf;
行之前添加以下行。
server_names_hash_bucket_size 64;
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
验证 Nginx 配置文件语法。
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重新启动 Nginx 服务。
$ sudo systemctl restart nginx
第 10 步 - 准备 Web 设置
在访问 Icinga Web 之前,我们需要将其与命令行工具一起安装。
$ sudo apt install icingaweb2 icingacli
将 Nginx 用户添加到 icingaweb2
组。
$ sudo usermod -aG icingaweb2 nginx
将 Icingaweb 目录的权限设置为 icingaweb2
组。
$ sudo icingacli setup config directory --group icingaweb2
Successfully created configuration directory /etc/icingaweb2
使用 Icinga Web 时,您需要使用令牌进行身份验证。使用以下命令生成令牌。
$ sudo icingacli setup token create
The newly generated setup token is: 56951f01f9f77a68
记下该令牌,因为稍后您将需要它。您以后随时可以使用以下命令检索它。
$ sudo icingacli setup token show
The current setup token is: 56951f01f9f77a68
下一步是创建数据库和数据库用户。登录 MariaDB shell。
$ sudo mysql
创建 Icinga Web 数据库。
MariaDB [(none)]> CREATE DATABASE icingaweb2;
为 Icinga Web 创建 SQL 用户帐户。
MariaDB [(none)]> CREATE USER 'icingaweb2'@'localhost' IDENTIFIED BY 'Your_password3';
向用户授予数据库的所有权限。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON icingaweb2.* TO 'icingaweb2'@'localhost';
刷新用户权限。
MariaDB [(none)]> FLUSH PRIVILEGES;
退出外壳。
MariaDB [(none)]> exit
重新启动 Nginx 和 PHP-FPM 以应用权限更改。
$ sudo systemctl restart nginx php8.2-fpm
第 11 步 - 设置 IcingaWeb
在浏览器中打开 URL https://icinga.example.com/setup
,您将看到以下屏幕。
输入上一步中生成的令牌,然后按下一步按钮继续。
在下一个屏幕上,选择要安装的模块,然后单击下一步继续。默认情况下会为您选择监控模块。在下一页上,您将看到要求以及是否已满足这些要求。确保所有要求都标记为绿色。
单击下一步进入下一页选择身份验证类型。
身份验证类型默认设置为数据库。单击下一步继续。系统将要求您在下一页上填写数据库凭据。
填写在步骤 10 中创建的数据库凭据。单击验证配置按钮验证凭据。验证后,点击下一步继续。接下来,系统将要求您命名身份验证后端。
保留默认值并单击下一步继续。在下一页上,系统将要求您创建管理员帐户。
输入新管理员帐户的凭据,然后单击下一步继续。接下来,您将看到应用程序配置页面。
未选中启用严格的内容安全策略。检查它并保留所有其他默认值不变。单击下一步继续。系统将要求您查看最后一页上的配置。
您可以返回更改任何设置。如果您满意,请单击下一步继续。
点击下一步继续进行监控模块的配置。接下来,系统将要求您提供 Icinga 数据库凭据。
填写第 3 步中的数据库凭据,然后单击验证配置以验证连接。验证后,点击下一步继续。接下来,系统会要求您填写 API 详细信息。
填写第 6 步中创建的 API 凭据,127.0.0.1
作为主机,然后单击验证配置以验证连接。单击下一步继续。接下来,系统将要求您选择受保护的自定义变量来监控安全性。
保留默认值并单击下一步继续。接下来,系统会要求您检查监控配置。如果您愿意,可以返回并更改它。
如果您满意,请单击完成完成安装。
成功完成后,单击登录 Icinga Web 2 按钮打开登录页面 (https://icinga.example.com
)。
输入您的管理员帐户详细信息,然后单击登录按钮打开 Icinga Web 仪表板。
访问概述>>服务页面检查主服务器的状态,类似于以下内容。
步骤 12 - 初始化主服务器
下一步是将主服务器初始化为主节点。主节点充当监控堆栈的主控制器。运行以下命令开始初始化过程。
$ sudo icinga2 node wizard
如果是代理设置,系统会提示您。输入n
设置主节点。
Welcome to the Icinga 2 Setup Wizard!
We will guide you through all required configuration details.
Please specify if this is an agent/satellite setup ('n' installs a master setup) [Y/n]: n
接下来,系统将要求您提供通用名称或域名。按Enter 选择显示的默认值(如果正确)。否则,请输入域并按 Enter。
Please specify the common name (CN) [icinga.example.com]:
Reconfiguring Icinga...
Checking for existing certificates for common name 'icinga.example.com'...
Certificate '/var/lib/icinga2/certs//icinga.example.com.crt' for CN 'icinga.example.com' already existing. Skipping certificate generation.
Generating master configuration for Icinga 2.
'api' feature already enabled.
接下来,输入主区域名称并按 Enter 继续。在我们的例子中,它与服务器域名相同。
Master zone name [master]: icinga.example.com
接下来,系统将询问您是否要添加任何其他全局区域。按n
跳过添加,然后按Enter 继续。
Default global zones: global-templates director-global
Do you want to specify additional global zones? [y/N]: n
在下一步中,将 API 绑定主机和端口保留为默认值,然后按 Enter 继续。
Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
接下来,按 Y
禁用 /etc/icinga2/conf.d/
目录中的配置,因为稍后我们将使用 Icinga2 区域配置。
Do you want to disable the inclusion of the conf.d directory [Y/n]: Y
Disabling the inclusion of the conf.d directory...
Checking if the api-users.conf file exists...
Done.
Now restart your Icinga 2 daemon to finish the installation!
重新启动服务以应用更改。
$ sudo systemctl restart icinga2
最后但并非最不重要的一点是,运行以下命令为客户端服务器创建票证。使用客户端的域名作为参数。
$ sudo icinga2 pki ticket --cn 'client.example.com'
c81f2a3b86534f34160ed8b776906e5452d8d09c
记下门票以供稍后使用。
步骤 13 - 在客户端服务器上初始化 Icinga2 代理
登录客户端服务器并安装 Icinga2 和监控插件。运行以下命令来执行此操作。
$ wget -O - https://packages.icinga.com/icinga.key | sudo gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/debian icinga-`lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/$(lsb_release -cs)-icinga.list
$ echo "deb-src [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] http://packages.icinga.com/debian icinga-`lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list.d/$(lsb_release -cs)-icinga.list
$ sudo apt update
$ sudo apt install icinga2 monitoring-plugins -y
验证 Icinga 服务是否已启用并正在运行。
$ sudo systemctl status icinga2
? icinga2.service - Icinga host/service/network monitoring system
Loaded: loaded (/lib/systemd/system/icinga2.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/icinga2.service.d
??limits.conf
Active: active (running) since Mon 2024-01-08 12:52:53 UTC; 35s ago
Main PID: 19530 (icinga2)
Status: "Startup finished."
Tasks: 12
Memory: 13.4M
CPU: 216ms
CGroup: /system.slice/icinga2.service
??19530 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
??19573 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
??19578 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
启动 Icinga 节点向导以初始化客户端服务器上的代理。
$ sudo icinga2 node wizard
如果是代理设置,系统会提示您。输入 Y
以设置代理。
Welcome to the Icinga 2 Setup Wizard!
We will guide you through all required configuration details.
Please specify if this is an agent/satellite setup ('n' installs a master setup) [Y/n]: Y
接下来,系统将要求您指定通用名称。保留默认值并按 Enter 继续。
Starting the Agent/Satellite setup routine...
Please specify the common name (CN) [client.example.com]:
接下来,将父端点指定为 icinga.example.com
并输入 Y
以建立从客户端到父节点的连接。
Please specify the parent endpoint(s) (master or satellite) where this node should connect to:
Master/Satellite Common Name (CN from your master/satellite node): icinga.example.com
Do you want to establish a connection to the parent node from this node? [Y/n]: Y
接下来,输入主服务器的IP地址,端口值保持默认不变。
Please specify the master/satellite connection information:
Master/Satellite endpoint host (IP address or FQDN): 199.247.31.184
Master/Satellite endpoint port [5665]:
输入 N
以拒绝添加更多主端点。
Add more master/satellite endpoints? [y/N]: N
接下来,您将看到主服务器的证书信息。按Y
确认信息并继续。
Parent certificate information:
Version: 3
Subject: CN = icinga.example.com
Issuer: CN = Icinga CA
Valid From: Jan 8 07:36:55 2024 GMT
Valid Until: Feb 8 07:36:55 2025 GMT
Serial: 3a:e5:5e:e6:d5:5e:cc:1d:89:be:18:0b:10:cb:7d:54:8f:82:b1:5e
Signature Algorithm: sha256WithRSAEncryption
Subject Alt Names: icinga.example.com
Fingerprint: DB 62 0D 2D AF 73 02 F2 86 92 5E A8 50 CD 0F 4F F2 D6 9E 86 AE F6 F9 E4 D7 F2 F2 60 78 1B 92 E5
Is this information correct? [y/N]: Y
接下来,输入上一步中生成的请求票证。
Please specify the request ticket generated on your Icinga 2 master (optional).
(Hint: # icinga2 pki ticket --cn 'client.example.com'): c81f2a3b86534f34160ed8b776906e5452d8d09c
将 API 绑定主机和端口保留为默认值,然后按 Enter 继续。
Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
接下来,输入Y
两次以接受来自主节点的配置和命令。
Accept config from parent node? [y/N]: Y
Accept commands from parent node? [y/N]: Y
按Enter键接受默认本地区域名称,即客户端域名。输入主域名作为父区域名称以继续。
Reconfiguring Icinga...
Disabling feature notification. Make sure to restart Icinga 2 for these changes to take effect.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
Local zone name [client.example.com]:
Parent zone name [master]: icinga.example.com
按 N
跳过添加其他全局区域。
Default global zones: global-templates director-global
Do you want to specify additional global zones? [y/N]: N
按 Y
跳过禁用 /etc/icinga2/conf.d/
目录中的配置。
Do you want to disable the inclusion of the conf.d directory [Y/n]: Y
Disabling the inclusion of the conf.d directory...
Done.
Now restart your Icinga 2 daemon to finish the installation!
重新启动 Icinga 服务以应用配置更改。
$ sudo systemctl restart icinga2
步骤 14 - 在主服务器上创建区域配置
重新登录服务器并创建一个新目录作为默认区域。
$ sudo mkdir -p /etc/icinga2/zones.d/icinga.example.com/
接下来,在新创建的目录中创建配置文件并打开它进行编辑。
$ sudo nano /etc/icinga2/zones.d/icinga.example.com/client.example.com.conf
将以下代码粘贴到其中。代码中的IP地址应与客户端的公共IP地址匹配。
// Endpoints
object Endpoint "client.example.com" {
}
// Zones
object Zone "client.example.com" {
endpoints = [ "client.example.com" ]
parent = "icinga.example.com"
}
// Host Objects
object Host "client.example.com" {
check_command = "hostalive"
address = "95.179.138.148"
vars.client_endpoint = name
}
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
创建并打开服务文件进行编辑。
$ sudo nano /etc/icinga2/zones.d/icinga.example.com/services.conf
将以下代码粘贴到其中。
// Ping
apply Service "Ping" {
check_command = "ping4"
assign where host.address // check executed on master
}
// System Load
apply Service "System Load" {
check_command = "load"
command_endpoint = host.vars.client_endpoint // Check executed on client01
assign where host.vars.client_endpoint
}
// SSH Service
apply Service "SSH Service" {
check_command = "ssh"
command_endpoint = host.vars.client_endpoint
assign where host.vars.client_endpoint
}
// Icinga 2 Service
apply Service "Icinga2 Service" {
check_command = "icinga"
command_endpoint = host.vars.client_endpoint
assign where host.vars.client_endpoint
}
运行以下命令来验证配置。
$ sudo icinga2 daemon -C
您将得到类似的输出。
[2024-01-08 13:01:26 +0000] information/cli: Icinga application loader (version: r2.14.1-1)
[2024-01-08 13:01:26 +0000] information/cli: Loading configuration file(s).
[2024-01-08 13:01:26 +0000] information/ConfigItem: Committing config item(s).
[2024-01-08 13:01:26 +0000] information/ApiListener: My API identity: icinga.example.com
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 IcingaApplication.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 Host.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 FileLogger.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 4 Zones.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 CheckerComponent.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 2 Endpoints.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 2 ApiUsers.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 ApiListener.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 1 NotificationComponent.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 246 CheckCommands.
[2024-01-08 13:01:26 +0000] information/ConfigItem: Instantiated 4 Services.
[2024-01-08 13:01:26 +0000] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2024-01-08 13:01:27 +0000] information/cli: Finished validating the configuration file(s).
重新启动 Icinga 服务以应用配置更改。
$ sudo systemctl restart icinga2
第 15 步 - 在 Icinga 仪表板上验证
打开 Icinga2 Web 仪表板以验证客户端计算机信息。从左侧菜单中选择概览>>主机,您将看到以下屏幕。
客户端状态可能需要一段时间才会显示为UP。单击客户端可查看有关它的更多详细信息。选择概览>>服务,您将看到有关客户的以下状态。
这确认客户端正在正确地将统计数据发送到 Icinga 主服务器。
结论
关于在 Debian 12 服务器上安装 Icinga 监控软件并将其配置为监控运行相同操作系统的客户端计算机的教程到此结束。如果您有任何疑问,请在下面的评论中发表。