二、设置访问权限 1、在/usr/local/nagios/share目录下
vi .htaccess
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/.htpasswd
require valid-user
2、在/usr/local/nagios/sbin目录下
vi .htpasswd
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/.htpasswd
require valid-user
3、/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/.htpasswd nagios
这个apache目录根据安装目录的不同而不同,主要所以用.htpasswd这个命令生成用户名和密码
三、配置nagios 1、在/usr/local/nagios/etc下是nagios的配置模板文件.cfg-sample,把.cfg-sample文件全部拷贝成.cfg
例如:cp nagios.cfg-sample nagios.cfg
全部拷贝完成即可.
2、vi dependencies.cfg (在2.0没有生成这个文件,自己创建)
然后保存即可.(在1.2用一个空的文件代替原来的dependencies.cfg文件,否则会出错)
3、修改minimal.cfg,把里面所有定义command的全部注释掉
vi /etc/minimal.cfg
修改cgi.cfg
修改use_authentication=1为use_authentication=0,即不用验证.不然有一些页面不会显示。
4、然后检查配置文件是否出错
/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
出现Total Warnings: 0
Total Errors: 0
为正常
出错的话,就是.cfg文件有问题
5、启动后台进程
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
/usr/local/etc/rc.d/nagios start
6、http://yourip/nagios/index.html
(如果有些页面看不到的话.可以在cgi.cfg文件中
把带有authorized的选项前的#号去掉即可)
这些配置完以后,基本的nagios配置完成。
经验:nagios功能非常强大,但是配置也特别复杂。在部署nagios应用之前,一定要事先规划好;
哪些主机需要监视,都需要监视哪些服务,在监视中都采取哪些动作;而且要把他们条理
清楚的体现在cfg文件中,这样便于问题查找和扩充。
举几个cfg文件的例子。
hosts.cfg hostgroup.cfg service.cfg这三个配置文件对于简单的配置很重要,至于其他的配置文件,就要根据具体的应用来配置了。
Hosts.cfg
# 'novell1' host definition
define host{
use generic-host ; Name of host template to use
host_name 你想管理的机器名
alias 自己定义的别名
address 你想管理的机器的IP
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}
Hostgroup.cfg
# 'novell-servers' host group definition
define hostgroup{
hostgroup_name novell-servers
alias Novell Servers
contact_groups novell-admins
members 你想管理的机器名(可以用多个,中间用逗号分隔)
}
services.cfg
# Service definition
define service{
use generic-service ; Name of service template to use
host_name 你的机器名字
service_description SMTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 1
contact_groups novell-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_smtp
}
contacts.cfg misccommands.cfg dependencies.cfg
nagios.cfg dependencies.cfg.bak resource.cfg
cgi.cfg escalations.cfg checkcommands.cfg
hostgroups.cfg services.cfg contactgroups.cfg
hosts.cfg timeperiods.cfg
以上三个配置文件对于想管理的机器,需要去配置,不过对于你的机器加入在不同的组里面所监视的服务是不同的,不同工作组的计算机在nagios的管理软件界面中的服务是不一样的,如果想要更多的监视一台服务器,那么就需要配置services.cfg文件,灵活的更改services.cfg文件对于使用好 nagios非常的重要。
