2、编译
进入到解压目录执行
./configure --prefix=/usr/local/nagios
--with-nagios-user=nagios
--with-nagios-group=nagios
--with-command-group= nagios
make all
make install
make install-config
make install-init
nagios安装完成
3、创建访问nagios的认证用户
/usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd andy
按照提示设置密码。
Apache已经安装好 到目录/usr/local/apache/
4、将nagios的信息加到apache中,打开/usr/local/apache/conf/httpd.conf文件,在文件最后添加如下代码:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
Alias /nagios /usr/local/nagios/share
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
5、重启apache
访问nagios http://IP/nagios
6、插件安装
本文中用到的是 nagios-plugins-1.4.13.tar.gz
解压缩
Tar zxvf nagios-plugins-1.4.13.tar.gz
进入到解压缩目录nagios-plugins-1.4.13
编译
./configure –prefix=/usr/local/nagios #和nagios安装目录相同
安装
Make
Make install
7、nagios 具体配置
(一)
首先编辑/usr/local/nagios/etc/objects/localhost.cfg、我把要监控的主机都放在localhost.cfg文件中
================================================
定义要监控的主机 (oracle.test.com、CVS)
define host{
use linux-server
host_name oracle.test.com
alias Database
address 192.168.1.176
contact_groups admins
parents routergw
icon_image server.gif
statusmap_image server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
define host{
use linux-server
host_name CVS
alias CVS
address 192.168.1.183
contact_groups admins
parents routergw
icon_image server.gif
statusmap_image server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
================================================
定义主机组和服务组
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ; Comma separated list of hosts that belong to this group
}
define servicegroup{
servicegroup_name linuxserv
alias services
members oracle.test.com,SSH,oracle.test.com,PING,oracle.test.com,disk,CVS,PING,CVS,disk,CVS,SSH
}
================================================
定义要监控的服务
define service{
use local-service
host_name oracle.test.com,CVS
service_description PING
check_command check_ping!100.0,20%!500.0,60%
notifications_enabled 1
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service te
host_name oracle.test.com,CVS
service_description disk
check_command check_local_disk!20%!10%!/
notifications_enabled 1
}
define service{
use local-service
host_name oracle.test.com,CVS
service_description users
check_command check_local_users!20!50
notifications_enabled 1
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service
host_name oracle.test.com,CVS
service_description procs
check_command check_local_procs!250!400!RSZDT
notifications_enabled 1
}
# Define a service to check the load on the local machine.
define service{
use local-service
host_name oracle.test.com,CVS
service_description local_load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
notifications_enabled 1
# 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
host_name oracle.test.com,CVS
service_description SSH
check_command check_tcp!22!1.0!10.0
notifications_enabled 1
}
# 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
host_name oracle.test.com
service_description HTTP
check_command check_http
notifications_enabled 1
}
================================================
(二)编辑联系人/usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_commands notify-service-by-sms, notify-service-by-email
host_notification_commands notify-host-by-sms, notify-service-by-email