CentOS5.5
nagios-3.2.3.tar.gz
nagios-plugins-1.4.15.tar.gz
nrpe-2.12.tar.gz
1.环境安装
#yum install –y httpd php gcc glibc glibc-common gd gd-devel
2.下载nagios-3.2.3.tar.gz nagios-plugins-1.4.15.tar.gz nrpe-2.12.tar.gz到如下目录
#mkdir nagios-install
#cd nagios-install
3.添加nagios账号
#useradd -m nagios
#passwd nagios
#groupadd nagcmd
#usermod –a –G nagcmd nagios
#usermod –a –G nagcmd apache
4.安装nagios-3.2.3.tar.gz
#tar –zxvf nagios-3.2.3.tar.gz
#cd nagios-3.2.3
#./configure --with-command-group=nagcmd
#make all
#make install-init
#make install-config
#make install-commandmode
#chkconfig --add nagios
#chkconfig nagios on
5.配置WEB访问
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#service httpd restart
6.安装nagios-plugins-1.4.15.tar.gz
#tar –zxvf nagios-plugins-1.4.15.tar.gz
#cd nagios-plugins-1.4.15
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make && make install
7.配置报警短信发送程序
# vi /usr/local/bin/sms_send.pl
#!/usr/bin/perl
use strict;
use LWP::Simple;
use URL::Escape;
use Digest::MD5;
my($mobile,$content)=@ARGV;
my $log_control=1;
my $key='mingdaoit';
my $souce_content=substr($mobile,0,8).substr($mobile,-10,10);
#my $md5=Digest::MD5->new;
#$md5->add($souce_content);
#my $result_conent=uc($md5->hexdigest);
my $url = "http://192.168.15.125:88/sms?mobile=$mobile&content=$content";
my $result = get $url;
if($log_control){
my $fh;
open($fh,'>>/var/log/sms.log')or die"can't open log:$!";
print $fh join('',time,$result,"/n");
close $fh;
}
安装上面的Pear 插件
#perl -MCPAN -e shell
cpan> install Digest::MD5
cpan> install URI::URL
cpan> install LWP::Simple
cpan>exit
测试是否可以发送短信
# /usr/local/bin/sms_send.pl 13458888888 "it is a test for nagios"
为了测试短信机是否正常,调用计划任务每天下午4点发送一条短信
#vi /etc/crontab
00 16 * * * /usr/local/bin/sms_send.pl 13458888888 "It is OK"
8.修改nagios.cfg
# vi /usr/local/nagios/etc/nagios.cfg
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg(注释掉这一行)
如下添加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
9.修改commands.cfg
# vi /usr/local/nagios/etc/objects/commands.cfg
添加
#host-notify-by-sms command definition
define command {
command_name host-notify-by-sms
command_line /usr/local/bin/sms_send.pl $CONTACTPAGER$ "$NOTIFICATIONTYPE$ alert -Host $HOSTNAMES$ is $HOSTSTATE$"
}
#service-notify-by-sms command definition
define command {
command_name service-notify-by-sms
command_line /usr/local/bin/sms_send.pl $CONTACTPAGER$ "$NOTIFICATIONTYPE$:$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
修改
# 'notify-host-by-email' command definition
command_name 为 host-notify-by-email
# 'notify-service-by-email' command definition
command_name 为 service-notify-by-email
新建相关配置文件
# vi /usr/local/nagios/etc/objects/hosts.cfg
define host {
host_name nagios-server
alias nagios server
address 192.168.15.125
contact_groups sagroup
check_command check-host-alive
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
# vi /usr/local/nagios/etc/objects/hostgroups.cfg
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members nagios-server
}
# vi /usr/local/nagios/etc/objects/contacts.cfg
define contact {
contact_name nagiosadmin
alias system administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands service-notify-by-email,service-notify-by-sms
host_notification_commands host-notify-by-email,host-notify-by-sms
email xxx@xxx.com
pager 1345888888
}
# vi /usr/local/nagios/etc/objects/contactgroups.cfg
define contactgroup {
contactgroup_name sagroup
alias system administrator group
members nagiosadmin
}
# vi /usr/local/nagios/etc/objects/services.cfg
efine service {
host_name nagios-server
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive
}
define service {
host_name nagios-server
service_description check_tcp 80
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80
}
define service{
host_name nagios-server
service_description check-disk
check_command check_nrpe!check_df
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
define service{
host_name nagios-server
service_description check-load
check_command check_nrpe!check_load
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
define service{
host_name nagios-server
service_description total_procs
check_command check_nrpe!check_total_procs
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
安装配置NRPE
#tar –zxvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#make install-xinetd
#cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec
#cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec
#cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec
#cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec
#cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec
#vi /usr/local/nrpe/etc/nrpe.cfg
server_address=192.168.15.125
allowed_hosts=127.0.0.1,192.168.15.125
#command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20 -c 10
以独立守护进程启动NRPE服务
#/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
# vi /etc/rc.local 添加
/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
#vi /etc/xinetd.d/nrpe
only_from=192.168.15.125
#vi /etc/services
nrpe 5666/ctp #NRPE
#chkconfig xinetd on
#service xinetd restart
[root@nagios etc]# netstat -an |grep tcp
tcp 0 0 192.168.15.125:5666 0.0.0.0:* LISTEN
# /usr/local/nagios/libexec/check_nrpe -H 192.168.15.125
NRPE v2.12
#vi /usr/local/nagios/etc/objects/command.cfg
添加
############################################################################### # NRPE CHECK COMMAND # # Command to use NRPE to check remote host systems ############################################################################### define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
检查nagios配置
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#service nagios restart
监控本机完成
相关链接
http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
http://www.kernelhardware.org/nagios-nrpe-to-monitor-remote-linux-server/
http://www.livejournal.com/doc/server/lj.install.perl_setup.modules.html