二、安装nagios
1)建立nagios用户
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
2)编译安装nagios
tar -zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios/
make all
make install
make install-init
make install-commandmode
make install-config
chkconfig --add nagios
chkconfig nagios on
chkconfig --list nagios
3)安装nagios-plugins
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --prefix=/usr/local/nagios/
make && make install
4)安装汉化包
tar -jxvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure && make all && make install
三,配置
1)配置httpd添加授权
vim /etc/httpd/conf/httpd.conf 最后加入
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
Alias /nagios "/usr/local/nagios/share"
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
2)生成密码
# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for user nagiosadmin
#这里为方便就用了nagiosadmin这个用户,如果用其他用户访问时要在/usr/local/nagios/etc/cgi.cfg里将nagiosadmin后面加上相应的用户即可
# service nagios start 启动
3)配置nagios
# vim /usr/local/nagios/etc/objects/hosts.cfg /添加要监控的主机,默认这个文件没有的。
define host{
use linux-server
host_name peace-nagios
alias nagios
address 192.168.10.246
}
define host{
use linux-server
host_name client-173
alias peace-client
address 192.168.10.173
}
define host{
use linux-server
host_name client-206
alias client
address 192.168.10.206
}
# vim /usr/local/nagios/etc/objects/services.cfg /定义监控主机的服务,默认也是没有的
############################ peace-nagios ##############################
define service {
use local-service
host_name peace-nagios
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service {
use local-service
host_name peace-nagios
service_description SSH
check_command check_tcp!12321
}
define service {
use local-service
host_name peace-nagios
service_description http
check_command check_http
}
############################ client-173 ##############################
define service {
use local-service
host_name client-173
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service {
use local-service
host_name client-173
service_description SSH
check_command check_ssh
}
define service {
use local-service
host_name client-173
service_description http
check_command check_http
}
############################ client-206 ##############################
define service {
use local-service
host_name client-206
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service {
use local-service
host_name client-206
service_description SSH
check_command check_ssh
}
define service {
use local-service
host_name client-206
service_description http
check_command check_http
}
# chown nagios.nagios hosts.cfg services.cfg /添加用户组
# vim /usr/local/nagios/etc/nagios.cfg /添加刚定义的两个文件
cfg_file=/usr/local/nagios//etc/objects/hosts.cfg
cfg_file=/usr/local/nagios//etc/objects/services.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
Checking services...
Checked 9 services.
Checking hosts...
Checked 3 hosts.
Checking host groups...
Checked 0 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
# service nagios restart
四、PNP(小太阳)
1)安装rrdtool需要的环境
#yum -y install cairo-devel libxml2-devel pango pango-devel
2)安装rrdtool
#tar zxvf rrdtool-1.4.4.tar.gz
#cd rrdtool-1.4.4
#./configure --prefix=/usr/local/rrdtool
#make && make install
3)安装pnp
tar -zxvf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
make all
make install
make install-config
make install-init
4)配置pnp
cd /usr/local/nagios/etc/pnp/
cp process_perfdata.cfg-sample process_perfdata.cfg
cp npcd.cfg-sample npcd.cfg
cp rra.cfg-sample rra.cfg
chown -R nagios.nagios /usr/local/nagios/etc/pnp/
5)修改process_perfdata.cfg文件
# vim /usr/local/nagios/etc/pnp/process_perfdata.cfg
40 LOG_FILE = /usr/local/nagios/var/perfdata.log
41 #
42 # Loglevel 0=silent 1=normal 2=debug
43 #
44 LOG_LEVEL = 2 /改成2 也就是debug模式
6)修改nagios,增加图标
# vim /usr/local/nagios/etc/objects/templates.cfg /添加
define host{
name hosts-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
process_perf_data
}
define service{
name services-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data
}
# vim /usr/local/nagios/etc/nagios.cfg /找到下面几行,去# 修改后如下:
833 process_performance_data=1
845 host_perfdata_command=process-host-perfdata
846 service_perfdata_command=process-service-perfdata
# vim /usr/local/nagios/etc/objects/commands.cfg /找到下面的内容,修改如下
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# vim /usr/local/nagios/etc/objects/hosts.cfg /在每个use 后都添加添加services-pnp,如下
define host{
use linux-server,hosts-pnp
host_name peace-nagios
alias nagios
address 192.168.10.246
}
……
# vim /usr/local/nagios/etc/objects/services.cfg /在每个use 后都添加添加services-pnp,如下
define service {
use local-service,services-pnp
host_name peace-nagios
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
……
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /检测没有问题重新启动nagios
# service nagios restart
五、nrpe
1)被监控端
useradd -s /sbin/nologin nagios
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure
make && make install
chown nagios.nagios /usr/local/nagios/
chown -R nagios.nagios /usr/local/nagios/libexec/
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure && make all && make install-plugin && make instal-daemon && make install-daemon-config
make install-daemon
make install-daemon-config
# vim /usr/local/nagios/etc/nrpe.cfg /编辑nrpe,定义命令
allowed_hosts=192.168.10.246,127.0.0.1
# The following examples use hardcoded command arguments...