概要
監視ツールして、nagios をインストールしました
その時にインストール時のメモです。
構成情報
OS
- CentOS5.5
ミドルウェア
- Nagios 3.2.3
- apache 2.2.3-43
※上記の環境を、VirtualBOXで構築しています
+-----------------------------------------------------------------+ | HOSTNAME | IP [eth0] | 役割、起動サービスなど +-----------------------------------------------------------------+ | ex-www01 | 192.168.0.110 | nagios サーバ 及び 監視対象サーバ +-----------------------------------------------------------------+
【作業内容】
- nagios ユーザの追加
- nagios 本体のインストール及び日本語パッチ適用
- さざなみフォントを適用
- テーマの変更
- nagios plugins のインストール
- Nagiosの設定 (nagios.cfg)
- アラートメール送信先アドレスを設定 (contacts.cfg)
- 日本語でメールを送信する際の文字化け防止設定を行う (commands.cfg)
- ローカルホストの設定 (localhost.cfg)
- アラート送信時間を変更する (templates.cfg)
- nagios 設定 (ex-www01.cfg)
- apache のトップディレクトリにテストページ作成
- nagios の起動
nagios ユーザの追加
nagios を実行するのユーザを追加し、適切なグループに所属させます。
※ UID,GID を指定したのは、別ホストの監視対象サーバのUID,GIDを統一させる為です
# yum -y install httpd php gcc glibc glibc-common gd gd-devel # useradd -m -s /sbin/nologin -u 1001 -g 1001 nagios # usermod -G nagios apache # groupadd nagcmd # usermod -a -G nagcmd nagios # usermod -a -G nagcmd apache
nagios のダウンロード
# cd /usr/local/src # wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz # wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz # wget http://ftp.momo-i.org/pub/other/nagios-jp-3.2.3.patch.gz
nagios 本体のインストール及び日本語パッチ適用
nagios のWEB画面が英語表記で分かりにくいので日本語パッチをあててから、nagiosをインストールします
# tar zxvf nagios-3.2.3.tar.gz # gunzip nagios-jp-3.2.3.patch.gz # cd nagios-3.2.3 # patch -p1 < ../nagios-jp-3.2.3.patch # ./configure # make all # make install # make install-init # make install-config # make install-commandmode # make install-webconf
さざなみフォントを適用
一様、日本語フォントをインストールします
# cd /usr/local/src # wget http://osdn.dl.sourceforge.jp/efont/10087/sazanami-20040629.tar.bz2 # tar xjvf sazanami-20040629.tar.bz2 # mkdir /usr/local/nagios/etc/font/ # cp sazanami-*.ttf /usr/local/nagios/etc/font/ # chown -Rf nagios:nagios /usr/local/nagios/etc/font
テーマの変更
デフォルトテーマが暗いので、明るめのテーマに変更します
# cd /usr/local/src # mkdir nagios-themes/ # wget http://lancet.mit.edu/mwall/projects/nagios/exfoliation-0.7.tgz # tar xzvf exfoliation-0.7.tgz # mv /usr/local/nagios/share/etc/stylesheets /usr/local/nagios/share/etc/stylesheets-orig # mv /usr/local/nagios/share/etc/images /usr/local/nagios/share/etc/images-orig # mv stylesheets /usr/local/nagios/etc/share/ # mv images /usr/local/nagios/etc/share/ # chown -Rf nagios:nagios /usr/local/nagios/share/etc/stylesheets # chown -Rf nagios:nagios /usr/local/nagios/share/etc/images # ls -l /usr/local/nagios/share -rw-rw-r-- 1 nagios nagios 556 5月 28 11:49 config.inc.php drwxrwxr-x 2 nagios nagios 4096 5月 28 11:49 contexthelp drwxrwxr-x 3 nagios nagios 4096 5月 28 11:49 docs drwxr-xr-x 3 nagios nagios 4096 10月 22 2010 images drwxrwxr-x 3 nagios nagios 4096 5月 28 11:49 images-orig drwxrwxr-x 2 nagios nagios 4096 5月 28 11:49 includes -rw-rw-r-- 1 nagios nagios 1627 5月 28 11:49 index.php drwxr-xr-x 4 root root 4096 5月 28 11:52 locale -rw-rw-r-- 1 nagios nagios 3440 5月 28 11:49 main.php drwxrwxr-x 2 nagios nagios 4096 5月 28 11:49 media -rw-rw-r-- 1 nagios nagios 26 5月 28 11:49 robots.txt -rw-rw-r-- 1 nagios nagios 5949 5月 28 11:49 side.php drwxrwxr-x 2 nagios nagios 4096 5月 28 11:49 ssi drwxrwxr-x 2 nagios nagios 4096 12月 26 04:54 stylesheets drwxrwxr-x 2 nagios nagios 4096 5月 28 11:49 stylesheets-orig
nagios plugins のインストール
# cd /usr/local/src # tar zxvf nagios-plugins-1.4.15.tar.gz # cd nagios-plugins-1.4.15 # ./configure # make all # make install
Nagiosの設定 (nagios.cfg)
nagios 本体の設定をおこないます。変更箇所は、監視対象サーバの設定を格納するディレクトリを変更します
# cd /usr/local/nagios/etc # cp -p nagios.cfg nagios.cfg.org # vi nagios.cfg #cfg_dir=/etc/nagios/servers # ↓ コメントアウトして、以下に変更 cfg_dir=/usr/local/nagios/etc/servers
アラートメール送信先アドレスを設定 (contacts.cfg)
障害検知した時に送付する、アラートメールのメールアドレスを変更します
# cp -p objects/contacts.cfg objects/contacts.cfg.org
# vi objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
# ↓変更(アラート連絡先)
email hogehoge@example.jp ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
日本語でメールを送信する際の文字化け防止設定を行う (commands.cfg)
# cp -p objects/commands.cfg objects/commands.cfg.org
# vi objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
# ↓変更
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
# ↓変更
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
ローカルホストの設定 (localhost.cfg)
ローカルホストの設定を変更します
# cp -p objects/localhost.cfg objects/localhost.cfg.org
# vi objects/localhost.cfg
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
# ↓変更
notifications_enabled 1 #ローカルホストのSSH状態に異常が起きたらアラートメールを送信する
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
# ↓変更
notifications_enabled 1 #ローカルホストのHTTP状態に異常が起きたらアラートメールを送信する
}
アラート送信時間を変更する (templates.cfg)
アラート送信時間を24時間送付するようにします、デフォルトでは営業時間のみです
# cp -p objects/templates.cfg objects/templates.cfg.org
# vi objects/templates.cfg ← アラート送信時間を変更する
define host{
name linux-server
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period workhours # この状態だと平日の9時~17時の間にしかアラートメールが送信されない
#↓変更
notification_period 24x7 # 24時間365日アラートメールを送信するようにする
notification_interval 120
notification_options d,u,r
contact_groups admins
register 0
}
define service{
name generic-service ; The 'name' of this service template
・
・
・
notification_interval 120 ; Re-notify about service problems every hour
# ↓変更(アラート通知を一度のみにする。通常は2時間毎に再送される。)
notification_interval 0 ; Re-notify about service problems every hour
nagios 設定
nagis のWEB画面のBASIC認証のUserID・PASSを設定します。
※ nagiosadminに指定しない場合は、何かしら設定ファイルの変更が必要です
# htpasswd -c /usr/local/nagios/htpasswd.users nagiosadmin New password:パスワードを入力 ******** Re-type new password:パスワードを入力 ******** Adding password for user nagiosadmin
監視対象サーバ(ex-www01) の設定をおこないます。
PING,SSH,HTTP のみを有効にします
# mkdir /usr/local/nagios/etc/servers
# chown nagios:nagios /usr/local/nagios/etc/servers
# vi /usr/local/nagios/etc/servers/ex-www01.cfg
define host{
use linux-server
host_name ex-www01 # hostname
alias ex-www01 # hostname
address 192.168.0.110 # ipaddr
}
define service{
use generic-service
host_name ex-www01
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name ex-www01
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name ex-www01
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
設定ファイルの確認及びテストを実施
Errors,Warnings が 0 ならOKです
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 3.2.3 Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 10-03-2010 License: GPL Website: http://www.nagios.org Reading configuration data... Read main config file okay... Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'... Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'... Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'... Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'... Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'... Processing object config directory '/usr/local/nagios/etc/servers'... Processing object config file '/usr/local/nagios/etc/servers/ex-ns1.cfg'... Processing object config file '/usr/local/nagios/etc/servers/ex-www01.cfg'... Total Warnings: 0 Total Errors: 0 # chown -Rf nagios:nagios /usr/local/nagios/etc/servers
apache のトップディレクトリにテストページ作成
DocumentRoute にHTMLファイルが無いと HTTPコードの403が帰ってきて
nagiosで障害検知となるので、テストページを作成する
# vi /var/www/html/index.html <html> <head> <title>ex-www01</title> </head> <body> test ex-www01 </body> </html> # chown apache:apache /var/www/html/index.html
nagios の起動
# /etc/rc.d/init.d/nagios start Starting nagios:This account is currently not available. done. # chkconfig nagios on # chkconfig --list nagios nagios 0:off 1:off 2:on 3:on 4:on 5:on 6:off # /etc/init.d/httpd restart 「nagios」の管理ページにアクセスする。 ブラウザのアドレス欄に「http://IP Addr or Domain/nagios/」を入力し、Basic認証を行いアクセスする。


コメント