[root@KCentOS5C ~]# yum install httpd*
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd i386 2.2.3-6.el5.centos.1 base 1.1 M
httpd-devel i386 2.2.3-6.el5.centos.1 base 145 k
httpd-manual i386 2.2.3-6.el5.centos.1 base 830 k
Installing for dependencies:
apr-devel i386 1.2.7-11 base 237 k
apr-util-devel i386 1.2.7-6 base 54 k
=============================================================================
[root@KCentOS5C ~]# chkconfig httpd on
添加Nagios系统用户和同名组:
[root@KCentOS5C ~]# useradd nagios
准备好Nagios的源代码包:
[root@KCentOS5C ~]# ll
total 3712
-rw------- 1 root root 928 Oct 3 10:33 anaconda-ks.cfg
-rw-r--r-- 1 root root 22760 Oct 3 10:33 install.log
-rw-r--r-- 1 root root 2888 Oct 3 10:33 install.log.syslog
-rw-r--r-- 1 root root 1738698 Sep 30 22:42 nagios-2.9.tar.gz
这个就是Nagios主程序的源代码包
-rw-r--r-- 1 root root 1693979 Sep 30 22:51 nagios-plugins-1.4.10.tar.gz
这个是Nagios-plugin插件程序源代码包
1.解压缩Nagios主程序源代码包
[root@KCentOS5C ~]# tar -zxvf nagios-2.9.tar.gz
2.进入Nagios主程序包的解压目录
[root@KCentOS5C ~]# cd nagios-2.9
[root@KCentOS5C nagios-2.9]# ./configure --prefix=/usr/local/nagios
预配置成功后将返回配置环境信息
----------------------------------------------------
*** Configuration summary for nagios 2.9 04-10-2007 ***:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Init directory: /etc/rc.d/init.d
Host OS: linux-gnu
------------------------
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.
请注意看最后的提示,如果对以上反馈信息接受的话,则需要继续执行“make all”命令来编译主程序以及CGI。
-----------------------------------------------------
4.编译Nagios主程序
[root@KCentOS5C nagios-2.9]# make all
Nagios主程序编译成功后将返回信息
-----------------------------------------------------
*** Compile finished ***
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
如果在编译当中没有发生错误的话,那么可以照以下这些命令继续操作。
- This installs the main program, CGIs, and HTML files
执行“make install”命令来对主程序,CGI以及HTML网页进行安装。
- This installs the init script in /etc/rc.d/init.d
执行“install-init”命令来在/etc/rc.d/init.d/目录中安装启动脚本。
- This installs and configures permissions on the
directory for holding the external command file
执行“install-commandmode”命令来安装和配置外部命令对Nagios主路径操作的权限。(这里所谓的外部命令主要是指Apache服务通过CGI来对Nagios的进行的操作。用户将通过Web以执行CGI程序脚本的方式来对Nagios的检测结果进行读取和调用。)
- 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!
执行“make install-config”命令将会在/usr/local/etc/这个Nagios编译安装的主配置路径下安装示例配置模板,这将对于之后的配置制定帮助很大。
这些关于支持的信息就不再详细讲了
please make sure that you:
- Read the HTML documentation
- Read the FAQs online at http://www.nagios.org/faqs
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
-----------------------------------------------------
5.安装Nagios主程序、CGI以及网页
[root@KCentOS5C nagios-2.9]# make install
安装完Nagios主程序、CGI和网页的之后将提示安装成功信息以及剩余可操作的步骤
-----------------------------------------------------
*** Main program, CGIs and HTML files installed ***
without any arguments for a list of all possible options):
- This installs the init script in /etc/rc.d/init.d
- This installs and configures permissions on the
directory for holding the external command file
- 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!
-----------------------------------------------------
6.安装Nagios的系统启动脚本
[root@KCentOS5C nagios-2.9]# make install-init
安装完Nagios的系统启动脚本之后将提示脚本安装成功信息以及剩余可操作的步骤
-----------------------------------------------------
*** Init script installed ***
without any arguments for a list of all possible options):
- This installs and configures permissions on the
directory for holding the external command file
- 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!
-----------------------------------------------------
7.将Nagios的启动脚本添加到系统服务当中去
[root@KCentOS5C ~]# chkconfig --add nagios
[root@KCentOS5C ~]# chkconfig nagios on
[root@KCentOS5C nagios-2.9]# make install-commandmode
安装配置外操作权限后将提示配置成功信息以及剩余可操作步骤
-----------------------------------------------------
*** External command directory configured ***
without any arguments for a list of all possible options):
- 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!
-----------------------------------------------------
10.将Apache服务宿主用户加到nagios组里面
这样做是为了让Apache有适当的权限能够通过CGI脚本程序对Nagios进行调用,否则Apache将没有权限调用Nagios,用户通过Web将无法访问Nagios处理的所有信息。
[root@KCentOS5C nagios-2.9]# usermod -G nagios apache
11.安装Nagios的配置模板
[root@KCentOS5C nagios-2.9]# make install-config
安装完毕Nagios的配置模板后将反馈安装成功的提示信息。
-----------------------------------------------------
*** Sample config file installed ***
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
- Look at the sample config files
- Read the HTML documentation
- Read the FAQs online at http://www.nagios.org/faqs
*BEFORE* you post a question to one of the mailing lists.
-----------------------------------------------------
1.解压缩Nagios-plugins插件源代码包
[root@KCentOS5C ~]# tar -zxvf nagios-plugins-1.4.10.tar.gz
[root@KCentOS5C ~]# cd nagios-plugins-1.4.10
[root@KCentOS5C nagios-plugins-1.4.10]# ./configure --prefix=/usr/local/nagios/
预配置完成的话将会建立Makefile并反馈检测系统环境的结果。
-----------------------------------------------------
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
-----------------------------------------------------
[root@KCentOS5C nagios-plugins-1.4.10]# make
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct 5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct 5 19:03 etc
drwxr-xr-x 2 root root 4096 Oct 5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct 5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct 5 19:07 share
drwxrwxr-x 4 nagios nagios 4096 Oct 5 19:08 var
1.备份Apache服务的主配置文件
[root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup
[root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
这里主要改动以下这些参数:
-----------------------------------------------------
ServerName *:80
-----------------------------------------------------
3.察看Nagios网页配置模板文件
[root@KCentOS5C ~]# less nagios-2.9/sample-config/httpd.conf
-----------------------------------------------------
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
-----------------------------------------------------
基本上这个文件可以直接使用。根据这个配置文件中指定的AuthUserFile项,它指定的是通过Apache访问Nagios的合法用户的帐户名单库文件,需要使用htpasswd命令对这个名单库进行用户的添加。而默认安装环境下在/usr/local/nagios/etc/目录下是没有htpasswd.user这个文件的,所以需要手动添加。请特别注意,用root身份建立的htpasswd.user文件的权限问题,应该在建立该文件完毕后立即更改为nagios用户nagios组的所有权,并且要增加Nagios同组用户读写权限。
4.整合Nagios网页配置文件到Apache中
将Nagios网页配置文件作为Apache的扩展配置文件复制改名到Apache的扩展配置文件目录/etc/httpd/conf.d/目录下
[root@KCentOS5C ~]# cp nagios-2.9/sample-config/httpd.conf /etc/httpd/conf.d/nagios-httpd.conf
[root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user
[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.users
[root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.users
[root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.users
-rw-rw-r-- 1 nagios nagios 0 Oct 5 14:05 /usr/local/nagios/etc/htpasswd.users
我添加了一个kanecruise用户,口令是123456。
[root@KCentOS5C ~]# htpasswd -m /usr/local/nagios/etc/htpasswd.user kanecruise
------------------------------------------------------------
New password: 123456
Re-type new password: 123456
Adding password for user kanecruise
------------------------------------------------------------
10.察看htpasswd的使用方法,这里我就解释一些比较重要和常用的。
[root@KCentOS5C ~]# htpasswd
-------------------------------------------------------------
Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
建立新的帐户库文件。
添加一个MD5口令加密的新用户。
添加一个口令不加密的新用户。
添加一个SHA口令加密的新用户。
删除一个指定的用户
在Windows、NetWare以及TPF这些操作系统中“-m”参数(启用MD5对口令加密)是默认使用的
On all other systems, the '-p' flag will probably not work.
在其他的所有操作系统中“-p”(不对口令启用加密)参数将可能会引起失败。
-------------------------------------------------------------
11.检查htpasswd帐户文件
[root@KCentOS5C ~]# cat /usr/local/nagios/etc/htpasswd.users
-------------------------------------------------------------
kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1
-------------------------------------------------------------
用户添加正确,并且口令都以MD5的方式加密了。
默认下Nagios编译安装后都没有现成的配置文件,它们都以模板配置文件的方式在/usr/local/nagios/etc/这个主配置路径下,需要手动复制并配置成可用的配置文件。
Nagios的主配置文件为nagios.cfg。
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/nagios.cfg-sample /usr/local/nagios/etc/nagios.cfg
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/nagios.cfg
主要修改和确认以下几个较重要的配置项,其余的类似优化涉及到的配置调整这里暂不交待了。这次不像上回我用RPM包安装Nagios那次的配置方式,这次我打算将所有Nagios功能定义配置都集中在localhost.cfg这一个文件当中去,而命令定义文件commands.cfg独立保存一个文件,因此除了这两个文件不注释外,其他的Nagios功能定义文件都保持注释状态。
-------------------------------------------------------------
log_file=/usr/local/nagios/var/nagios.log
确认Nagios服务的日志记录文件,需要确认此项是解注状态的。默认编译安装后没有该文件,要手动添加并指定适当的读写权限。
在Nagios中将对应功能插件定义成命令的命令定义文件,需要确认此项是解注状态的。默认编译安装后也没有该文件,需要从模版复制。
设定Naigos对象功能定义的配置文件,需要确认此项是解注状态的。默认编译安装后也没有该文件,需要从模版复制。
#cfg_file=/usr/local/nagios/etc/contacts.cfg
#cfg_file=/usr/local/nagios/etc/dependencies.cfg
#cfg_file=/usr/local/nagios/etc/escalations.cfg
#cfg_file=/usr/local/nagios/etc/hostgroups.cfg
#cfg_file=/usr/local/nagios/etc/hosts.cfg
#cfg_file=/usr/local/nagios/etc/services.cfg
#cfg_file=/usr/local/nagios/etc/timeperiods.cfg
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
以上这些分块功能的定义配置文件需要保持注释,因为这些文件的作用都已经集中到localhost.cfg这一个文件当中去了。
nagios_group=nagios
设定Nagios服务的宿主用户和组。
check_external_commands=1
设定Nagios外部检查命令功能开关,默认是值0。将原来的注释掉,更改为值1,必须要打开该功能,否则CGI将不能调用。
#command_check_interval=-1
设定命令检查的时间间隔,将原来值-1的项注释掉,启用原来备用值为15s(15秒)。这项的时间间隔值请按实际需求情况设定。
-------------------------------------------------------------
[root@KCentOS5C ~]# touch /usr/local/nagios/var/nagios.log
改变Nagios主日志文件的属主。
添加同组成员的读写权限。
查看日志文件的属性。
-rw-rw-r-- 1 nagios nagios 0 Oct 5 15:28 /usr/local/nagios/var/nagios.log
3.处理Nagios的CGI配置文件:
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/cgi.cfg-sample /usr/local/nagios/etc/cgi.cfg
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/cgi.cfg
这里主要注意关于访问用户身份验证的配置项的设定。Nagios系统将各种操作行为的授权用户分的非常的仔细,所以在实际应用当中可以分的非常细,什么用户可以做哪些操作而哪些用户又没有权限做哪些操作。但是这里我只简单的授权给同一个用户。请特别注意,这里的授权用户的对象必须只能够是在htpasswd中添加注册过的用户。
-------------------------------------------------------------
use_authentication=1
设定启用身份验证。
设定系统信息的授权用户。
设定配置信息的授权用户。
设定系统命令的授权用户。
设定全部监测服务的授权用户。
设定全部被监测主机的授权用户。
设定全部监测服务命令的授权用户。
设定全部主机命令的授权用户。
-------------------------------------------------------------
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/commands.cfg-sample /usr/local/nagios/etc/commands.cfg
目前来说暂时不需要对Nagios命令定义文件做什么修改。但是如果要添加新的命令或者修改现有命令的定义的话,则需要修改该文件。