監視ソフトウェア · 13 min read · Nov 22, 2025

Debian 12にIcinga 2監視ソフトウェアをインストールする方法

Icinga 2は、ネットワークリソースの可用性をチェックし、ユーザーに障害を通知し、報告用のパフォーマンスデータを生成するオープンソースの監視システムです。Icinga2を使用して、ネットワークサービス(SMTP、POP3、HTTP、NNTP、ping)、ホストリソース(CPU使用率、ディスク使用率)、およびネットワークコンポーネント(スイッチ、ルーター、温度および湿度センサー)を監視できます。Nagiosプラグインと統合することもできます。

以下のチュートリアルでは、Debian 12サーバーにIcinga2をインストールし、クライアントノードに接続する方法を学びます。デフォルトのApacheサーバーの代わりに、Icinga2 Webを実行するためにNginxを使用します。

前提条件

  • Debian 12を実行している2台のマシン。一方はマスターサーバーとして、もう一方は監視用のクライアントとして機能します。
  • 両方のサーバーでsudo権限を持つ非rootユーザー。
  • マスターサーバー用の完全修飾ドメイン名(FQDN)icinga.example.comとクライアントノード用のclient.example.com
  • すべてが更新されていることを確認してください。 $ 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(Uncomplicated Firewall)が付属しています。

ファイアウォールが実行中かどうかを確認します。

$ 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
コマンドは既存のssh接続を中断する可能性があります。操作を続行しますか(y|n)? y
ファイアウォールはアクティブで、システム起動時に有効になっています

再度ファイアウォールの状態を確認します。

$ 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!

MariaDBにログインしてセキュリティを確保するには、現在のrootユーザーのパスワードが必要です。MariaDBをインストールしたばかりで、まだrootパスワードを設定していない場合は、ここでEnterを押してください。

Enter current password for root (enter for none):

次に、Unixソケット認証メソッドに切り替えるかどうかを尋ねられます。unix_socketプラグインを使用すると、オペレーティングシステムの資格情報を使用してMariaDBサーバーに接続できます。すでに保護されたrootアカウントがあるため、nを入力して続行します。

OK, successfully used password, moving on...

rootパスワードを設定するか、unix_socketを使用することで、適切な認証なしに誰もMariaDBのrootユーザーにログインできないようにします。

すでにrootアカウントが保護されているため、安全に'n'と答えることができます。

Switch to unix_socket authentication [Y/n] n

次に、rootパスワードを変更するかどうかを尋ねられます。Debian 12では、rootパスワードは自動システムメンテナンスに密接に関連しているため、そのままにしておくべきです。nを入力してさらに進めます。

 ... skipping.

すでにrootアカウントが保護されているため、安全に'n'と答えることができます。

Change the root password? [Y/n] n

次に、MariaDBのセキュリティを向上させるためのいくつかの質問が行われます。匿名ユーザーを削除し、リモートrootログインを禁止し、テストデータベースを削除し、特権テーブルを再読み込みするためにYを入力します。

 ... skipping.

デフォルトでは、MariaDBのインストールには匿名ユーザーがあり、誰でもユーザーアカウントを作成せずにMariaDBにログインできます。これはテスト用にのみ意図されており、インストールをスムーズに進めるためのものです。生産環境に移行する前に削除する必要があります。

Remove anonymous users? [Y/n] y
 ... Success!

通常、rootは'localhost'からのみ接続できるようにするべきです。これにより、誰かがネットワークからrootパスワードを推測できなくなります。

Disallow root login remotely? [Y/n] y
 ... Success!

デフォルトでは、MariaDBには誰でもアクセスできる'test'という名前のデータベースが付属しています。これもテスト用にのみ意図されており、生産環境に移行する前に削除する必要があります。

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

特権テーブルを再読み込みすることで、これまでに行ったすべての変更が即座に有効になります。

Reload privilege tables now? [Y/n] y
 ... Success!

クリーンアップ中...

すべて完了しました!上記のすべてのステップを完了した場合、MariaDBのインストールは安全になっているはずです。

MariaDBを使用していただきありがとうございます!

コマンドラインでsudo mysqlまたはsudo mariadbと入力することでMariaDBシェルに入ることができます。

ステップ3 - MariaDBを構成する

MariaDBシェルにログインします。プロンプトが表示されたら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機能を有効にするように求められます。続行するにはYesを選択します。

Icinga IDO-MySQL feature

次に、dbconfig-commonユーティリティを使用してドライバーを設定し、データベースを作成するように求められます。続行するにはYesを選択します。

次に、icinga2データベースのMySQLパスワードを尋ねられます。ステップ3で設定したパスワードを入力して続行します。

Enter Database password for Icinga2

再度パスワードを確認するように求められます。

Icinga2 Confirm Password

データベースの詳細は/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!

上記のコマンドは、デフォルトユーザーrootがIcinga2 APIに対してすべての権限を持つ/etc/icinga2/conf.d/api-users.confファイルを作成します。最小限の権限を持つ新しいユーザーが必要です。

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をインストールする

