4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

監視ツールIcinga 2のインストール

Last updated at Posted at 2020-03-01

Icinga 2

Icinga 2はエージェント/エージェントレスに両対応した監視ツールで、監視プラグインがNagios互換のOSS。
多分、普通はWebUIを提供するIcinga Web 2を併用する。

インストール手順

CentOS 7環境にてマスタサーバ単独を単独で立ち上げる方法を記載する。1CPUのサーバでも200台のサーバをSNMP監視する位は可能だったため、サテライトサーバまで手をつける必要が無かった。

今回は事前にApache httpdの導入が終わっているサーバに対して、Icinga 2、Icinga Web 2に加え、Graphiteプラグインの導入まで行う。

Icinga 2の導入

yumを使ってIcinga 2をインストールする。

# yum localinstall https://packages.icinga.com/epel/icinga-rpm-release-7-latest.noarch.rpm
# yum install epel-release
# yum install icinga2 icinga2-bin icinga2-common icinga2-ido-mysql icinga2-selinux vim-icinga2
# yum install nagios-plugins-all
 
# systemctl start icinga2
# systemctl enable icinga2

MariaDBをインストールして設定する。

# yum install mariadb-server

Graphiteの導入時にグラフが表示されない不具合が発生しない様に対策しておく。

/etc/my.cnf.d/server.cnf
    [mariadb]
+   character_set_server = latin1
+   collation_server = latin1_general_ci

他に必要な設定を行った後、MariaDBを適当に初期設定。最後にIcinga2用のテーブルをSQLから投入してIcinga2を起動。

# systemctl start mariadb
# systemctl enable mariadb
# mysql_secure_installation

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE icinga;
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> QUIT

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

Icinga Web 2の導入

WebUIインストール。icingaweb2がrh-php71-fpmをインストールするので必要に応じて設定・起動する。なお、rh-php71にはphp-pecl-imagickが無いため、インストールチェック時に警告が出る。

rh-php71-fpmを利用するのが嫌な場合は、remi-php71などを使っても良いが、その場合は/etc/httpd/conf.d/icingaweb2.conf を確認して必要な部分を変更する。

# yum install centos-release-scl
# yum install icingaweb2 icingacli

# systemctl start rh-php71-php-fpm
# systemctl enable rh-php71-php-fpm
# systemctl restart httpd

Icinga Web 2の初期設定

http://<hostname.domain>/icingaweb2/ にアクセスしてログイン。指示に従ってトークンの作成と設定を行う。

commandを有効にする

WebUI操作時に icinga2: Can't send external Icinga command to the local command file というエラーが出る場合は、# icinga2 feature list を実行してcommandがEnabled featuresにあるか確認する。Disabledになってたら icinga2 feature enable command を実行する。

Graphiteによるグラフ表示の設定

Graphiteの設定

Graphiteをインストールする。

# yum install graphite-web python-carbon 

/etc/graphite-web/local_settings.py を編集して、SECRET_KEY、TIME_ZONE などの設定を行う。

# ll /var/lib/graphite-web/graphite.db を実行し、ファイルサイズが0なら # python /usr/lib/python2.7/site-packages/graphite/manage.py syncdb を実行する。

初期設定値だとIcinga Web 2で1日より前のグラフが正常に表示されなくなるため、RRDのデータ保存サイクルの変更を行う。下記の設定値は参考で、適当に変えても問題ない。
Graphiteで利用しているRRDのWhisperデータベースは /var/lib/carbon/whisper/icinga2 以下に保存される。Icinga 2の監視サーバでGraphiteを利用する場合は、ここのディスク容量とIOPS性能に注意する。

/etc/carbon/storage-schemas.conf
-   retentions = 60s:1d
+   retentions = 60s:1d,5m:30d,1h:3y
# systemctl start carbon-cache
# systemctl enable carbon-cache

VirtualHost用の設定を行うのが面倒な場合は、Graphite Webの設定を変更し、ポート80以外の適当なポートで動作する様に変更する。
また、同設定で /usr/share/graphite/ へのアクセス許可IPに動作確認用PCのIPを追加しておく。Graphite Webの動作確認後はRequire localだけに戻して良い。

/etc/httpd/conf.d/graphite-web.conf
+   Listen *:81
-   <VirtualHost *:80>
+   <VirtualHost *:81>
# icinga2 feature enable graphite
# systemctl restart icinga2

http://<hostname.domain>:81/graphite-web/ にアクセスして、Icinga 2からのデータ転送が行われていることを確認する。上手くいかない場合は # systemctl stop icinga2 && systemctl start icinga2
問題が無ければGraphite側の設定と動作確認終了。

Icinga 2用Graphiteモジュールの設定

Graphiteモジュールをgithubから拾ってきてインストールする。

# git clone https://github.com/Icinga/icingaweb2-module-graphite.git /usr/share/icingaweb2/modules/graphite
# icingacli module enable graphite

最後にWebUI上でGraphiteの設定を行う。
[設定] > [モジュール設定] > [graphite] > [バックエンド]
Graphite Web URL: http://127.0.0.1:81/

Graphite用にグラフテンプレを定義する場合

/usr/share/icingaweb2/modules/graphite/templates/ にテンプレを作成する。

その他

後からWhisperデータベースの設定を変える場合

設定を変更しないまま運用を開始している場合は、下記のコマンドでRRDの設定を変更する。

# cd /var/lib/carbon/whisper/icinga2
# sudo -u carbon find ./ -type f -name '*.wsp' -exec whisper-resize {} 60s:1d 5m:30d 1h:3y \;
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?