1.创建nagios用户和用户组
[root@localhost /]# useradd -s /sbin/nologin nagios
[root@localhost /]# mkdir /usr/local/nagios
2.准备安装环境
[root@localhost ~]# yum install �Cy php httpd gcc glibc glibc-common gd gd-devel php-devel php-mysql mysql mysql-serverphp-snmp php-pdo perl-DBD-MYSQL php-pear openssl-devel
3.下载并安装nagios 4.0
[root@localhost ~]# cd /usr/local/
[root@localhost local]# wget http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.0/nagios-4.0.0.tar.gz
[root@localhost local]# tar -zxvf nagios-4.0.0.tar.gz
[root@localhost local]# chown -R nagios.nagios /usr/local/nagios
[root@localhost local]# cd nagios
[root@localhost nagios]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios]# make all
[root@localhost nagios]# make install
[root@localhost nagios]# make install-init
[root@localhost nagios]# make install-commandmode
[root@localhost nagios]# make install-config
[root@localhost nagios]# make install-webconf
备注:
make install用来安装nagios的主程序,CGI和HTML文件
make install-init命令可以在/etc/rc.d/init.d目录下创建nagios启动脚本
make install-commandmode命令来配置目录权限
make install-cofig命令用来安装nagios示例配置文件,这里安装的路径是/usr/local/nagios/etc
make install-webconf用来为nagios web接口安装apache配置文件
4.安装nagios的插件
[root@localhost nagios]# wget http://assets.nagios.com/downloads/nagiosplugins/nagios-plugins-1.5.tar.gz
[root@localhost nagios]# tar -zxvf nagios-plugins-1.5.tar.gz
[root@localhost nagios]# cd nagios-plugins-1.5
[root@localhost nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.5]# make all&& make install
5.配置httpd和php
修改httpd的配置文件/etc/httpd/conf/httpd.conf
[root@localhost ~]# cd /etc/httpd/conf/
[root@localhost conf]# vi httpd.conf
找到如下两行
User apache
Group apache
修改为
User nagios
Group nagios
然后找到
DirectoryIndex index.htmlindex.html.var
修改为
DirectoryIndex index.htmlindex.html.var index.php
再在其下增加如下行
AddTypeapplication/x-httpd-php .php
在配置文件末尾增加如下信息:
#setting for nagiosScript
Alias /nagios/cgi-bin"/usr/local/nagios/sbin"这行不加有空在研究WHY
<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"这行不加有空在研究WHY
<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>
ServerName nagios:80
保存配置文件
6.配置hosts文件
由于没有内部DNS服务器,所以只能编辑hosts文件
[root@localhost conf]# cd
[root@localhost ~]# cd /etc/
[root@localhost etc]# vi hosts
新增一行
10.14.34.54 nagios
7.启动httpd服务
[root@localhost conf]# httpd -t检查语法
[root@localhost conf]# service httpd start
8.新增验证文件
[root@localhost /]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiostest
New password:
Re-type new password:
Adding password for user nagiostest
在/usr/local/nagios/etc下就会新增一个htpasswd验证文件
9.把nagios加入到启动服务选项中
[root@localhost /]# chkconfig --level 35 nagios on
10.启动nagios服务
[root@localhost /]# service nagios start
nagios is stopped
Starting nagios: [OK]
11.关闭SELINUX和IPTABLES
[root@localhost /]# setenforce 0
[root@localhost /]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [OK]
iptables: Flushing firewall rules: [OK]
iptables: Unloading modules: [OK]
这是临时关闭,重启后又会开启的!
12.访问nagios
用浏览器输入nagios/nagios,然后输入帐号刚刚创建的nagiostest帐号和密码,终于看到久违的页面