资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Centos6.5-----nagios快速安装编译配置文档-全部虚拟环境

写这个文档的目的,就是为了方便 快捷的部署nagios,涉及到个人喜好的配置,大家自行修改,可以套用。

站在用户的角度思考问题,与客户深入沟通,找到晋州网站设计与晋州网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站制作、成都网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖晋州地区。

一、下载并安装所需软件

 1,yum install gcc MySQL httpd php gd openssl openssl-devel mysql-server vim wget

Wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz

Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Ls 可以看到nagios-4.0.7.tar.gz nagios-plugins-2.0.3.tar.gz nrpe-2.14.tar.gz

yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

useradd nagios

passwd nagios

groupadd nagcmd

usermod –a –G nagcmd nagios

(nagcmd:x:504:nagios)

tar –xvzf nagios-4.0.7.tar.gz

cd nagios-4.0.7

./configure –with-command-group=nagcmd

可以先./configure –help先看看帮助,应为默认为主是用nagios用户,不需要指定—with-nagios-user或其它什么的。

make all

make install

make install-init

这个安装/etc/rc.d/init.d中的init脚本

make install-commandmode

这个安装和配置权限

目录的外部命令文件

make install-config

这个安装* * /usr/local/nagios/etc配置文件示例

你必须修改这些示例文件之前

使用Nagios。阅读HTML文档

make install-webconf

这个安装Nagios的Apache配置文件

Web界面

Cp –R contrib/eventhandlers/ /usr/local/nagios/libexec/

 (-R:递归复制目录,即连同目录下的子目录和文件一起复制。)

Chown –R nagios:nagios /usr/local/nagios/libexec/eventhandlers

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (检测配置文件是否有错误)

