注:
本文档基于nagios+apache的模式,安装nagios时须预先编译安装apache,在此不进行apache编译安装的赘述。
一:配置apache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# vi /usr/local/apache/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName 192.168.189.132
DocumentRoot
"/www"
<Directory
"/www"
>
Order deny,allow
Deny from all
<
/Directory
>
#以下是apache上,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"
//
配置nagios用户验证
Authuserfile
/usr/local/nagios/etc/htpasswd
Require valid-user
<
/directory
>
<
/VirtualHost
>
|
二:创建nagios用户与组
1
2
3
4
|
# useradd nagios
# groupadd nagios
# usermod –a –Gnagios nobody
# usermod –a –Gnagios nagios
|
二:下载nagios相关软件包,并编译安装及环境配置
1
2
3
4
5
6
7
|
# cd /usr/local/src
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
# tar -zxvf nagios-3.4.1.tar.gz
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# tar -zxvf nagios/nrpe-2.13.tar.gz
|
编译安装nagios
1
2
3
4
5
6
7
|
# cd nagios-3.4.1/
# ./configure --prefix=/usr/local/nagios --with-command-group=nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
|
编译安装nagios插件
# cd ../nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
# make && make install
编译安装nrpe
1
2
3
4
|
# cd ../nrpe-2.13
# ./configure --prefix=/usr/local/nagios
# make all
# make install-plugin
|
设置nagios目录权限
1
|
# chown –R nagios:nagios /usr/local/nagios/
|
配置用户密码访问
1
2
3
4
|
# /usr/local/apache/bin/htpasswd -cm /usr/local/nagios/etc/htpasswd nagiosadmin
New password:
Re-
type
new password:
Adding password
for
usernagiosadmin
|
三:启用nagios,并访问测试
开启apache服务
1
|
# /usr/local/apache/bin/apachectl -k start
|
检测nagios配置文件语法是否正确
1
|
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
|
若语法正确,则可以正常启动nagios
1
|
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -d
|
(也可使用系统服务方式启动:service nagios start)
页面访问测试
出现以上页面,说明nagios安装部署成功。后续需在服务中添加主机与服务,方能开始进行监控。
本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1852000,如需转载请自行联系原作者