ウェブサイト検索

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


Icinga2 は、ネットワークからのリソースの可用性を確認し、停止をユーザーに通知できる、無料のオープンソース ネットワーク監視ソフトウェアです。 Icinga2 を使用して、ネットワーク サービス (SMTP、POP3、HTTP、NNTP、ping)、ホスト リソース (CPU 使用率、ディスク使用率)、およびネットワーク コンポーネント (スイッチ、ルーター、温度、湿度センサー) を監視できます。 Nagios プラグインと統合できます。

次のチュートリアルでは、Ubuntu 22.04 サーバーに Icinga2 をインストールする方法と、それをクライアント ノードに接続する方法を学習します。デフォルトの Apache サーバーの代わりに、Nginx を使用して Icinga2 Web を実行します。

前提条件

    Ubuntu 22.04 を実行している 2 台のマシン。そのうちの 1 つはマスター サーバーとして機能し、もう 1 つは監視用のクライアントとして機能します。

    両方のサーバーで 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 ubuntu-keyring unzip -y
    

    これらのパッケージの一部はすでにシステムにインストールされている可能性があります。

ステップ 1 - マスターサーバーでファイアウォールを構成する

最初のステップはファイアウォールを構成することです。 Ubuntuにはデフォルトで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
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 - MySQL をインストールする

Ubuntu 22.04 には、最新バージョンの MySQL が同梱されています。単一のコマンドでインストールできます。

$ sudo apt install mysql-server

MySQLのバージョンを確認してください。

$ mysql --version
mysql  Ver 8.0.32-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))

この手順は、MySQL バージョン 8.0.28 以降で必要です。 MySQL シェルに入ります。

$ sudo mysql

次のコマンドを実行して、root ユーザーのパスワードを設定します。数字、大文字、小文字、特殊文字が混在していることを確認してください。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword12!';

シェルを終了します。

mysql> exit

MySQL セキュア インストール スクリプトを実行します。

$ sudo mysql_secure_installation

まず、root パスワードを求められます。入力してください。次に、パスワード検証コンポーネントをインストールするように求められます。 MySQL で使用されるパスワードの強度をチェックします。 Y を押してインストールします。次に、パスワード検証ポリシーのレベルを設定するように求められます。最も強力な2を選択します。

Securing the MySQL server deployment.

Enter password for user root:

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 100

次に、N と入力して root パスワードの変更を拒否します。また、匿名ユーザーを削除し、リモート root ログインを禁止し、テスト データベースを削除し、権限テーブルをリロードするには、Y を入力します。

Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

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

MySQL シェルにログインします。プロンプトが表示されたら、root パスワードを入力します。

$ sudo mysql -u root -p

Icinga データベースを作成します。

mysql> CREATE DATABASE icinga2;

Icinga2 の SQL ユーザー アカウントを作成します。データベースとユーザー名はデフォルトですでに設定されているため、変更しないでください。これらを変更する場合は、ステップ 5 で MySQL ドライバーをインストールする際に追加の手順を実行する必要があります。パスワードを入力するとエラーが表示され、カスタム データベース名とユーザーを指定できる場所を再構成するように求められます。 。

mysql> CREATE USER 'icinga2'@'localhost' IDENTIFIED BY 'Your_password2';

データベースに対するすべての権限をユーザーに付与します。

mysql> GRANT ALL PRIVILEGES ON icinga2.* TO 'icinga2'@'localhost';

ユーザー権限をフラッシュします。

mysql> FLUSH PRIVILEGES;

シェルを終了します。

