|
- 安装前的准备
3台装有rhel6.2x64系统的机器,其中一台作为服务端(192.168.5.203),另两台为被监控端(192.168.5.204和192.168.5.206)
在服务端:
1)创建nagios用户和用户组
[iyunv@Nagios-Server ~]# pwd
/root
[iyunv@Nagios-Server ~]# useradd -s /sbin/nologin nagios
[iyunv@Nagios-Server ~]# mkdir /usr/local/nagios
[iyunv@Nagios-Server ~]# chown -R nagios.nagios /usr/local/nagios/
2)开始系统的sendmail服务
[iyunv@Nagios-Server ~]# /etc/init.d/sendmail start
只需开启sendmail服务,无需配置
2.编译安装
[iyunv@Nagios-Server ~]# tar zxvf nagios-3.2.3.tar.gz
[iyunv@Nagios-Server ~]# cd nagios-3.2.3
[iyunv@Nagios-Server nagios-3.2.3]# ./configure --prefix=/usr/local/nagios
[iyunv@Nagios-Server nagios-3.2.3]# make all
[iyunv@Nagios-Server nagios-3.2.3]# make install
[iyunv@Nagios-Server nagios-3.2.3]# make install-init
[iyunv@Nagios-Server nagios-3.2.3]# make install-commandmode
[iyunv@Nagios-Server nagios-3.2.3]# make install-config
[iyunv@Nagios-Server nagios-3.2.3]# chkconfig --add nagios
[iyunv@Nagios-Server nagios-3.2.3]# chkconfig --level 35 nagios on
3.安装nagios插件
[iyunv@Nagios-Server ~]# tar nagios-plugins-1.4.14.tar.gz
[iyunv@Nagios-Server ~]# cd nagios-plugins-1.4.14
[iyunv@Nagios-Server nagios-plugins-1.4.14]# ./configure --prefix=/usr/local/nagios
[iyunv@Nagios-Server nagios-plugins-1.4.14]# make
[iyunv@Nagios-Server nagios-plugins-1.4.14]# make install
4.安装Apache和php
[iyunv@Nagios-Server ~]# tar jxvf httpd-2.2.23.tar.bz2
[iyunv@Nagios-Server ~]# cd httpd-2.2.23
[iyunv@Nagios-Server httpd-2.2.23]# ./configure --prefix=/usr/local/apache2
[iyunv@Nagios-Server httpd-2.2.23]# make &&make install
[iyunv@Nagios-Server ~]# tar zxvf php-5.4.10.tar.gz
[iyunv@Nagios-Server ~]# cd php-5.4.10
[iyunv@Nagios-Server php-5.4.10]# ./configure --prefix=/usr/local/php \
> --with-gd --with-zlib --with-apxs2=/usr/local/apache2/bin/apxs
[iyunv@Nagios-Server php-5.4.10]# make && make install
配置Apache
1)首先在/usr/local/apache2/conf/httpd.conf 中修改apache进程的启动用户为nagios
修改为:(大概在第67行)
User nagios
Group nagios
2)然后找到 DirectoryIndex(大概在168行 )
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
3)增加如下内容(大概在311行增加)
AddType application/x-httpd-php .php
4)授权访问nagios的web监控界面,需要增加验证配置,在http.conf文件的最后添加如下信息:
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>
5)创建Apache目录验证文件htpasswd (用户名ixdba ,密码1)
[iyunv@Nagios-Server ~]# /usr/local/apache2/bin/htpasswd \
> -c /usr/local/nagios/etc/htpasswd ixdba
New password:
Re-type new password:
Adding password for user nagios
6)启动apache服务
[iyunv@Nagios-Server ~]# /usr/local/apache2/bin/apachectl start
3.在服务端(192.168.5.203)安装NRPE外部构件监控远程主机
[iyunv@Nagios-Server ~]# tar zxvf nrpe-2.12.tar.gz
[iyunv@Nagios-Server ~]# cd nrpe-2.12
[iyunv@Nagios-Server nrpe-2.12]# make all
[iyunv@Nagios-Server nrpe-2.12]# make install-plugin
4.在被监控端(192.168.5.204和192.168.5.206)安装nagios客户端和NRPE(两台一样照下面操作)
1)在被监控机上安装nagios-plugins
[iyunv@localhost ~]# useradd -s /sbin/nologin nagios
[iyunv@localhost ~]# tar zxvf nagios-plugins-1.4.14.tar.gz
root@localhost ~]# cd nagios-plugins-1.4.14
[iyunv@localhost nagios-plugins-1.4.14]# ./configure
[iyunv@localhost nagios-plugins-1.4.14]# make
[iyunv@localhost nagios-plugins-1.4.14]# make install
[iyunv@localhost nagios-plugins-1.4.14]# chown nagios.nagios /usr/local/nagios/
[iyunv@localhost nagios-plugins-1.4.14]# chown -R nagios.nagios /usr/local/nagios/libexec/
2)在被监控机上安装nrpe
[iyunv@localhost ~]# tar zxvf nrpe-2.12.tar.gz
[iyunv@localhost ~]# cd nrpe-2.12
[iyunv@localhost nrpe-2.12]# ./configure
[iyunv@localhost nrpe-2.12]# make all
[iyunv@localhost nrpe-2.12]# make install-plugin
[iyunv@localhost nrpe-2.12]# make install-daemon
[iyunv@localhost nrpe-2.12]# make install-daemon-config
3)被监控机的NRPE
修改 /usr/local/nagios/etc/nrpe.cfg 中的allowed_hosts=127.0.0.1,(79行)修改为
allowed_hosts=127.0.0.1,192.168.5.203
启动nrpe进程
[iyunv@Nagios-Linux ]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[iyunv@localhost nrpe-2.12]# ps -ef | grep nrpe
nagios 21885 1 0 Sep09 ? 00:00:08 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[iyunv@Nagios-Server nrpe-2.12]# netstat -tunl | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
4)在服务端上测试与客户端能否正常通信,执行命令如下,表明,NRPE可以与客户端正常通信。
[iyunv@Nagios-Server nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.204
NRPE v2.12
[iyunv@Nagios-Server nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.206
NRPE v2.12
5)定义一个check_nrpe监控命令
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
6)在被监控机(192.168.5.204#假设该机器主要服务是web)上定义新增加监控服务器内容(204行)
[iyunv@localhost ~]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_tcp80]=/usr/local/nagios/libexec/check_tcp!80!5
重启nrpe进程才能生效:杀死进程,再启动进程
在被监控机(192.168.5.206#假设该机器主要服务是mysql)上定义新增加监控服务器内容(204行)
command[check_tcp3306]=/usr/local/nagios/libexec/check_tcp!3306!5
重启nrpe进程才能生效:杀死进程,再启动进程
4.在服务端添加被监控主机和监控服务
[iyunv@Nagios-Server ~]# cd /usr/local/nagios/etc/
[iyunv@Nagios-Server ~]# ls
cgi.cfg cgi.cfg~ htpasswd nagios.cfg nagios.cfg~ objects resource.cfg resource.cfg~
1)templates.cfg (默认不动)
位置 /usr/local/nagios/etc/objects/templates.cfg
2)resource.cfg(只有一行,大概是第26行,保证是下面参数)
#vim /usr/local/nagios/etc/resource.cfg
$USER1$=/usr/local/nagios/libexec
3)commands.cfg(默认不动)
4)host.cfg(默认没有,需要手动创建,此文件定义监控主机的名字和IP)
[iyunv@Nagios-Server objects]# pwd
/usr/local/nagios/etc/objects
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server ;默认写linux-server, 在templates.cfg中默认定义
host_name web ;这个主机名可以任意命名
alias ixdba-web ;别名任意命名
address 192.168.5.204 ;被监控机地址
}
define host{
use linux-server
host_name mysql
alias ixdba-mysql
address 192.168.5.206
}
define hostgroup ;定义主机组
hostgroup_name sa-server ;主机组名称任意命名
alias sa server ;主机别名
members web,mysql ;上面定义的两个主机
}
5)services.cfg(默认没有,需手动创建,此文件用来定义被监控主机的服务)
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/objects/services.cfg
define service{
use local-service ;默认local-servvice,已在templates.cfg中默认定义
host_name web ;web主机,即192.168.5.204,已在hosts.cfg中定义
service_description web80 ;监控内容描述,名称意思接近服务即可,任意
check_command check_nrpe!check_tcp80 ;命令已在被监控机nrpe.cfg中定义
}
define service{
use local-service
host_name mysql
service_description mysql3306
check_command check_nrpe!check_tcp3306
}
define servicegroup{ ;定义服务组,不是重点
servicegroup_name servergroup
alias server-group
members web,web80,mysql,mysql3306
}
~
6)contacts.cfg(定义联系人和联系人组)
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; 联系人名称,自定义 use generic-contact ; 使用generic-contact的属性信息,已在templates.cfg中定义
alias Nagios Admin ; Full name of user
email 15901392876@139.com ; 邮箱
}
define contactgroup{
contactgroup_name admins ;联系人组名称
alias Nagios Administrators
members nagiosadmin
}
7)timeperiods.cfg(定义监控时间段,已默认定义,无需改动)
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/objects/timeperiods.cfg
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
8)cgi.cfg(此文件用来控制相关CGI脚本,只需在此文件添加用户的执行权限)
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/cgi.cfg
default_user_name=ixdba
authorized_for_system_information=nagiosadmin,ixdba
authorized_for_configuration_information=nagiosadmin,ixdba
authorized_for_system_commands=nagiosadmin,ixdba
authorized_for_all_services=nagiosadmin,ixdba
authorized_for_all_hosts=nagiosadmin,ixdba
authorized_for_all_service_commands=nagiosadmin,ixdba
authorized_for_all_host_commands=nagiosadmin,ixdba
9)nagios.cfg(nagios的核心配置文件)
[iyunv@Nagios-Server ~]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg(添加)
cfg_file=/usr/local/nagios/etc/objects/services.cfg (添加)
use_authentication=1 #0改成1,大概78行
5.验证nagios配置文件的正确性
[iyunv@Nagios-Server ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
根据提示在错误在哪个文件的第几行有错误,而适当修改,(配置正确提示 警告0,错误0)
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
[iyunv@Nagios-Server ~]# service nagios start
|
|
|