Nagios-install
安装环境:redhat 5.4
apache2.2.14
php5.2.9
mysql5.1.36
服务器的安装:
1:确保系统上安装好了以下的软件包,以下软件gd与gd-devel若缺少,会导致map页面出现cgi-bin statusmap.cgi was not found on this server这样的错误信息!
[root@server ~]#rpm -qa | grep -E "zlib-|gd-|freetype-|fontconfig-|libxml|libpng-|libjpeg-*"
libpng-1.2.10-7
zlib-devel-1.2.3-3
fontconfig-devel-2.4.1-6.el5
libxml2-2.6.26-2.1.2
fontconfig-2.4.1-6.el5
sysklogd-1.4.1-39.2
libxml2-devel-2.6.26-2.1.2
libjpeg-devel-6b-37
freetype-devel-2.2.1-16.el5
gd-devel-2.0.33-9.3.fc6
zlib-1.2.3-3
freetype-2.2.1-16.el5
libjpeg-6b-37
libxml2-python-2.6.26-2.1.2
libpng-devel-1.2.10-7
gd-2.0.33-9.3.fc6
2:安装并设定nagios主程序
[root@server ~]#useradd nagios (添加nagios,该用户可以不设定密码,但登录shell最好设定为/bin/sh,之前设定为/sbin/nologin后,启动服务的时候出现了current account not avaliable这样的信息)
[root@server ~]#groupadd nagcmd 创建nagcmd组
[root@server ~]#usermod -a -G nagcmd daemon (因为是编译方式安装的apache,默认是以daemon用户运行)
[root@server ~]#usermod -a -G nagcmd nagios
下载相关的软件包,服务器端需要安装以下三个包,客户端只需要安装后两个插件包
[root@server ~]#cd /usr/local/src/tarbag/
[root@server tarbag]#wget http://d3.766.com/766down/nagios/nagios-3.2.0.tar.gz
[root@server tarbag]#wget http://d3.766.com/766down/nagios/nagios-plugins-1.4.14.tar.gz
[root@server tarbag]#wget http://d3.766.com/766down/nagios/nrpe-2.12.tar.gz
解压并编译安装
[root@server tarbag]#tar -zxvf nagios-3.2.0.tar.gz -C ../software/
[root@server tarbag]#cd ../software/nagios-3.2.0/
[root@server nagios3.2.0]#./configure --prefix=/usr/local/nagios —with-command-group=nagcmd 运行nagios配置脚本设置安装路径并使用先有设定的用户及组
[root@server nagios-3.2.0]#make all
[root@server nagios-3.2.0]#make install
[root@server nagios-3.2.0]#make install-init //在/etc/rc.d/init.d安装启动脚本
[root@server nagios-3.2.0]#make install-commandmode //配置目录权限
[root@server nagios-3.2.0]#make install-config //安装示例配置文件,安装的路径是/usr/local/nagios/etc
[root@server nagios-3.2.0]#ls /usr/local/nagios/
bin 存放nagios执行程序,nagios文件为主程序
etc 配置文件存放目录
libexec 存放一些脚本程序
sbin cgi文件所在目录,也就是执行外部命令所需文件所在的目录
share 网页文件存放位置
var 日志文件、spid 等文件所在的目录
[root@server ~]#vi /usr/local/apache2/conf/httpd.conf
#把下面的内容增加到文件的最后:
Scriptalias /nagios/cgi-bin /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
Alias /nagios /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
[root@server ~]#service httpd restart
[root@server ~]#/usr/local/apache2/bin/htpasswd -cm /usr/local/nagios/etc/htpasswd yang 创建一个yang的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它
New password:
Re-type new password:
Adding password for user yang
1:修改cgi脚本控制文件cgi.cfg
[root@server ~]#vi /usr/local/nagios/etc/cgi.cfg //cgi脚本控制文件
use_authentication=1 //打开验证
default_user_name=yang
authorized_for_system_information=nagiosadmin,yang
authorized_for_configuration_information=nagiosadmin,yang
authorized_for_system_commands=nagiosadmin,yang
authorized_for_all_services=nagiosadmin,yang
authorized_for_all_hosts=nagiosadmin,yang
authorized_for_all_service_commands=nagiosadmin,yang
authorized_for_all_host_commands=nagiosadmin,yang
这里添加的用户"yang"可以通过浏览器对nagios服务进行关闭.重启等操作.在这里为了安全也可以把nagiosadmin这一个用户删除.如果有多个用户.用逗号隔开.如: ngaiosadmin.yang.test.admin.
服务器端的主程序安装到此结束,打开浏览器输入:http://ip (or url)/nagios应该要能访问nagios主页面,同时,apache需要支持php扩展。
2:下面安装第2个插件
[root@server tarbag]#tar zxvf nagios-plugins-1.4.14.tar.gz -C ../software/
[root@server tarbag]#cd ../software/nagios-plugins-1.4.14/
[root@server nagios-plugins-1.4.14]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@server nagios-plugins-1.4.14]#make && make install
[root@server ~]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 检测主配置文件是否能被正常加载
Total Warnings: 0
Total Errors: 0
3:安装第3个插件nrpe
[root@server tarbag]#tar -zvxf nrpe-2.12.tar.gz -C ../software/
[root@server tarbag]#cd ../software/nrpe-2.12/
[root@server nrpe-2.12]#./configure (如果这步报错:configure: error: Cannot find ssl headers ,则需安装openssl-devel)
[root@server nrpe-2.12]#make all
[root@server nrpe-2.12]#make install-plugin
[root@server ~]#chown -R nagios:nagios /usr/local/nagios/
[root@server ~]#service nagios start 启动nagios服务
[root@server ~]#chkconfig nagios on
[root@server ~]# ps -ef |grep nagios
nagios 22724 1 0 01:34 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
服务器端的安装部分到此结束!
客户端的安装:
[root@client ~]#useradd nagios -s /sbin/nologin 这里可以指定用户的登录shell为/sbin/nologin
[root@client ~]#cd /usr/local/src/tarbag
[root@client tarbag]#wget http://d3.766.com/766down/nagios/nagios-plugins-1.4.14.tar.gz
[root@client tarbag]#tar -zxvf nagios-plugins-1.4.14.tar.gz -C ../software/
[root@client nagios-plugins-1.4.14]#cd ../software/nagios-plugins-1.4.14/
[root@client nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios
[root@client nagios-plugins-1.4.14]#make
[root@client nagios-plugins-1.4.14]#make install
[root@client ~]#cd /usr/local/src/tarbag
[root@client tarbag]#wget http://d3.766.com/766down/nagios/nrpe-2.12.tar.gz
[root@client tarbag/ <116>]#tar zxvf nrpe-2.12.tar.gz -C ../software/
[root@client tarbag/ <118>]#cd ../software/nrpe-2.12/
[root@client nrpe-2.12/ <121>]#./configure --prefix=/usr/local/nagios/
[root@client nrpe-2.12/ <121>]#make all
[root@client nrpe-2.12/ <121>]#make install-plugin 安装check_nrpe这个插件
[root@client nrpe-2.12/ <122>]#make install-daemon 安装daemon
[root@client nrpe-2.12/ <123>]#make install-daemon-config 安装配置文件
修改客户端的主配置文件,添加允许访问的主机,这里我服务器的IP是192.168.90.20,同时让他侦听本机的所有网络接口上的IP地址
[root@client ~]#grep 'allowed_hosts' /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.90.20
[root@client ~]#grep server_address /usr/local/nagios/etc/nrpe.cfg
server_address=0.0.0.0
启动nrpe,并检测端口是否正常开启
[root@client ~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@client ~]#netstat -ntpl |grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 4251/nrpe
nrpe也支持xinetd方式启动,下面来设置下nrpe随xinetd启动:
[root@client ~]#cd /etc/xinetd.d
[root@client xinetd.d]#cp tftp nrpe
[root@client xinetd.d]#vim nrpe
将内容改成如下:
# default: on
# description: NRPE
service nrpe
{
socket_type = stream
protocol = tcp
wait = no
user = nagios ##运行的用户
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
disable = no ##默认运行
cps = 100 2
flags = IPv4
}
[root@client xinetd.d]#vim /etc/services
在最后一行加上:nrpe 5666/tcp
测试:
[root@client xinetd.d]# netstat -lntp | grep 5666
[root@client xinetd.d]#
[root@client xinetd.d]# service xinetd start
Starting xinetd: [ OK ]
[root@client xinetd.d]# netstat -lntp | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 20640/xinetd
测试nrpe本机能否正常工作
[root@client ~]#/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users
USERS OK - 3 users currently logged in |users=3;5;10;0
也可以在服务器端上检测下nrpe的连通性,若这里出现“Connection refused by host
”则需要检查能否telnet 到客户端的5666端口,这里可能会存在网络,防火墙问题,或者客户端的nrpe进程没有启用,若出现“CHECK_NRPE: Error - Could not complete SSL handshake.”
则需要检查客户端的主配置文件中的“allowed_hosts”参数设定或者tcp_wrappers的相关配置
[root@server ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.90.1
NRPE v2.12
自此客户端的安装配置结束!
服务器与客户端配置文件设置请详见 766-Nagios-config 文档!