mysql> 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/ubuntu 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/ubuntu icinga-`lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list.d/$(lsb_release -cs)-icinga.list

システム リポジトリ リストを更新します。

$ sudo apt update

Icinga2 と監視プラグインをインストールします。

$ sudo apt install icinga2 monitoring-plugins -y

ステップ 5 - IDO MySQL ドライバーをマスターサーバーにインストールする

Icinga2 が動作するにはデータベースが必要です。そのためには、IDO MySQL ドライバーをインストールし、データベース接続をセットアップする必要があります。次のコマンドを実行して、MySQL ドライバーをインストールします。

$ sudo apt install -y icinga2-ido-mysql

ドライバーをセットアップし、dbconfig-common ユーティリティを使用してデータベースを作成するように求められます。 [はい] を選択して続行します。

次に、icinga2 データベースの MySQL パスワードの入力を求められます。手順 3 で設定したパスワードを入力して続行します。

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

次に、ido-mysql 機能を有効にするように求められます。 [はい] を選択して続行します。

データベースの詳細は、/etc/icinga2/features-available/ido-mysql.conf ファイルで確認できます。

$ 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

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; vendor preset: enabled)
    Drop-In: /etc/systemd/system/icinga2.service.d
             ??limits.conf
     Active: active (running) since Mon 2023-05-01 08:02:36 UTC; 1s ago
    Process: 9823 ExecStartPre=/usr/lib/icinga2/prepare-dirs /etc/default/icinga2 (code=exited, status=0/SUCCESS)
   Main PID: 9828 (icinga2)
     Status: "Startup finished."
      Tasks: 10
     Memory: 17.6M
        CPU: 657ms
     CGroup: /system.slice/icinga2.service
             ??9828 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
             ??9846 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
             ??9849 /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!

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

api-users.conf ファイルを開いて編集します。

$ sudo nano /etc/icinga2/conf.d/api-users.conf

ファイルの最後に次のコードを追加します。

/** api for icingaweb2 */
object ApiUser "icingaweb2" {
  password = "PassWordApiIcingaWeb2"
  permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}

後で Web サイトにアクセスするために必要となる資格情報をメモしておきます。 Icinga2 API サーバーは、デフォルトでポート 5665 をリッスンします。変更を有効にするためにサービスを再起動します。

$ sudo systemctl restart icinga2

次のステップは、Icinga Web インターフェイスをインストールすることです。 Apache 用に事前設定されていますが、Nginx サーバーを使用します。したがって、まず、Nginx と SSL 証明書をインストールする必要があります。

ステップ 7 - Nginx をインストールする

Ubuntu 22.04 には、古いバージョンの 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/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

システムリポジトリを更新します。

$ sudo apt update

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

$ sudo apt install nginx

インストールを確認します。

$ nginx -v
nginx version: nginx/1.24.0

Nginxサーバーを起動します。

$ sudo systemctl start nginx

ステップ 8 - SSL をインストールする

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

Ubuntu 22.04 には、デフォルトで Snapd がインストールされています。次のコマンドを実行して、Snapd のバージョンが最新であることを確認します。

$ sudo snap install core && sudo snap refresh core

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

$ sudo snap install --classic certbot

次のコマンドを使用して、/usr/bin ディレクトリへのシンボリック リンクを作成して Certbot コマンドを実行できることを確認します。

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

次のコマンドを実行して 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

実行がスケジュールされているサービスの 1 つとして snap.certbot.renew.service が見つかります。

NEXT                        LEFT          LAST                        PASSED         UNIT                     ACTIVATES
------------------------------------------------------------------------------------------------------------------------------------
Mon 2023-05-01 13:37:57 UTC 3h 45min left Mon 2023-05-01 07:20:42 UTC 2h 31min ago   ua-timer.timer           ua-timer.service
Mon 2023-05-01 14:39:29 UTC 4h 47min left Sat 2023-02-04 16:04:18 UTC 2 months ago   motd-news.timer          motd-news.service
Mon 2023-05-01 15:53:00 UTC 6h left       n/a                         n/a            snap.certbot.renew.timer snap.certbot.renew.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.1/fpm/pool.d/www.conf を開きます。

$ sudo nano /etc/php/8.1/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.1-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.1-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 にアクセスする前に、それを設定する必要があります。 Icinga Web を使用する場合は、トークンを使用した認証が必要です。次のコマンドを使用してトークンを生成します。

$ sudo icingacli setup token create
The newly generated setup token is: 3c4d4e155635f512

トークンは後で必要になるため、メモしておきます。次のコマンドを使用すると、後でいつでも取得できます。

$ sudo icingacli setup token show
The current setup token is: 3c4d4e155635f512

次のステップでは、データベースとデータベース ユーザーを作成します。 MySQL シェルにログインします。

$ sudo mysql -u root -p

Icinga Web データベースを作成します。

mysql> CREATE DATABASE icingaweb2;

Icinga Web の SQL ユーザー アカウントを作成します。

mysql> CREATE USER 'icingaweb2'@'localhost' IDENTIFIED BY 'Your_password3';

データベースに対するすべての権限をユーザーに付与します。

mysql> GRANT ALL PRIVILEGES ON icingaweb2.* TO 'icingaweb2'@'localhost';

ユーザー権限をフラッシュします。

mysql> FLUSH PRIVILEGES;

シェルを終了します。

mysql> exit

ステップ 11 - IcingaWeb をセットアップする

ブラウザで URL https://icinga.example.com を開くと、次の画面が表示されます。

前の手順で生成されたトークンを入力し、次へ ボタンを押して続行します。

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

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

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

手順 10 で作成したデータベース認証情報を入力します。[設定の検証] ボタンをクリックして認証情報を確認します。確認したら、[次へ] をクリックして続行します。次に、認証バックエンドの名前を指定するように求められます。

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

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

アプリケーションとログ設定のすべてのデフォルト値をそのままにし、[次へ] をクリックして続行します。最後のページで設定を確認するように求められます。

戻って設定を変更することができます。問題がなければ、[次へ] をクリックして続行します。

[次へ] をクリックして、監視モジュールの構成に進みます。次に、Icinga データベースの認証情報を求められます。

ステップ 3 でデータベースの認証情報を入力し、[設定の検証] をクリックして接続を確認します。確認したら、[次へ] をクリックして続行します。次に、API の詳細を入力するように求められます。

手順 6 で作成した API 認証情報を入力し、[設定の検証] をクリックして接続を確認します。 [次へ] をクリックして続行します。次に、セキュリティを監視するために保護されたカスタム変数を選択するよう求められます。

デフォルト値をそのまま使用し、[次へ] をクリックして続行します。次に、監視構成を確認するように求められます。必要に応じて、戻って変更することができます。

問題がなければ、[完了] をクリックしてインストールを完了します。

正常に完了したら、[Icinga Web 2 にログイン] ボタンをクリックしてログイン ページを開きます。

管理者アカウントの詳細を入力し、ログイン ボタンをクリックして 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 を押して、表示されるデフォルト値を選択します。

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'
365cd931d3091537622a95b113b17775893a224f

後で使用するためにチケットをメモしておきます。

ステップ 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/ubuntu 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/ubuntu 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; vendor preset: enabled)
    Drop-In: /etc/systemd/system/icinga2.service.d
             ??limits.conf
     Active: active (running) since Tue 2023-05-02 07:32:07 UTC; 59min ago
   Main PID: 7602 (icinga2)
     Status: "Startup finished."
      Tasks: 8
     Memory: 13.9M
        CPU: 1.018s
     CGroup: /system.slice/icinga2.service
             ??7602 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
             ??7620 /usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
             ??7623 /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:          May  1 08:28:26 2023 GMT
 Valid Until:         Jun  1 08:28:26 2024 GMT
 Serial:              53:50:d4:1a:85:c5:70:5b:b1:f6:0e:c3:b6:e4:db:62:df:8d:5e:d9

 Signature Algorithm: sha256WithRSAEncryption
 Subject Alt Names:   icinga.example.com
 Fingerprint:         DC BB 90 68 29 E5 C4 B5 74 F5 BC 8C BF A1 8F BF D2 9D A4 E5 A9 9A 43 2C 3B 24 AE A9 CD 19 32 F4

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'): 365cd931d3091537622a95b113b17775893a224f

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

N を押して、/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

同様の出力が得られます。

[2023-05-02 11:21:23 +0000] information/cli: Icinga application loader (version: r2.13.7-1)
[2023-05-02 11:21:23 +0000] information/cli: Loading configuration file(s).
[2023-05-02 11:21:23 +0000] information/ConfigItem: Committing config item(s).
[2023-05-02 11:21:23 +0000] information/ApiListener: My API identity: icinga.example.com
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 IcingaApplication.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 Host.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 FileLogger.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 CheckerComponent.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 4 Zones.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 2 Endpoints.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 2 ApiUsers.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 ApiListener.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 1 NotificationComponent.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 244 CheckCommands.
[2023-05-02 11:21:23 +0000] information/ConfigItem: Instantiated 4 Services.
[2023-05-02 11:21:23 +0000] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2023-05-02 11:21:23 +0000] information/cli: Finished validating the configuration file(s).

Icinga サービスを再起動して、構成の変更を適用します。

$ sudo systemctl restart icinga2

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

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

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

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

結論

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

関連記事: