Nagios是一款非常优秀的网络主机管理软件,它在开源社区的影响力是非同寻常的。但很可惜的是,它的界面及操作使用过程中采用了英语的语言提示与源程序紧密结合使得这款软件的汉化界面迟迟不能推出,影响了它在中文区的使用。为推进Nagios的使用,笔者建立了nagios-cn工程,该工程的主要目标是翻译源程序中运行提示、界面生成和文档说明,通过一些努力,nagios-cn终于可以正常运转了,本书编写的主要目的是为在中文使用区域推广和使用Nagios软件,让这款优秀的软件为国人服务。
1)建立一个帐号
[root@june src]# useradd nagios
创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
[root@june src]# groupadd nagcmd
[root@june src]#usermod -G nagcmd nagios
[root@june src]#usermod -G nagcmd apache
2)下载Nagios和插件程序包
[root@june src]# wget http://nagios-cn.googlecode.com/files/nagios-cn-3.1.0.tar.bz2 [root@june src]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz [root@june src]# tar xjfv nagios-cn-3.1.0.tar.bz2
3)编译与安装Nagios
展开Nagios源程序包
[root@june src]# tar xjfv nagios-cn-3.1.0.tar.bz2
运行Nagios配置脚本并使用先前开设的用户及用户组
[root@june src]# cd nagios-cn-3.1.0
[root@june nagios-cn-3.1.0]# ./configure –prefix=/usr/local/nagios/ –with-nagios-user=nagios –with-nagios-group=nagios –with-command-user=nagios –with-command-group=nagcmd
:
:
:
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
————————
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type ‘make all’ to compile the main program and CGIs.
[root@june nagios-cn-3.1.0]# make install
[root@june nagios-cn-3.1.0]# make install-init
[root@june nagios-cn-3.1.0]# make install-config
[root@june nagios-cn-3.1.0]# make install-commandmode
[root@june nagios-cn-3.1.0]# make install-webconf # 安装Nagios的WEB配置文件到Apache的conf.d目录下
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
Nagios/Apache conf file installed
创建一个jadeshow的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。
[root@june nagios-cn-3.1.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users jadeshow
New password:
Re-type new password:
Adding password for user jadeshow
重启http服务器
[root@june nagios-cn-3.1.0]# service httpd restart
停止 httpd: [确定]
启动 httpd:[Thu Jan 13 23:00:50 2011] [warn] The ScriptAlias directive in /etc/httpd/conf/httpd.conf at line 992 will probably never match because it overlaps an earlier ScriptAlias.
[Thu Jan 13 23:00:50 2011] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1003 will probably never match because it overlaps an earlier Alias.
[确定]
4)编译并安装Nagios插件
[root@june src]# gunzip nagios-plugins-1.4.15.tar.gz
[root@june src]# tar xvf nagios-plugins-1.4.15.tar
[root@june nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
[root@june nagios-plugins-1.4.15]# make
[root@june nagios-plugins-1.4.15]# make install
5)启动Nagios
把Nagios加入到服务列表中以使之在系统启动时自动启动
[root@june nagios-plugins-1.4.15]# chkconfig nagios –add
[root@june nagios-plugins-1.4.15]# chkconfig nagios on
验证Nagios的样例配置文件
[root@june nagios-cn-3.1.0]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios 3.1.0
Copyright (c) 1999-2009 Ethan Galstad (http://www.nagios.org)
Last Modified: 01-25-2009
License: GPL
Reading configuration data…
Read main config file okay…
Processing object config file ‘/usr/local/nagios//etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/localhost.cfg’…
Read object config files okay…
Running pre-flight check on configuration data…
Checking services…
Checked 18 services.
Checking hosts…
Checked 11 hosts.
Checking host groups…
Checked 2 host groups.
Checking service groups…
Checked 2 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 24 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[root@june nagios-cn-3.1.0]#
启动nagios
[root@june nagios-cn-3.1.0]# service nagios start
Starting nagios: done.
[root@june nagios-cn-3.1.0]#
6)登录WEB接口

