1,nagios安装
下载的nagios版本为:nagios-3.4.1.tar.gz
安装环境nagios依赖的环境:
# yum -y install gcc
# yum -y install glibc glibc-common
# yum -y install gd gd-devel
解压并安装:
# cd /opt/soft/
# tar xf nagios-3.4.1.tar.gz
# /opt/soft/nagios
添加nagios用户:
# useradd nagios
对安装进行配置:
# ./configure --prefix=/opt/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
编译:
# make all
安装主程序,CGI以及HTML网页等:
# make install
在/etc/rc.d/init.d/目录中安装启动脚本:
# make install-init
安装和配置外部命令对Nagios主路径操作的权限(这里所谓的外部命令主要是指Apache服务通过CGI来对Nagios的进行的操作。用户将通过Web以执行CGI程序脚本的方式来对Nagios的检测结果进行读取和调用):
# make install-commandmode
在/usr/local/etc/这个Nagios编译安装的主配置路径下安装示例配置模板
# make install-config
2,安装nagios插件
# tar xzf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/opt/nagios --enable-redhat-pthread-workaround && make all && make install && chown -R nagios.nagios /opt/nagios/
(在redhat系统上面安装可能出现configure时,到这里checking for redhat spopen problem...就不动了,所以需要在configure时再加上这个 --enable-redhat-pthread-workaround
查看nagios的插件是否正常安装:
# ls /opt/nagios/libexec
3,编译安装nrpe:
由于server端会使用check_nrpe,建议在本机编译生成cherk_nrpe,拷贝其他机器生成的可能导致无法使用
# tar xzf nrpe-2.13.tar.gz
# nrpe-2.13
# ./configure --enable-ssl --enable-command-args --prefix=/opt/nagios/
# make all
安装check_nrpe 这个插件
# make install-plugin
安装deamon
# make install-daemon
安装nrpe配置文件
# make install-daemon-config
4,安装apache服务并配置:
# yum -y install httpd
# cd /etc/httpd/conf
# vim httpd.conf
添加如下内容:
设定Nagios的CGI执行目录对应的系统路径和网页URL对应的系统路径,并进行访问控制:
ScriptAlias /nagios/cgi-bin/ "/opt/nagios/sbin/"
<Directory "/opt/nagios/sbin/">
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /opt/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/opt/nagios/share/"
<Directory "/opt/nagios/share/">
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /opt/nagios/etc/htpasswd
Require valid-user
</Directory>
建立mops用户并设定密码为"SoHu&*":
# htpasswd -c /opt/nagios/etc/htpasswd mops
# sed -i 's/nagiosadmin/mops/g' /opt/nagios/etc/cgi.cfg
让Apache有适当的权限能够通过CGI脚本程序对Nagios进行调用,否则Apache将没有权限调用Nagios,用户通过Web将无法访问Nagios处理的所有信息:
# usermod -G nagios apache
使apache支持对php页面的支持
首先要确认自己安装了php(如果是用yum install php命令安装的php,则只需修改A即可)
# vim /etc/httpd/conf/httpd.conf
修改如下:
A、修改文件/etc/httpd/conf/httpd.conf添加默认文件
DirectoryIndex index.html index.htm index.php
B、加载支持php5的模块
LoadModule php5_module modules/libphp5.so
C、添加php识别
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
5,nagios的启动
检查其主配置文件的语法是否正确:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:
# service nagios start
6,启动httpd,我们就可以通过url访问:
# service httpd start
http://10.13.82.231/nagios/
输入用户名和密码即可登录nagios