7、制作nagios访问权限管理密码文件
[root@nagios ~]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 
New password:  (kevin)
Re-type new password:  (kevin)
Adding password for user nagiosadmin 
这里添加用户nagiosadmin用户的原因是nagios所有相关的脚本执行用户就是默认的nagiosadmin,为了不麻烦这里就只是改一下nagiosadmin的密码就行了。具体可查看配置文件/usr/local/nagios/etc/cgi.cfg
重启apache服务
[root@nagios ~]#/usr/local/apache2/bin/apachectl stop 
[root@nagios ~]#/usr/local/apache2/bin/apachectl start 
OK,web页面配置好了,不过没有任何东西,nagios监控配置文件还没有的。
为了方便实验,安装一个nagios汉化插件吧
[root@nagios ~]# tar -jxvf nagios-cn-3.2.3.tar.bz2 
[root@nagios ~]# cd nagios-cn-3.2.3 
[root@nagios nagios-cn-3.2.3]# ./configure 
[root@nagios nagios-cn-3.2.3]# make all 
[root@nagios nagios-cn-3.2.3]# make install 
这只是一个汉化插件而已,前面的make install-init 配置启动脚本,make install-commandmode设定相关文件及目录的权限,make install-config安装相关配置文件,以及make install-webconf配置web页面的apache接口等都已经做好。如果再次执行将会替换之前在nagios目录的所有修改,所以这里只用安装汉化的web相关页面就行了
查看一下,汉化成功。
二、开始一个简单的本地监控实验吧
***涉及文件:
nagios.cfg nagios主配置文件
localhost.cfg 定义监控本地主机的配置文件
templates.cfg 定义主机和服务的一个模板配置文件
commands.cfg 定义命令配置文件,定义的命令可以被其他配置文件引用
hosts.cfg 新建的一个配置文件,为了好管理,只定义相关主机
services.cfg 新建的一个配置文件,为了好管理,只定义相关服务
***涉及定义:
主机,主机组;服务,服务组;联系人;监控命令等
***配置文件的关系:
定义主机、主机组、服务、服务组-->用什么命令曲实现监控目的-->定义监控时间段-->定义当主机或者服务出现问题时如何通知联系人
1、添加host
[root@nagios objects]# cp -p localhost.cfg hosts.cfg  (可以参考localhost.cfg进行配置)
[root@nagios objects]# cat hosts.cfg  (定义主机和主机组)
###############################################################################
define host{ 
use linux-server ; Name of host template to use 
host_name 本地监控主机 
alias nagios监控主机 
address 127.0.0.1 
} 
############################################################################### 
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 
} 
############################################################################### 
2、添加service
[root@nagios objects]# vim services.cfg  (编辑所监控的服务)
[root@nagios objects]# cat services.cfg  (所有的命令都可以在/usr/local/nagios/etc/objects/commands.cfg下查看)
# Define a service group. 
define servicegroup{ 
servicegroup_name 系统状况检查 
alias 系统概况 
}
# Define a service to "ping" the local machine
define service{ 
use local-service ; Name of service template to use 
host_name * ;对所有服务都启用ping检测 
service_groups 系统状况检查 
service_description PING 
check_command check_ping!100.0,20%!500.0,60% 
}
# 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 ; Name of service template to use 
host_name 本地监控主机 
service_groups 系统状况检查 
service_description 根分区 
check_command check_local_disk!20%!10%!/ 
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical 
# if > 50 users. 
define service{ 
use local-service ; Name of service template to use 
host_name 本地监控主机 
service_groups 系统状况检查 
service_description 登录用户数 
check_command check_local_users!20!50 
}
# 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 ; Name of service template to use 
host_name 本地监控主机 
service_groups 系统状况检查 
service_description 进程总数 
check_command check_local_procs!250!400!RSZDT 
}
# Define a service to check the load on the local machine.
define service{ 
use local-service ; Name of service template to use 
host_name 本地监控主机 
service_groups 系统状况检查 
service_description 系统负载 
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 
}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free 
define service{ 
use local-service ; Name of service template to use 
host_name 本地监控主机 
service_groups 系统状况检查 
service_description 交换空间利用率 
check_command check_local_swap!20!10 
}
3、修改nagos配置文件
[root@nagios objects]# vim ../nagios.cfg 
***加入这两行,并注释掉localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg 
cfg_file=/usr/local/nagios/etc/objects/servicess.cfg
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
4、检查配置文件的正确性
[root@nagios objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
.......
Total Warnings: 0 
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check 
5、好了,看来没什么问题,重启服务生效
[root@nagios etc]#service nagios restart 
Running configuration check...done. 
Stopping nagios: done. 
Starting nagios: done.  
(未决表明改完配置文件后还没有检测完的服务,等一会)
 
6、等待所有服务正常开启之后就来测试一下吧
[root@nagios ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all 
当ping不通了,会认为已经宕机。
