nagios的安装配置记录

nrpe:nagios remote plugin executable

成都创新互联专业为企业提供丰林网站建设、丰林做网站、丰林网站设计、丰林网站制作等企业网站建设、网页设计与制作、丰林企业网站模板建站服务,10年丰林做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

  • 准备工作:

yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp openssl openssl-devel (其中的httpd php要么都使用yum安装的,要么都重新使用源码编译安装,不然后面会加载不到相关包,导致页面打不开或报错)

安装包下载:

[root@nagios ~]# wget http://nchc.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.4.4/nagios-3.4.4.tar.gz

[root@nagios ~]# wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

[root@nagios ~]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

http://nsclient.org/nscp/downloads

http://files.nsclient.org/0.3.x/NSClient%2B%2B-0.3.9-Win32.zip

http://files.nsclient.org/0.3.x/NSClient%2B%2B-0.3.9-x64.zip

添加用户及组:

useradd nagios -p nagios

groupadd nagcmd

usermod -G nagcmd nagios

usermod -G nagcmd apache

  • apache(httpd)的安装配置:(源码编译安装)

tar zxvf httpd

cd httpd

./configure

make && make install

vi /usr/local/apache2/conf/httpd.conf [Listen 8080] 修改端口,记得在防火墙中允许该端口

/usr/local/apache2/bin/apachectl -k start [此为启动源码安装的httpd,若使用了yum install httpd,则service httpd start 启动的不是源码安装的,若源码安装的也可以使用service,需要修改配置文件]

netstat -lntp 查看修改的8080端口是否处于LISTENING,是则启动成功

http://ip:8080 显示apache页面则正常

{添加命令开机启动设置:echo "/usr/local/apache2/bin/apachectl -k start" >> /etc/rc.d/rc.local reboot netstat -lntp}

  • php的重新安装配置:(源码编译安装)

    http://www.cnblogs.com/fly1988happy/archive/2011/12/14/2288096.html

安装包:php libxml2

tar zxvf libxml2

cd libxml2

./configure --prefix=/usr/local/libxml2

make && make install

#tar zvxf php-5.3.8.tar.gz 
#cd php-5.3.8
#./configure \
--prefix=/usr/local/php \
--with-MySQL=/usr/local/mysql \
--with-apxs=/usr/local/apache2/bin/apxs \
--with-libxml-dir=/usr/ local/libxml2
#make
#make install

# vi /usr/local/apache/conf/httpd.conf

找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容

AddType application/x-httpd-php .php (.前面有空格)

AddType application/x-httpd-php-source .phps (.前面有空格)

cp php-5.3.8/php.ini.dist /usr/local/php/lib/php.ini (文件在解压出来的安装包中)

(如果没有php.ini.dist 则把php.ini-development php.ini-production中的任何一个重命名为php.ini.dist即可。)

修改php.ini文件 register_globals = On (有些没有这个,直接添加即可)

service apache restart

写一个php测试页info.php,放到apache2/htdocs中。

phpinfo();

?>;

http://ip:8080/info.php 显示出相关信息则php启动正常 [nagios页面为php页面]

  • 监控端nagios的安装配置

    nagios 目标:可查看到nagios core [http://ip:port/nagios]

tar zxvf nagios

cd nagios

./configure --with-command-group=nagcmd

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf (default:/etc/httpd/conf.d/nagios.cfg 此目录为yum安装httpd的路径,若apache为源码编译安装,则需要手动执行命令或建立目录,但这是读取不到的,需要将配置的内容拷贝到httpd.conf中)

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

nagios配置文件验证与启动:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

/etc/init.d/nagios start

chkconfig --add nagios

chkconfig nagios on | chkconfig nagios --level 2345 on

chkconfig --list nagios

创建web页面访问用户

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

htpasswd /usr/local/nagios/etc/htpasswd.users nagiostest (第一次创建用-c参数,之后添加登录用户不用参数,直接创建)

查看:cat /usr/local/nagios/etc/htpasswd.users

安装nagios-plugin:

tar zxvf nagios-plugin

cd nagios-plugin

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make && make install

vi /etc/sysconfig/iptables

service iptables restart

cat /etc/httpd/conf.d/nagios.cfg >> /usr/local/apache2/conf/httpd.conf

vi /usr/local/apache2/conf/httpd.conf [Listen 8080 ; DirectoryIndex index.php ]

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

service nagios reload

service httpd restart

http://ip:port/nagios

  • 监控端(nagios服务器)的配置:

    linux(centos):

cd nrpe

./configure

make all

make install-plugin (只需这一步即可,因为只要check_nrpe插件)

vi /usr/local/nagios/etc/objects/command.cfg 增加以下代码:

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

} #只有在command.cfg中定义的命令才可以在service中使用,而check_nrpe的参数arg1只有在被监控端的etc/nrpe.cfg中定义的命令才可以使用

