本次安装环境是RHEL5.5server。php
1、建立nagios用户和用户组
[root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#mkdir /usr/local/nagios
[root@localhost ~]#chown -R nagios.nagios /usr/local/nagios
2、开启系统sendmail服务
[root@localhost ~]#service sendmail start
3、编译安装nagios
[root@localhost ~]# tar -zxvf nagios-3.2.0.tar.gz
[root@localhost ~]# cd nagios-3.2.0
[root@localhost nagios-3.2.0]#./configure --prefix=/usr/local/nagios
#指定nagios的安装目录,这里指定nagios安装到/usr/local/nagios目录
[root@localhost nagios-3.2.0]#make all
[root@localhost nagios-3.2.0]#make install
# make install用来安装nagios的主程序,CGI和HTML文件
[root@localhost nagios-3.2.0]# make install-init
#经过make install-init命令能够在/etc/rc.d/init.d目录下建立nagios启动脚本
[root@localhost nagios-3.2.0]# make install-commandmode
#经过make install-commandmode命令来配置目录权限
[root@localhost nagios-3.2.0]# make install-config
#make install-cofig命令用来安装nagios示例配置文件,这里安装的路径是/usr/local/nagios/etc
nagios安装完成后,目录对应的功能说明以下:
bin:可执行程序所在目录
etc:配置文件所在目录
sbin:cgi文件所在目录,也就是执行外部命令所需文件所在目录
share:网页文件所在目录
libexec:外部插件所在目录
var:日志文件,lock等文件所在目录
var/archives:日志自动归档目录
var/rw:用来存放外部命令文件的目录
4、安装nagios的插件
以nagios-plugins-1.4.14为例,插件版本与nagios版本关系并不大。
[root@localhost nagios]#tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@localhost nagios]#cd nagios-plugins-1.4.14
[root@localhost nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.14]# make
[root@localhost nagios-plugins-1.4.14]# make install
查看/usr/local/nagios/libexec,会看到新增不少的插件。
5、安装Nagios中文化插件
下载地址:http://sourceforge.net/projects/nagios-cn/files/
此处切忌版本要与nagios的版本对应。
[root@localhost ~]#tar jxvf nagios-cn-3.2.0.tar.bz2
[root@localhost nagios-cn-3.2.0]#cd nagios-cn-3.2.0
[root@localhost nagios-cn-3.2.0]#./configure
[root@localhost nagios-cn-3.2.0]#make all
[root@localhost nagios-cn-3.2.0]#make install
6、安装httpd和php
依次执行以下命令:
[root@localhost nagios-cn-3.2.0]#rpm -ivh httpd-2.2.3-43.el5.i386.rpm
[root@localhost nagios-cn-3.2.0]#rpm -ivh php-common-5.1.6-27.el5.i386.rpm
[root@localhost nagios-cn-3.2.0]#rpm -ivh php-cli-5.1.6-27.el5.i386.rpm
[root@localhost nagios-cn-3.2.0]#rpm -ivh php-5.1.6-27.el5.i386.rpm
以上软件包从安装盘中的server目录中寻找。
7、配置httpd和php
修改httpd的配置文件/etc/httpd/conf/httpd.conf
找到以下两行
User apache
Group apache
#若是找不到,请经过搜索nobody寻找
修改成
User nagios
Group nagios
而后找到
DirectoryIndex index.html index.html.var
修改成
DirectoryIndex index.html index.html.var index.php
再在其下增长以下行
AddType application/x-httpd-php .php
在配置文件末尾增长以下信息:
#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>
保存配置文件
8、新增验证文件
[root@localhost]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd mark
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for user mark
在/usr/local/nagios/etc下就会新增一个htpasswd验证文件。
9、验证
[root@localhost]#service httpd restart
[root@localhost]#vipw
修改最后一行为
nagios:x:500:501::/home/nagios:/bin/bash
[root@localhost]#service nagios start
经过浏览器输入http://ip/nagios/
输入用户名/密码,就能够看到nagios的管理界面啦。此时看到的界面中没有任何监控机的信息。
10、配置本机监控
根据以下配置,完成本机监控的配置,先简单看看nagios监控的庐山真面目。本人已经验证在RHEL5.5下的nagios-3.2.0版本按以下配置以后,能实现nagios对本机的监控支持。
1、新建monitor文件夹,拷贝示例配置文件到该文件夹下
/usr/local/nagios/etc$cp -rf objects/ monitor
2、删除不须要得配置文件
/usr/local/nagios/etc/monitor$rm windows.cfg switch.cfg printer.cfg
3、修改contacts.cfg(联系人配置文件)
define contact{
contact_name mark ;修改成本身名字
use generic-contact ;引用generic-contact的属性信息
alias markjohnson ; 全名
email mark@126.com ; 修改成本身电子邮箱地址
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members mark ;添加上边定义的联系人名,以逗号分隔
}
4、修改cgi.cfg
default_user_name=mark ;将用户名修改成nagios界面登陆的用户名
5、修改nagios.cfg
将全部cfg_file=都注释掉添加以下一行
cfg_dir=/usr/local/nagios/etc/monitor
6、使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg检查配置是否有误
7、重启nagios:service nagios restart
此时登陆到nagios的web界面,就能查看到监控界面左侧的主机和服务中有咱们配置好的本地监控的信息啦。
问题:
一、 若是监控界面报出HTTP WARNING: HTTP/1.1 403 Forbidden错误,说明nagios不断地检查apache的根目录,在寻找index主页文件,执行以下命令:
/usr/local/nagios/etc$touch /var/www/html/index.html