安装配置nagios+nrpe+nconf
Nagios是一个功能非常强大的开源的系统网络监测程序,通过访问http://www.nagios.org可以了解其基本特性。Nagios不但能够实现对系统CPU,磁盘、网络等方面参数的基本系统监测,而且还能够监测包括SMTP,POP3,HTTP,NNTP等各种基本的服务类型。另外通过一些插件的安装和监测脚本自定义用户可以针对自己的应用程序实现监测,并针对大量的监测主机和多个对象部署层次化的监测架构
Nagios最大的特点之一是其设计者将Nagios设计成监测的管理中心尽管其功能是监测服务和主机,但是他自身并不包括这部分功能的代码,所有的监测、监测功能都是由相关插件来完成的,包括报警功能
Nagios的基本安装和配置:(广州机房商旅服务器)
监测主机:IP:10.205.0.71
操作系统:CentOS release 6.4 (Final)
被监测主机:IP:10.205.0.70
操作系统:CentOS release 6.4 (Final)
所需软件:
nagios-3.4.1.tar.gz nagios-plugins-1.4.15.tar.gz nrpe-2.13.tar.gz
先在监测主机也就是192.168.1.10上安装Nagios的基本软件包,在安装Nagios之前首先需要保证系统中有下面这些软件包:Apache,gcc,gd,gd-devel,glibc,glibc-devel。可以用rpm
–qa | grep的方式去逐一检查。
如果确认上面这些包都安装之后需要先建立Nagios的用户和nagcmd组:
# useradd -m nagios
[ Enter ]
# passwd nagios
[ Enter ]
并将nagios以及apache用户加入到nagcmd组中
# groupadd nagcmd
[ Enter ]
# usermod -G nagcmd nagios
[ Enter ]
# usermod -G nagcmd apache
[ Enter ]
完成之后将下载的nagios压缩包拷贝到/usr/local目录中,并且执行下面的步骤进行编译和安装:
# tar -zxf
nagios-plugins-1.4.15.tar.gz
[ Enter ]
# cd nagios
[ Enter ]
首先初始化和建立编译的环境
# ./configure --with-command-group=nagcmd
[ Enter ]
Review the options above for accuracy.
If they look okay,
type ‘make all‘ to compile the main program and CGIs.
之后按照提示执行命令来进行编译:
# make all
[ Enter ]
如果编译过程顺利完成,则需要执行下面的命令:
# make install
[ Enter ]
# make install-init
[ Enter ]
# make install-config
[ Enter ]
# make install-commandmode
[ Enter ]
分别用于安装二进制文件、初始化脚本、示例配置文件和设置目录权限。
# ls /usr/local/nagios
[ Enter ]
安装完成之后,在/usr/local/nagios目录下如果能够看到这些目录:bin etc sbin share var就表示Naigos安装成功了。
不过在完成之后还不能启动Nagios,因为还有一些操作需要执行。
Nagios的样例配置文件默认安装在/usr/local/nagios/etc目录下,这些样例文件可以配置Nagios使之正常运行,只需要做一个简单的修改。用你擅长的编辑器软件来编辑这个/usr/local/nagios/etc/objects/contacts.cfg配置文件,更改email部分,在nagiosadmin的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。
# vi /usr/local/nagios/etc/objects/contacts.cfg
[
之后执行下面的命令来安装Nagios的WEB配置文件到Apache的conf.d目录下:
# make install-webconf
[ Enter ]
在Apache中使用基本认证的方式创建一个nagiosadmin的用户用于Nagios的WEB界面登录。记下你所设置的登录口令。该用户登录口令和账号信息会存储到/usr/local/nagios/etc/passwd.users文件中:
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
重启apache来应用配置:
# service httpd restart
# chkconfig --level 345 httpd on
安装nagios插件
# tar -zvxf nagios-plugins-1.4.15.tar.gz
[ Enter ]
# cd nagios-plugins-1.4.15
[ Enter ]
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
[
然后把Nagios加入到服务列表中以使之在系统启动时自动启动:
# chkconfig --add nagios
# chkconfig nagios on
[
执行下面的命令来验证Nagios的样例配置文件:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果最后的结果类似下面而没有报错,可以启动Nagios服务:
Total Warnings: 0
Total Errors:
0
# service nagios start
后可以在浏览器上访问链接http://10.205.0.71/nagios
安装NRPE
用NRPE外部构件监测远程主机。NRPE外部构件可以在远程的Linux/Unix主机上执行插件程序。如果是要象监测本地主机一样对远程主机的磁盘利用率、CPU负荷和内存占用率等情况下,NRPE外部构件将非常有用。
下面的操作将会在被监测主机10.205.0.71上进行。
首先要建立Nagios账号,这里我使用同样的密码:
# useradd nagios
# passwd nagios
之后按照和上面相同的步骤来编译和安装nagios-plugin软件:
# tar -zvxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure
# make
# make install
然后对相关的目录设置权限和所属用户组:
# chown nagios.nagios /usr/local/nagios
# chown –R nagios.nagios /usr/local/nagios/libexec
接着NRPE包放到/usr/local目录下,按照下面的步骤解压缩,并且编译和安装:
# tar -zvxf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
接着执行命令将nrpe安装为依赖xinetd超级进程的非独立服务,那么前提是必须安装xinetd:
安装方法: yum -y install xinetd
最后执行下面的命令将NRPE安装为xinetd超级进程所管理的进程之一。
make install-xinetd
完成之后需要编辑/etc/xinetd.d目录下的nrpe文件,并且在最后添加允许实施监测的主机IP地址,这里是10.205.0.71,那么整个配置文件全文如下:
# cat /etc/xinetd.d/nrpe
[ Enter ]
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 10.205.0.71
}
然后修改/etc/services档,并添加下面的内容:
nrpe
5666/tcp # nrpe
重启服务:
# /etc/init.d/xinetd restart
此时检查nrpe服务启动状况如下:
# netstat -nl | grep 5666
tcp
0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
# lsof -i:5666
COMMAND
PID USER FD TYPE DEVICE SIZE NODE NAME
xinetd
9949 root 5u IPv4 28764 TCP *:nrpe (LISTEN)
在监控机(10.205.0.70)也要安装NRPE:
[[email protected] nrpe-2.13]# scp [email protected]:/usr/local/nrpe-2.13.tar.gz ./
[[email protected] nrpe-2.13]# tar -zxvf nrpe-2.13.tar.gz
[[email protected] nrpe-2.13]# cd nrpe-2.13
[[email protected] nrpe-2.13]# ./configure
Review the options above for accuracy. If they look okay,
type ‘make all‘ to compile the NRPE daemon and client.
[[email protected] nrpe-2.13]# make all
[[email protected] nrpe-2.13]# make install-plugin
只运行这一步就行了,因为只需要check_nrpe插件
在监控机上连被监控机,如下则表示成功:
[[email protected] local]# /usr/local/nagios/libexec/check_nrpe -H 10.205.0.70
NRPE v2.13
安装NCONF
上传nconf-1.3.0-0.tgz,并解压到apache文档目录
cd /var/www/html/
tar -zxvf /bee/app/nagios/nconf-1.3.0-0.tgz -C .
创建nconf数据库以用户
# mysql -u root -p (root初始密码为空,可自行更改)
mysql> create database nconf;
mysql> grant all privileges on nconf.* to [email protected] identified by ‘bee2c.com‘;
mysql> flush privileges;
# cd /var/www/html/nconf/
# mysql -u nconf -p nconf < INSTALL/create_database.sql
4.修改相关目录权限
# chown -R nagios:nagios config/ temp/ static_cfg/ output/
在浏览器中输入http://10.205.0.71/nconf
点click here
进行安装:点”next”,设置数据库和登录用户密码等
在保存配置文件处报了错,网上找不到相关内容,于是从以前环境中拷贝来了四个配置文件
安装完毕后,然后删除安装文件:
# cd /var/www/html/nconf/
# rm -rf INSTALL* UPDATE*
# cp /usr/local/nagios/bin/nagios bin/nagios
# chown -R nagios:nagios bin
访问nconf:http://10.205.0.71/nconf/
输入正确的用户名和密码:
注意用户名和密码配置在隐形文件:/var/www/html/nconf/config/ .file_accounts.php中
问题解决附录:
checking for SSL headers... configure: error: Cannot find ssl headers
[[email protected] nrpe-2.13]# yum -y install openssl-devel
Redhat默认没有安装xinetd
[[email protected] init.d]# /etc/init.d/xinetd restart
-bash: /etc/init.d/xinetd: No such file or directory
[[email protected] init.d]# yum -y install xinetd
[email protected] nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H 10.205.0.70
CHECK_NRPE: Error - Could not complete SSL handshake.
[[email protected] local]# vi /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 10.205.0.71
}
[[email protected] local]# service xinetd restart
[KB1004] Submited infos are not allowed to be resent
Problem description
The following error may sometimes appear when you‘re submitting data (e.g. adding or modifying an item). The error is based on a feature which is intended to protect the application from users who unintentionally resubmit the same data.
Solution
Make sure the user account which is running your webserver has write access to the session-cache path specified in your php.ini (the “session.save_path” variable).
find / -name "php.ini"
session.save_path = "/var/lib/php/session"
chmod 777 /var/lib/php/session
安装nconf后看不到check_nrpe
命令:
deploy_local.sh是nconf自带配置文件导入脚本
/usr/local/nconf/ADD-ONS/deploy_local.sh
手动执行此脚本,将在/usr/local/nagios/etc下生成两目录Default_collector与global
Nagios改从这两目录中读取配置文件,需修改nagios.cfg,注释掉原来的, nagios.cfg新加:
cfg_dir=/usr/local/nagios/etc/Default_collector
cfg_dir=/usr/local/nagios/etc/global
重启后在nconf中新加check_nrpe
[[email protected] ~]#./configure --enable-command-args
安装完之后编辑 nrpe.cfg
将 dont_blame_nrpe=1 从0改为1 #打开参数传递