CentOS5にnagiosをインストールする
例によってCent OS5にインストール。
参考はいつも通り、こちら( http://centossrv.com/nagios.shtml )。
・ひたすら実行
yum -y install gd-devel useradd -d /usr/local/nagios/ -M nagios wget http://jaist.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.1.tar.gz tar zxvf nagios-3.0.1.tar.gz cd nagios-3.0.1 wget http://jaist.dl.sourceforge.jp/nagios-jp/30391/nagios-3.0.1-ja-utf8.patch.gz gzip -dc nagios-3.0.1-ja-utf8.patch.gz |patch -p0 ./configure && make all && make fullinstall && make install-config cd .. rm -rf nagios-3.0.1* cd wget http://osdn.dl.sourceforge.jp/efont/10087/sazanami-20040629.tar.bz2 tar jxvf sazanami-20040629.tar.bz2 mkdir /usr/local/nagios/etc/font cp sazanami-20040629/sazanami-gothic.ttf /usr/local/nagios/etc/font/font.ttf rm -rf sazanami-20040629* yum -y install mysql-devel wget http://jaist.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz tar zxvf nagios-plugins-1.4.11.tar.gz cd nagios-plugins-1.4.11 ./configure && make && make install cp contrib/check_mem.pl /usr/local/nagios/libexec/
・メモリチェックプラグイン修正
$ vi /usr/local/nagios/libexec/check_mem.pl - $command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`; + $command_line = `free | head -3 | tail -1 | awk '{print \$3,\$4}'`;
・ひたすら実行
chmod +x /usr/local/nagios/libexec/check_mem.pl cd rm -rf nagios-plugins-1.4.11* mkdir /usr/local/nagios/etc/servers usermod -G nagios apache
・アラート通知先メールアドレス設定
$ vi /usr/local/nagios/etc/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 test@example.com + email yuki@sorauta.net }
・SSH,HTTP,MySQLの状態変化,メモリ使用量,ログインユーザ数を通知するように
$ vi /usr/local/nagios/etc/objects/localhost.cfg 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 } 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 } +define service{ + use generic-service + host_name localhost + service_description Memory Free + check_command check_mem!20!10 + } +define service{ + use generic-service + host_name localhost + service_description Current Users + check_command check_local_users!3!5 + } +define service{ + use generic-service + host_name localhost + service_description MySQL + check_command check_mysql!root!____root_password____ + }
※____root_password____の部分はmysqlのrootパスワードで置換
・メールの文字化け防止
$ vi /usr/local/nagios/etc/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$" | /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$" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } +# 'check_mem' command definition +define command{ + command_name check_mem + command_line $USER1$/check_mem.pl -f -w $ARG1$ -c $ARG2$ + } +# 'check_mysql' command definition +define command{ + command_name check_mysql + command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$ + }
・nagiosページのアクセス制限
$ vi /etc/httpd/conf.d/nagios.conf <Directory "/usr/local/nagios/sbin"> # SSLRequireSSL Options ExecCGI AllowOverride None Order allow,deny - Allow from all +# Allow from all # Order deny,allow -# Deny from all -# Allow from 127.0.0.1 + Deny from all + Allow from 127.0.0.1 + Allow from 192.168.1.0/24 AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory> <Directory "/usr/local/nagios/share"> # SSLRequireSSL Options None AllowOverride None Order allow,deny - Allow from all +# Allow from all # Order deny,allow -# Deny from all -# Allow from 127.0.0.1 + Deny from all + Allow from 127.0.0.1 + Allow from 192.168.1.0/24 AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory>
・Apache再起動
※組み込みのapacheの場合 /etc/init.d/httpd restart ※ソースから入れたapacheの場合 cp /etc/httpd/conf.d/nagios.conf /usr/local/apache2/conf/ /usr/local/apache2/bin/apachectl restart
・admin作成
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
・ひたすら実行
/etc/rc.d/init.d/nagios start chkconfig --add nagios chkconfig nagios on chmod 777 /usr/local/nagios/var/rw/nagios.cmd
以上!