SSL証明書を生成するためにCertbotをインストールする必要があります。Debianのリポジトリを使用してCertbotをインストールするか、Snapdツールを使用して最新バージョンを取得できます。Snapdバージョンを使用します。

Debian 12にはSnapdがインストールされていません。Snapdパッケージをインストールします。

$ sudo apt install snapd

次のコマンドを実行して、Snapdのバージョンが最新であることを確認します。

$ sudo snap install core && sudo snap refresh core

Certbotをインストールします。

$ sudo snap install --classic certbot

次のコマンドを使用して、Certbotコマンドが/usr/binディレクトリで実行できるようにシンボリックリンクを作成します。

$ 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 protected] -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がスケジュールされたサービスの1つとして表示されます。

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 - ウェブセットアップを準備する

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シェルにログインします。

$ 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を開くと、次の画面が表示されます。

Icinga Web Setup Page

前のステップで生成したトークンを入力し、次へボタンを押して進みます。

Icinga Modules Setup

次の画面で、インストールしたいモジュールを選択し、次へをクリックして進みます。Monitoringモジュールはデフォルトで選択されています。次のページでは、要件が表示され、それらが満たされているかどうかが示されます。すべての要件が緑色にマークされていることを確認してください。

Icinga Requirements Page

次へをクリックして次のページに進み、認証タイプを選択します。

Icinga Authentication Type

認証タイプはデフォルトでデータベースに設定されています。次へをクリックして進みます。次のページでは、データベースの資格情報を入力するように求められます。

Icinga Web Database Credentials

ステップ10で作成したデータベースの資格情報を入力します。構成を検証ボタンをクリックして資格情報を確認します。確認が完了したら、次へをクリックして進みます。次に、認証バックエンドの名前を付けるように求められます。

Icinga Authentication Backend

デフォルト値のままにして次へをクリックして進みます。次のページでは、管理者アカウントを作成するように求められます。

Icinga Administrator Details

新しい管理者アカウントの資格情報を入力し、次へをクリックして進みます。次に、アプリケーション構成ページが表示されます。

Icinga Application Configuration

厳格なコンテンツセキュリティポリシーを有効にするはチェックされていません。チェックを入れ、他のすべてのデフォルト値はそのままにします。次へをクリックして進みます。最後のページで構成を確認するように求められます。

Icinga Review Configuration

設定を変更するために戻ることができます。満足したら、次へをクリックして進みます。

Icinga Web 2 Configuration Module Welcome

次へをクリックして監視モジュールの構成を続行します。次に、Icingaデータベースの資格情報を求められます。

Icinga Database Credentials

ステップ3でのデータベースの資格情報を入力し、構成を検証をクリックして接続を確認します。確認が完了したら、次へをクリックして進みます。次に、APIの詳細を入力するように求められます。

Icinga API Details

ステップ6で作成したAPIの資格情報を入力し、ホストとして127.0.0.1を入力し、構成を検証をクリックして接続を確認します。次へをクリックして進みます。次に、監視セキュリティのための保護されたカスタム変数を選択するように求められます。

Icinga Monitoring Security

デフォルト値のままにして次へをクリックして進みます。次に、監視構成を確認するように求められます。変更したい場合は戻ることができます。

Icinga Monitoring Configuration Review

満足したら、完了をクリックしてインストールを完了します。

Icinga Installation Finished

成功裏に完了したら、Icinga Web 2にログインボタンをクリックしてログインページを開きます(https://icinga.example.com)。

Icinga Web Login Page

管理者アカウントの詳細を入力し、ログインボタンをクリックしてIcinga Webダッシュボードを開きます。

Icinga Web Dashboard

概要 >> サービスページに移動して、マスターサーバーの状態を確認します。

Icinga Web Services Page

ステップ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 Node Wizardを開始します。

$ 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を2回入力します。

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

/etc/icinga2/conf.d/ディレクトリからの構成を無効にするかどうかを尋ねられます。Yを押して無効にします。

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/cli: Finished validating the configuration file(s).

構成変更を適用するためにIcingaサービスを再起動します。

$ sudo systemctl restart icinga2

ステップ15 - Icingaダッシュボードで確認する

Icinga2 Webダッシュボードを開いてクライアントマシンの情報を確認します。左側のメニューから概要 >> ホストを選択すると、次の画面が表示されます。

Icinga Web Dashboard Hosts Page

クライアントの状態がUPとして表示されるまでに時間がかかる場合があります。クライアントをクリックして詳細を確認します。概要 >> サービスを選択すると、クライアントに関する次のステータスが表示されます。

Icinga Client Services details

これにより、クライアントがIcingaマスターサーバーに正しく統計を送信していることが確認できます。

結論

これで、Debian 12サーバーにIcinga監視ソフトウェアをインストールし、同じオペレーティングシステムを実行しているクライアントマシンを監視するように構成するチュートリアルが終了します。質問がある場合は、下のコメントに投稿してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。