監視ソフト(SELinux EnforcingでIcinga2)

Icinga2

Zabbixはちょっと重い気がする(たぶん気のせい)ので、Icinga2で監視してみる。

LAMPのインストール・設定

Lはfedora39。

# dnf install -y httpd mariadb-server mariadb php php-cli php-devel php-pear make php-mysqlnd php-pecl-imagick php-pecl-imagick-devel

systemctl。

# systemctl enable httpd
# systemctl enable mariadb
# systemctl start httpd
# systemctl start mariadb

mariadbの初期設定をいつものように。
/etc/my.cnf.d/charset.cnfを以下の内容で新規作成する。

[mysqld]
character-set-server = utf8mb4

[client]
default-character-set = utf8mb4

初期化。

mysql_secure_installation

firewalldの設定も。

Icinga2のインストール

Icinga2のfedoraへのインストールは公式の通りに実施した。また、公式のfedoraの手順では足りないところがあると思われるので、こちらも参考にしている。

Fedora Repository

icinga2用のリポジトリの設定。下記の内容をシェルスクリプトにして実行する。

rpm --import https://packages.icinga.com/icinga.key
dnf install -y 'dnf-command(config-manager)' 
dnf config-manager --add-repo https://packages.icinga.com/fedora/$(. /etc/os-release; echo  $VERSION_ID")/release


一行目のコマンドを実行すると以下のようになるが引き続きコマンドを実行すると正常に完了するようだ。

warning: Certificate C6E319C334410682:
  Policy rejects subkey 146117B313F2C675: Policy rejected asymmetric algorithm

以下のメッセージが表示されれば完了。

Adding repo from: https://packages.icinga.com/fedora/39/release

リポジトリの確認。

# dnf repolist
repo id                                    repo name
fedora                                     Fedora 39 - x86_64
fedora-cisco-openh264                      Fedora 39 openh264 (From Cisco) - x86_64
packages.icinga.com_fedora_39_release      created by dnf config-manager from https://packages.icinga.com/fedora/39/release
updates                                    Fedora 39 - x86_64 - Updates
#

Icinga2のインストール

icinga2をインストールする。

# dnf -y install icinga2 nagios-plugins-all
# systemctl enable icinga2
# systemctl start icinga2

SELinuxが有効になっている場合は、以下のコマンドを実行し追加のパッケージをインストールする。

# dnf -y install icinga2-selinux

Icinga が SELinux コンテキストで稼働していることの確認。

# ps -eZ | grep icinga2
system_u:system_r:icinga2_t:s0     4846 ?        00:00:01 icinga2
system_u:system_r:icinga2_t:s0     4869 ?        00:00:05 icinga2
system_u:system_r:icinga2_t:s0     4874 ?        00:00:00 icinga2
#

icinga2 の IDO MySQL バックエンドをインストール

# dnf install -y icinga2-ido-mysql

DataBaseの設定

mariadbへの接続。

# mysql -u root -p

データベースとユーザの作成。

CREATE DATABASE icinga;
GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icingapassdb';
FLUSH PRIVILEGES;

icinga2-ido-mysql データベース スキーマを icinga データベースにインポートする。

# mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql

以下のコマンドを使用して新しい構成を適用する。icinga2-ido-mysql 機能を有効にする。

# icinga2 feature enable ido-mysql
Enabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect.
# systemctl restart icinga2

API機能の有効化

API機能を有効にする。同時に証明書のセットアップ、自動生成されたパスワードを持つ API ユーザー(root)の作成、およびその利用者を構成ファイル(/etc/icinga2/conf.d/api-users.conf)に追加する。
以下のコマンドを実行するだけ。

# icinga2 api setup

上記のコマンドを実行した結果。

# 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//icinga2.yo7612.com.csr'.
information/base: Writing private key to '/var/lib/icinga2/certs//icinga2.yo7612.com.key'.
information/base: Writing certificate signing request to '/var/lib/icinga2/certs//icinga2.yo7612.com.csr'.
information/cli: Signing CSR with CA and writing certificate to '/var/lib/icinga2/certs//icinga2.yo7612.com.crt'.
information/pki: Writing certificate to file '/var/lib/icinga2/certs//icinga2.yo7612.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!

#

API機能の有効化コマンドを実行後、以下のコマンドを実行しicinga2を再起動しておく。

# systemctl restart icinga2

Icingaweb2 のインストールと構成

Icingaweb2 のインストール

次のコマンドを実行して、icingaweb2 パッケージをインストールする。

# dnf install -y icingaweb2 icingacli

/etc/httpd/conf.d/icingaweb2.confができていることを確認する。