7)登录排错
当登录之后出现无法解析,查看apache日志有如下错误
Thu Jan 13 23:34:29 2011] [error] [client 192.168.0.111] access to /nagios failed, reason: verification of user id ‘nagiosadmin’ not configured
access to /nagios failed, reason: verification of user id ‘jadeshow’ not configured
查看htpasswd 确实存在文件
[root@june etc]# vim htpasswd.users
1 jadeshow:b8ekEY0SUW1Zo
查看apache的配置文件
[root@june etc]# vim /etc/httpd/conf/httpd.conf
992 ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
993 <Directory “/usr/local/nagios/sbin”>
:
:
391 DirectoryIndex index.html index.html.var index.php
:
AuthUserFile /usr/local/nagios/etc/htpasswd
而nagios下的认证文件为htpasswd.users
[root@june etc]# ll
总计 72
-rw-rw-r– 1 nagios nagios 11364 01-13 22:56 cgi.cfg
-rw-r–r– 1 nagios nagios 23 01-13 23:40 htpasswd.users
-rw-rw-r– 1 nagios nagios 44109 01-13 22:56 nagios.cfg
-rw-rw-r– 1 nagios nagios 2242 01-13 22:56 nagiosgraph.cfg
drwxrwxr-x 2 nagios nagios 4096 01-13 22:56 objects
-rw-rw—- 1 nagio
修改两个文件其中的一个,
[root@june etc]# htpasswd -c /usr/local/nagios/etc/htpasswd jadeshow
New password:
Re-type new password:
Adding password for user jadeshow
[root@june etc]# service httpd restart
登录成功

查看etc目录下的权限
[root@june etc]# ll
总计 76
-rw-rw-r– 1 nagios nagios 11364 01-13 22:56 cgi.cfg
-rw-r–r– 1 root root 23 01-13 23:46 htpasswd
-rw-r–r– 1 nagios nagios 23 01-13 23:40 htpasswd.users
-rw-rw-r– 1 nagios nagios 44109 01-13 22:56 nagios.cfg
-rw-rw-r– 1 nagios nagios 2242 01-13 22:56 nagiosgraph.cfg
drwxrwxr-x 2 nagios nagios 4096 01-13 22:56 objects
-rw-rw—- 1 nagios nagios 1342 01-13 22:56 resource.cfg
赫然发现htpasswd的属主是root,修改目录属性,
再次重启,仍然不行,查看cgi配置文件发现;
authorized_for_all_services=nagiosadmin
而我用的是jadeshow做的认证用户,所以需要添加jadeshow的用户至配置文件,此时可以读取主机信息

1)建立一个帐号
[root@june src]# useradd nagios
创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
[root@june src]# groupadd nagcmd
[root@june src]#usermod -G nagcmd nagios
[root@june src]#usermod -G nagcmd apache
2)下载Nagios和插件程序包
[root@june src]# wget http://nagios-cn.googlecode.com/files/nagios-cn-3.1.0.tar.bz2 [root@june src]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz [root@june src]# tar xjfv nagios-cn-3.1.0.tar.bz2
3)编译与安装Nagios
展开Nagios源程序包
[root@june src]# tar xjfv nagios-cn-3.1.0.tar.bz2
运行Nagios配置脚本并使用先前开设的用户及用户组
[root@june src]# cd nagios-cn-3.1.0
[root@june nagios-cn-3.1.0]# ./configure –prefix=/usr/local/nagios/ –with-nagios-user=nagios –with-nagios-group=nagios –with-command-user=nagios –with-command-group=nagcmd
:
:
:
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
————————
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type ‘make all’ to compile the main program and CGIs.
[root@june nagios-cn-3.1.0]# make install
[root@june nagios-cn-3.1.0]# make install-init
[root@june nagios-cn-3.1.0]# make install-config
[root@june nagios-cn-3.1.0]# make install-commandmode
[root@june nagios-cn-3.1.0]# make install-webconf # 安装Nagios的WEB配置文件到Apache的conf.d目录下
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
Nagios/Apache conf file installed
创建一个jadeshow的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。
[root@june nagios-cn-3.1.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users jadeshow
New password:
Re-type new password:
Adding password for user jadeshow
重启http服务器
[root@june nagios-cn-3.1.0]# service httpd restart
停止 httpd: [确定]
启动 httpd:[Thu Jan 13 23:00:50 2011] [warn] The ScriptAlias directive in /etc/httpd/conf/httpd.conf at line 992 will probably never match because it overlaps an earlier ScriptAlias.
[Thu Jan 13 23:00:50 2011] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1003 will probably never match because it overlaps an earlier Alias.
[确定]
4)编译并安装Nagios插件
[root@june src]# gunzip nagios-plugins-1.4.15.tar.gz
[root@june src]# tar xvf nagios-plugins-1.4.15.tar
[root@june nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
[root@june nagios-plugins-1.4.15]# make
[root@june nagios-plugins-1.4.15]# make install
5)启动Nagios
把Nagios加入到服务列表中以使之在系统启动时自动启动
[root@june nagios-plugins-1.4.15]# chkconfig nagios –add
[root@june nagios-plugins-1.4.15]# chkconfig nagios on
验证Nagios的样例配置文件
[root@june nagios-cn-3.1.0]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios 3.1.0
Copyright (c) 1999-2009 Ethan Galstad (http://www.nagios.org)
Last Modified: 01-25-2009
License: GPL
Reading configuration data…
Read main config file okay…
Processing object config file ‘/usr/local/nagios//etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios//etc/objects/localhost.cfg’…
Read object config files okay…
Running pre-flight check on configuration data…
Checking services…
Checked 18 services.
Checking hosts…
Checked 11 hosts.
Checking host groups…
Checked 2 host groups.
Checking service groups…
Checked 2 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 24 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[root@june nagios-cn-3.1.0]#
启动nagios
[root@june nagios-cn-3.1.0]# service nagios start
Starting nagios: done.
[root@june nagios-cn-3.1.0]#
6)登录WEB接口

