3,安装nagios主程序包
# tar xf nagios-4.0.5.tar.gz -C /usr/src/
# cd /usr/src/nagios-4.0.5/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# make install-exfoliation
# make install-classicui
make install
- This installs the main program, CGIs, and HTML files
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme for the Nagios
web interface
# ls /usr/local/nagios/
bin etc libexec sbin share var
--libexec目录为空,需要安装插件包才会有很多命令与脚本
4,安装nagios插件包 --包含用于收集数据的程序,命令,脚本等
# tar xf nagios-plugins-2.0.3.tar.gz -C /usr/src/
# cd /usr/src/nagios-plugins-2.0.3/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make ;make install
5。创建web界面可访问的验证用户
/etc/httpd/conf.d/nagios.conf --在这个文件里已经配置了nagios的apache验证,所以我们要把用户给创建出来
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin --这里注意一下,用户名一定要用nagiosadmin,如果你用其它自定义的用户名,可以通过apache的验证,但是查看nagios数据时,会没有权限查看到数据
New password:
Re-type new password:
Adding password for user nagiosadmin
==================================================
现在查看web界面,默认只监控了localhost,并监控了其8个服务
一些小操作:
1,如果http服务为黄色,是警告,则需要把网站家目录里加一个主页进去(家目录为空,他就会警告)。
但需要等它下一次check才会OK。如果要手动check,可以点http,再右边点Re-schedule the next check of this service去强制check,就OK了
2,默认http和ssh是关闭通知的,是因为在localhost.cfg里这两个服务有一句 notifications_enabled 0。
也可以手动打开,点进去,再右边点enabled notifications for this service.
3,关闭ssh服务,刷新web界面,还是没有critical.
点击ssh,可以看到下一次计划的check时间。如果不等的话,在右边点Re-schedule the next check of this service强制check,再刷新就critical
4,修改ssh的check时间间隔
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service --使用的这个模版,所以要去改这个模版里的时间
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# vim /usr/local/nagios/etc/objects/templates.cfg
define service{
name local-service
.............
normal_check_interval 1 --把这个五分钟改为1分钟
.............
}
--直接使用监控命令去手工check一下,OK的
# /usr/local/nagios/libexec/check_ftp -w 1 -c 3 -p 2121
FTP OK - 0.004 second response time on port 2121 [220-#############################
220-#]|time=0.003835s;1.000000;3.000000;0.000000;10.000000
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service
host_name localhost
service_description MYSQL
check_command check_mysql!root!123
}
1,在nagios服务器上安装nrpe插件
# tar xf nrpe-2.12.tar.gz -C /usr/src/
# cd /usr/src/nrpe-2.12/
# ./configure && make && make install
--安装完后,就有下面的命令工具了
/usr/local/nagios/libexec/check_nrpe
2,安装plugins插件,包含了数据采集命令脚本
# tar xf nagios-plugins-2.0.3.tar.gz -C /usr/src/
# cd /usr/src/nagios-plugins-2.0.3/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make && make install
3,安装nrpe
# tar xf nrpe-2.12.tar.gz -C /usr/src/
# cd /usr/src/nrpe-2.12/
# ./configure && make && make install
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
4,修改nrpe的超级守护进程的配置文件
# vim /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 10.1.1.35 --加上nagios服务器的IP,允许它来访问
}
# vim /etc/services --最后面加一行
nrpe 5666/tcp # NRPE
5,在nrpe配置文件里定义check命令,使nagios服务能调用
# vim /usr/local/nagios/etc/nrpe.cfg
# vim /usr/local/nagios/etc/objects/templates.cfg --加上下面的模版
define service {
name nagiosgraph
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
register 0
}
# vim /usr/local/nagios/etc/objects/localhost.cfg --在你所有的要加图形的监控主机里的服务的use后加上nagiosgraph模版,如下
define service{
use local-service,nagiosgraph
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}