{ [root@Nagios libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

[root@Nagios libexec]# ll

total 4

drwxr-xr-x. 4 nagios nagios 4096 Oct 21 01:16 eventhandlers}

/etc/init.d/nagios start 或者service nagios start

Chkconfig --add nagios

Chkconfig nagios on

Chkconfig httpd on

Service httpd start

二、创建web用户

切换到ngios用户

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

输入密码nagios

三、安装nagios-plugins

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins-2.0.3

./configure {–with-nagios-user=nagios –with-nagios-group=nagios}

Make 

Make install

前面这步做了可以略过,反正要做一次。

Chkconfig nagios on 或者chkconfig –level 35 nagios on

Chkconfig httpd on 或者 chkconfig –level 35 httpd on

四、关闭防火墙和selinux 

service iptables stop

Vim /etc/sysconfig/selinux 把selinux改成disabled这个需重启生效。

http://192.168.1.202/nagios/ 这个是nagios地址,要输入用户名和密码的nagiosadmin nagios

******无法开题notifications报错****************************************

Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!

这个主要是apache 用户 没有执行权限 /usr/local/nagios/var/rw/nagios.cmd 造成,

解决方法:

usermod -a -G nagcmd apache

将apache用户添加到nagios用户组,就OK了。

date -s 调整日期时间   clock -w 保存

五、安装NRPE插件。

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure 

 make && make install

make install-plugin 

把check_nrpe放到/usr/local/nagios/libex下。才能使用check_nrpe。

 

***********************************************************************************

*********************************2***************************************************

在被监控机器上安装。

Nagios-plugins安装.

Useradd nagios

Passwd nagios

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins

./configure 

Make 

Make install

Chown –R nagios:nagios /usr/local/nagios

安装nrpe-2.14

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

yum install xinetd

chkconfig --add xinetd

chkconfig xinetd on

make install-xinetd

vim /etc/xinetd.d/nrpe 

在该文件的only_from  = 127.0.0.1 192.168.1.107  //在后面增加监控主机的地址,以空格间隔

vim /usr/local/nagios/etc/nrpe.cfg 这里也是充许访问里添加 192.168.107

vim /etc/services

启动nrpe就好了。

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

service xinetd restart

 netstat -at |grep nrpe

Netstat –an | grep 5666

Vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT (该语句有待,不过我另一台也是这样配的)

好像不添加上面这个不得行,会报check_nrpe:Error - Could not complete SSL handshake

运行ipables –F 清空一下规则,然后保存。

然后iptables –L –n 查看确认后。

Service iptables save

Service iptables restart

2、配置文件方面:

(1)/usr/local/nagios/etc/nrpe.cfg 此配置文件是配置正确,多个IP地址逗号隔开,且要注意空格:allowed_host=127.0.0.1,  192.168.0.1 这是不对的,必须是allowed_host=127.0.0.1,192.168.1.202   逗号之后不能有空格;

(2)检查是否配置里限制了,在 /etc/xinetd.d/nrpe 文件中要添加允许访问的服务器的IP地址,在 “only_from = ” 这一行添加, 多个IP地址用空格隔开,例如:only_from       = 192.168.0.8 192.168.1.202

被控端:

vi /etc/xinetd.d/nrpe

only_from 增加主控IP

vi /usr/local/nagios/etc/nrpe.cfg

allowed_hosts 增加主控IP

service xinetd restart

主控端:

/usr/local/nagios/libexec/check_nrpe -H 被监控端IP地址       测试是否连接成功

修改nrpe.cfg后一定要重启nrpe,大侠我是这样做的: 

pkill nrpe;

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

二、添加监控节点及service

三】增加验证用户

也就是通过web访问nagios的时候,必须要用这个用户登陆.在这里我们增加用户test:密码为12345

64.   [root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test

可以用 which命令查看 htpasswd命令的位置,如果是源码安装的apache这里就写htpasswd的全路径。用户是test,命令结束会提示你输入密码,这里输入123456即可。

65.   查看认证文件的内容

66.   [root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd

67.   到这里nagios的安装也就基本完成了,你可以通过web来访问了.

三、检测定义快捷命令

问题1:新建立文件夹及节点无法生效

解决:修改nagios目录文件,使其目录被检测

vi /usr/local/nagios/etc/nagios.cfg 

添加 要检测的目录。

cfg_dir=/usr/local/nagios/etc/cfgs

问题2:《《apache 启动失败 》》  默认安装在/usr/sbin/下,执行apachectl start时候,提示如下错误:

httpd: apr_sockaddr_info_get() failed for shiwei

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

于是上网查了一下,根据前人的经验,问题终于解决了。总结一下,方便以后使用。

原因:这个问题应该是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName。所以apache会用主机上的名称来取代,首先会去找 /etc/hosts 中有没有主机的定义。

解决办法:

(1)可以设定httpd.conf文件中的 ServerName,如下:ServerName localhost:80                        

(2)在 /etc/hosts 中填入自己的主机名称 bogon,如下:127.0.0.1 shiwei (用户名称)

问题3 NRPE: Unable to read output

我的解决办法是:修改nagios目录的权限

#chown -R nagios:nagios nagios/

#chmod -R 775 nagios/

问题解决。linux

四、添加command 

command[check_cpu]=/usr/local/nagios/libexec/check_cpu_pct -w $ARG1$ -c $ARG2$

command[check_memory]=/usr/local/nagios/libexec/check_mem -w $ARG1$ -c $ARG2$

将配置文件拷贝到指定目录后,修改所属及访问权限。

command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$

command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$228 

command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$

command[check_io]=/usr/local/nagios/libexec/check_iostat -d $ARG3$ -w $ARG1$ -c $ARG2$

五、安装sendmail

首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:

# yum install -y sendmail*

然后重新启动sendmail服务:

# service sendmail restart

然后发送测试邮件,验证sendmail的可用性:

# echo "Hello World" | mail abc@abc.com

Root@Nagios objects]# service sendmail restart

Shutting down sendmail:                                    [FAILED]

Starting sendmail:                                         [  OK  ]

Starting sm-client:                                        [  OK  ]

chkconfig sendmail off

chkconfig sendmail off  加速开机时间

重启服务器注意1,开机nrpe 二启动sendmail 三 iptables 设置

Nagios 多用户的一些配置

刚开始我想到在搭nagios的时候,用户验证是用apache来做的,接到这个需求后的第一反应是这个东西可能做不了。但接着一想,不应该啊,nagios本身至少会有一些用户配置的吧,于是乎开始寻找相关资料,基本配置如下:

     

   (1)新增一个apache用户,如qiuyuetao

     [root@service3F-38 ~]# htpasswd /usr/local/nagios/etc/htpasswd.users  qiuyuetao

   (2)更改cgi.cfg配置

     [root@service3F-38 ~]# vi /usr/local/nagios/etc/cgi.cfg

     use_authentication=1

     如果只允许查看,不允许管理,加上下面配置

authorized_for_read_only=qiuyuetao

authorized_for_all_services=qiuyuetao

authorized_for_all_hosts=qiuyuetao

   (3)将userA设为联系人

     [root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/contacts.cfg  #添加如下配置

      define contact{

                     contact_name                   qiuyuetao

                     use                                      generic-contact

                    alias                                     qyt

            }

        (4)在属于userA的主机、服务配置文件的联系人中加入qiuyuetao

         [root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/hosts.cfg

           define host {

              host_name web02-1.22@sh

              alias web02-1.22@sh

              address 10.1.1.22

              contacs qyt

              contact_groups sys_admins

              check_command check-host-alive

              max_check_attempts 5

              notification_interval  3

              notification_period 24x7

              notification_options d,u,r

           }

      (5)重启nagios后生效

        [root@service3F-38 ~]#  /etc/init.d/nagios restart


标题名称:Centos6.5-----nagios快速安装编译配置文档-全部虚拟环境
标题URL:http://cdkjz.cn/article/pcicoh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220