7)登录排错
当登录之后出现无法解析,查看apache日志有如下错误
Thu Jan 13 23:34:29 2011] [error] [client 192.168.0.111] access to /nagios failed, reason: verification of user id ‘nagiosadmin’ not configured
access to /nagios failed, reason: verification of user id ‘jadeshow’ not configured
查看htpasswd 确实存在文件
[root@june etc]# vim htpasswd.users
1 jadeshow:b8ekEY0SUW1Zo
查看apache的配置文件
[root@june etc]# vim /etc/httpd/conf/httpd.conf
992 ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
993 <Directory “/usr/local/nagios/sbin”>
:
:
391 DirectoryIndex index.html index.html.var index.php
:
AuthUserFile /usr/local/nagios/etc/htpasswd
而nagios下的认证文件为htpasswd.users
[root@june etc]# ll
总计 72
-rw-rw-r– 1 nagios nagios 11364 01-13 22:56 cgi.cfg
-rw-r–r– 1 nagios nagios 23 01-13 23:40 htpasswd.users
-rw-rw-r– 1 nagios nagios 44109 01-13 22:56 nagios.cfg
-rw-rw-r– 1 nagios nagios 2242 01-13 22:56 nagiosgraph.cfg
drwxrwxr-x 2 nagios nagios 4096 01-13 22:56 objects
-rw-rw—- 1 nagio
修改两个文件其中的一个,
[root@june etc]# htpasswd -c /usr/local/nagios/etc/htpasswd jadeshow
New password:
Re-type new password:
Adding password for user jadeshow
[root@june etc]# service httpd restart
登录成功

查看etc目录下的权限
[root@june etc]# ll
总计 76
-rw-rw-r– 1 nagios nagios 11364 01-13 22:56 cgi.cfg
-rw-r–r– 1 root root 23 01-13 23:46 htpasswd
-rw-r–r– 1 nagios nagios 23 01-13 23:40 htpasswd.users
-rw-rw-r– 1 nagios nagios 44109 01-13 22:56 nagios.cfg
-rw-rw-r– 1 nagios nagios 2242 01-13 22:56 nagiosgraph.cfg
drwxrwxr-x 2 nagios nagios 4096 01-13 22:56 objects
-rw-rw—- 1 nagios nagios 1342 01-13 22:56 resource.cfg
赫然发现htpasswd的属主是root,修改目录属性,
再次重启,仍然不行,查看cgi配置文件发现;
authorized_for_all_services=nagiosadmin
而我用的是jadeshow做的认证用户,所以需要添加jadeshow的用户至配置文件,此时可以读取主机信息
