1.安装依赖包
[root@node1 opt]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
[root@node1 ~]# useradd -s /sbin/nologin nagios
[root@node1 ~]# mkdir /usr/local/nagios
[root@node1 ~]# chown -R nagios.nagios /usr/local/nagios
2、编译安装Nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz
[root@node1 ~]# tar zxvf nagios-3.4.3.tar.gz
[root@node1 ~]# cd nagios
[root@node1 ~]# ./configure --prefix=/usr/local/nagios
General Options:
-------------------------
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
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@node1 ~]# make all
[root@node1 ~]#make install
[root@node1 nagios]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
*** Init script installed ***
[root@node1 nagios]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
[root@node1 nagios]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
[root@node1 nagios]# chkconfig --add nagios
[root@node1 nagios]# chkconfig --level 35 nagios on
[root@node1 nagios]# chkconfig --list nagios
nagios 0:off 1:off 2:off 3:on 4:on 5:on 6:off
3、安装Nagios 插件
[root@node1 opt]#tar zxvf nagios-plugins-1.4.13.tar.gz
[root@node1 opt]# cd nagios-plugins-1.4.13
[root@node1 opt]# ./configure --prefix=/usr/local/nagios
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
--enable-extra-opts: 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@node1 nagios-plugins-1.4.13]# make && make install
4、安装与配置Apache和Php
Apache 和Php 不是安装nagios 所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。
需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.4.3,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.4.10。
a. 安装Apache
# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
# tar zxvf httpd-2.2.23.tar.gz
# cd httpd-2.2.23
[root@node1 ~]# mkdir -p /usr/local/apache2
[root@node1 ~]# ./configure --prefix=/usr/local/apache2
[root@node1 ~]# make && make install
b. 安装Php
php-5.4.10.tar.gz
[root@node1 ~]# tar zxvf php-5.4.10.tar.gz
[root@node1 ~]# cd php-5.4.10
[root@node1 ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
checking for strftime... (cached) yes
checking which regex library to use... php
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
--解决方案
[root@node1 php-5.3.8]#yum erase zlib-devel
[root@node1 php-5.3.8]#yum install zlib-devel
[root@node1 php-5.3.8]#yum install libxml2-devel
[root@node1 ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@master php-5.4.10]# make && make install
c. 配置apache
找到apache 的配置文件/usr/local/apache2/conf/httpd.conf
找到:
User daemon
Group daemon
修改为
User nagios
Group nagios
然后找到
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
修改为
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
接着增加如下内容:
AddType application/x-httpd-php .php
为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在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>
复制代码
d. 创建apache目录验证文件
在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:
# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david
这样就在/usr/local/nagios/etc 目录下创建了一个htpasswd 验证文件,当通过http://192.168.1.108/nagios/ 访问时就需要输入用户名和密码了。
e. 查看认证文件的内容
# cat /usr/local/nagios/etc/htpasswd
f. 启动apache 服务
# /usr/local/apache2/bin/apachectl start
到这里nagios 的安装也就基本完成了,你可以通过web来访问了。
http://192.168.1.106/nagios/
遇到的问题与解决方案
问题一:
./configure以下错误发生
Sorry, I cannot run apxs. Possiblereasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using--with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page isdisplayed)
解决方法:指定正确的apxs路径
1.查找apxs路径
# whereis apxs
apxs:
说明系统没有安装apxs扩展工具
2.安装apxs
# yum install httpd-devel
3.查找apxs路径
# whereis apxs
apxs: /usr/sbin/apxs /usr/share/man/man8/apxs.8.gz
apxs安装成功
问题二:
安装apxs以下错误发生:
Package cyrus-sasl-plain needs cyrus-sasl-lib = 2.1.22-4, thisis not available.
解决方法:
# yum -y install cyrus*
之后再次安装apxs
问题三:
再次./configure以下错误发生
configure: error: xml2-config not found. Please check your libxml2installation.
解决方法:
安装libxml2
# yum install libxml2-devel
【问题四:=====================================================】
hecking libxml2 install dir... no
checking for xml2-config path... /usr/bin/xml2-config
checking whether libxml build works... no
configure: error: build test failed. Pleasecheck the config.log for details.
解决方法:
# yum erase zlib-devel
# yum install zlib-devel
# yum install libxml2-devel
[root@node1 ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
# make && make install