# cat /etc/httpd/conf.d/icingaweb2.conf
Alias /icingaweb2 "/usr/share/icingaweb2/public"

<Directory "/usr/share/icingaweb2/public">
    Options SymLinksIfOwnerMatch
    AllowOverride None
    Require all granted

    SetEnv ICINGAWEB_CONFIGDIR "/etc/icingaweb2"

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /icingaweb2/
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </IfModule>

    <IfModule !mod_rewrite.c>
        DirectoryIndex error_norewrite.html
        ErrorDocument 404 /icingaweb2/error_norewrite.html
    </IfModule>

    DirectoryIndex index.php
</Directory>
#

apacheの再起動を行う。

# systemctl restart httpd

データベースの設定

icingaweb2 用の新しいデータベースとユーザーを作成する。

# mysql -u root -p

以下のコマンドを実行。

CREATE DATABASE icingaweb2;
GRANT ALL ON icingaweb2.* TO 'icingaweb2'@'localhost' IDENTIFIED BY 'icingaweb2passdb';
FLUSH PRIVILEGES;

セットアップ用トークンの作成

cingaweb2 セットアップ トークンを生成する。

# icingacli setup token create
The newly generated setup token is: xxxxxxxxxxxxxxxx
# icingacli setup token show
The current setup token is: xxxxxxxxxxxxxxxx

上記のtokenはのちに利用するのでメモしておく。

Icinga Web 2 の構成

SELinux

「Icinga Web 2」画面の「Read- and writable configuration directory」の項目が「The directory /etc/icingaweb2 is not writable.」となって先に進めなかったので以下の設定をしておく。

回避策を調べてみるとSELinuxをpermissiveで動作させるというのが多くて実際それで先に進めることができた。

が、もうちょっと調べてみると、以下のようなコマンドを実行することでenforcingのままでOKであった。

# semanage fcontext -a -t httpd_sys_rw_content_t '/etc/icingaweb2(/.*)?'
# restorecon -RFvv /etc/icingaweb2
# /usr/sbin/setsebool -P httpd_can_network_connect 1

Webブラウザでの設定

Webブラウザで以下のURLに接続する。

http://IPアドレス/icingaweb2/setup

つづいて、「Authentication」画面はそのまま「Next」をクリックする。

WebブラウザでIcinga Web 2の設定作業を行っていく。

「Welcome to the configuration of Icinga Web 2!」画面の「Setup Token」に先ほどメモしたtokenを入力し、「Next」をクリック。

「Modules」画面ではなにもせずに「Next」をクリック。

つづいて、「Authentication」画面はそのまま「Next」をクリックする。

「Database Resource」画面では、icingaweb2 のデータベース名、ユーザー名、およびパスワードを入力し、「Next」 をクリックする。

「Authentication Backend」画面ではそのまま「Next」をクリック。

「Administration」画面で新しい管理者IDとパスワードを入力し、「Next」をクリックする。

「Application Configuration」をデフォルトのままにして、「Next」をクリックする。

次の画面で設定一覧がでるので内容を確認して「Next」をクリックする。訂正を行う場合は「Back」で戻ることが可能。

「Welcome to the configuration of the monitoring module for Icinga Web 2!」画面で「Next」をクリック。

「Monitoring IDO Resource」画面で、icinga2-ido-mysql のデータベース名、ユーザー名、およびパスワードを入力し、「Validate Configuration」ボタンをクリックする。

次のエラーが出たら、/etc/icinga2/features-available/ido-mysql.confを編集する。

There is currently no icinga instance writing to the IDO. Make sure that a icinga instance is configured and able to write to the IDO.

以下の内容を追加する。

object IdoMysqlConnection "ido-mysql" {
  user = "icinga",
  password = "icingapassdb",
  host = "localhost",
  database = "icinga"
}

編集が終わったらicinga2を再起動する。

# systemctl restart icinga2

Web ブラウザに戻り、「Skip Validation」ボタンを有効にし「Next」をクリックする。

「Command Transport」画面で、「Transport Type」で「Local Command File」を選択し「Next」をクリックする。

「Monitoring Security」画面ではそのまま「Next」をクリックする。

設定確認画面がでるので、内容が正しければ「Finish」をクリックする。

ログイン画面がでるので先ほどのユーザIDとパスワードでログインすることができる。

commandを有効にする

以下のコマンドを実行してcommandがEnabled featuresにあるか確認する。

# icinga2 feature list

Disabledになってたら

# icinga2 feature enable command

を実行する。

たいていのサイトはここまでしか説明していない。

監視設定はこちらで。

コメント

タイトルとURLをコピーしました