增加nagios账号
- #useradd nagios -s /sbin/nologin
安装nagios
- tar -zxvf nagios-2.9.tar.gz
- ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
- make all
- make install
- make install-commandmode
- make install-config
解释如下
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!
安装nagios-plugins
- tar -zxvf nagios-plugins-1.4.9.tar.gz
- cd nagios-plugins-1.4.9
- ./configure --prefix=/usr/local/nagios
- make
- make install
修改nagios目录属主
- chown -R nagios:nagios /usr/local/nagios
修改apache配置文件
- vi /usr/local/apache/conf/httpd.conf
#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/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
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/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
</Directory>
生成用户验证文件:
- /usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd sery
上述文本块的作用是对nagios的目录进行用户验证,只有合法的授权用户才可以访问nagios的页面文件。上述就会生成web的合法访问用户sery;命令交互执行,需要输入2次密码,然后就在文件/usr/local/nagios/etc/htpasswd 写入一行-第一个字段是刚生成的用户名,第二个是加密后的密码,如果还要添加更多的用户,执行命令 htpasswd 就不需要选项 “-c”,否则就会覆盖所有已经生成的行。
配置完成后,执行/usr/local/apache/bin/apachctl –t 检查apache配置文件是否有语法错误,无误后用/usr/local/apache/bin/apachctl start & 把apache启动,然后从另外的机器的浏览器输入nagios 的访问地址(如:http://ip/nagios),如果正常,将出现登录验证窗口等待用户输入
修改配置文件:
先把/usr/local/nagios/etc下的文件改名,如 cgi.cfg-sample改成cgi.cfg ,用命令cp cgi.cfg-sample cgi.cfg …依样把余下的几个*.cfg-sample都复制成*.cfg文件。从nagios2.6版开始,不用修改配置文件localhost.cfg就可以直 接运行../bin/nagios –v nagios.cfg验证程序是否能正常运行
Nagios的主配置文件是nagios.cfg,我们就从这个文件开始修改。
编辑nagios.cfg,
注释行 #cfg_file=/usr/local/nagios/etc/localhost.cfg
修改cgi.cfg
authorized_for_system_information=sery
authorized_for_configuration_information=sery
authorized_for_system_commands=sery
authorized_for_all_services=sery
authorized_for_all_hosts=sery
authorized_for_all_service_commands=sery
authorized_for_all_host_commands=sery
修改timeperiods.cfg文件
此文件只要用于定义监控的时间段,下面是一个配置好的实例:
#下面是定义一个名为24x7的时间段,即监控所有时间段
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
#下面是定义一个名为workhours的时间段,即工作时间段。
define timeperiod{
timeperiod_name workhours
alias Normal Work Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}