service中的命令,对于有参数的,使用!分隔开

vi /usr/local/nagios/etc/nagios.cfg 添加配置文件路径

vi /usr/local/nagios/etc/objects/hosts 添加监控对象及服务

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

service nagios reload 或 service nagios restart

  • 被监控端(nrpe)的配置:

linux(centosnode1):

yum install -y lrzsz (将监控端的两个安装包传输过来:nagios-plugin,nrpe)

rpm -qa|grep gcc openssl openssl-devel

yum install -y openssl openssl-devel

tar zxvf nagios-plugin;tar zxvf nrpe

cd nagios-plugin

useradd nagios -s /sbin/nologin -p nagios

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make && make install

ll /usr/local/nagios/ --etc/ libexec/ include/

chown -R nagios:nagios /usr/local/nagios

cd nrpe

./configure (openssl,openssl-devel)

make all

make install-plugin (不是必须的,用于本机测试,plugin提供命令check_nrpe,相当于ping等命令)

make install-daemon

make install-daemon-config

make install-xinetd (用于nrpe的另一种使用方式,即nrpe运行在xinetd下)

vi /etc/xinetd.d/nrpe [only_from=127.0.0.1 192.168.1.123] 此处用空格,仅对nrpe运行在xinetd下时有用,至于nrpe使用哪种方式,根据其启动方式定

vi /etc/service [添加nrpe 5666/tcp 使用xinted方式则需要,独立时不需要]

vi /usr/local/nagios/etc/nrpe.cfg [allowed_hosts=127.0.0.1,10.10.10.254]此处用逗号,仅对独立运行nrpe时有效,xinetd运行下时将被忽略

修改防火墙,放开5666端口. service iptables restart

启动nrpe:

方式1-独立nrpe daemon:

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

netstat -lntp 或 netstat -an|grep 5666 查看端口是否处于侦听状态

方式2-xinetd下

service xinetd start

ps -elf|grep nrpe netstat -an|grep 5666

测试:被监控机上 /usr/local/nagios/libexec/check_nrpe -H localhost

监控机上 /usr/local/nagios/libexec/check_nrpe -H 被监控机ip

(正常返回nrpe版本号)

windows [使用nsclient++ 与 check_nt]

【修改nagios.cfg,放开windows.cfg,检查后重启nagios】

下载NSClient++ 解压

cd NSClient++

NSClient++ -install

NSClient++ SysTray install

service.msc ->NSClient++ ->打开,登录【允许服务与桌面交互】

编辑解压包下的nsc.ini

nagios的安装配置记录NSClient++ -start

netstat -an 看到12489端口处于LISTENING表示正常启动

至此windows上的配置完成,等待监控端nagios发起某个监控请求

(有点问题,测试时:监控端linux与windows互ping存在问题,之前正常,需要查找哪出现问题)

  • 防火墙设置:

vi /etc/sysconfig/iptables

/sbin/iptables -I INPUT -p tcp -dport 8080 -j ACCEPT

  • 问题记录说明:

1 nrpe版本一致,但分别安装在32位与64位,在使用/usr/local/nagios/libexec/check_nrpe -H 被监控主机ip 时报错:CHECK_NRPE: Error - Could not complete SSL handshake.换成同为32位正常

此问题,需将两端的nrpe配置检查一遍,因为只要防火墙打开,网络即通,出问题的地方是ssl通信,即check_nrpe与nrpe的通信出问题

2 分清楚yum包安装 与 源码编译安装,混用可能会导致无法相互加载。 forbidden:no access /nagios

3 not found /nagios [cat ../nagios.cfg >> ../apache2/conf/httpd.conf]


网页名称:nagios的安装配置记录
文章URL:http://hbruida.cn/article/jdjgdd.html