资讯

精准传达 • 有效沟通

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

搭建nagios监控步骤-创新互联

1、实验环境:

创新互联是一家专业提供南芬企业网站建设,专注与成都做网站、成都网站制作、H5响应式网站、小程序制作等业务。10年已为南芬众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

主机名:       ip        需要的软件环境

nagios-server   192.168.124.143    Apache、Php、Nagios、nagios-plugins、nrpe

nagios-linux    192.168.124.203   nagios-plugins、nrpe

监控机 nagios-server上需要 安装nagios软件,对监控的数据做处理,并且提供 web界面查看和管理。当然也对本机自身的信息进行监控;

被监控机 nagios-linux需安装NRPE及nagios plugins,根据监控机的请求执行监 控,然后将结果回传给监控机;

一、Nagios监控机(192.168.124.143)上的环境准备

   1、 安装编译环境

   使用yum安装

   [root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel

   2、 创建nagios用户和用户组

   [root@localhost ~]#useradd -s /sbin/nologin nagios

   [root@localhost ~]#mkdir /usr/local/nagios

   [root@localhost ~]#chown -R nagios:nagios /usr/local/nagios

   3、 yum安装httpd和php,并配置httpd支持php

      只要能实现浏览器能正常访问 http://本机IP/index.php 既可

   4、 编译安装nagios

   上传nagios源码包至/root目录下

   [root@localhost ~]#tar zxvf nagios-4.0.3.tar.gz

   [root@localhost ~]#cd nagios-4.0.3

   [root@localhost ~]#./configure --prefix=/usr/local/nagios --with-nagiosuser=nagios --with-nagios-group=nagios

   [root@localhost ~]#make all

   [root@localhost ~]#make install

   [root@localhost ~]#make install-init

   [root@localhost ~]#make install-commandmode

   [root@localhost ~]#make install-config

   [root@localhost ~]#make install-webconf

   [root@localhost ~]#chkconfig --add nagios              #    将nagios加入系统 服务

   [root@localhost ~]#chkconfig nagios on

   5、 验证nagios是否被正确安装

     切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、 libexec、sbin、share、var  这些目录,如果存在则可以表明程序被正确的安装到 系统了。

     Nagios 各个目录用途说明如下:

   目录名       用途

  bin Nagios    可执行程序所在目录

  etc Nagios    配置文件所在目录

  sbin      Nagios CGI文件所在目录,也就是执行外部命令所需文件所在的目录    share      Nagios网页文件所在的目录

  libexec     Nagios 外部插件所在目录

  var Nagios     日志文件、lock 等文件所在的目录

  var/archives    Nagios 日志自动归档目录

  var/rw       用来存放外部命令文件的目录

   6、 安装nagios插件

     上传nagios-plugins-1.5.tar.gz至/root目录下

     [root@localhost ~]#tar zxvf nagios-plugins-1.5.tar.gz

     [root@localhost ~]#cd nagios-plugins-1.5

    [root@localhost ~]#./configure --prefix=/usr/local/nagios --with-mysql --with-nagios-user=nagios --with-nagiosgroup=nagios

     [root@localhost ~]#make && make install

   备注:

   --with-mysql 使nagios插件支持监控mysql(系统要先yum安装好 mysql-devel软件包),在libexec目录下会有 check_mysql和check_mysql_query命令

   7、 安装check_nrpe插件

     上传nrpe-2.12.tar.gz至/root目录下

    [root@localhost ~]#tar zxvf nrpe-2.12.tar.gz

     [root@localhost ~]#cd nrpe-2.12

     [root@localhost ~]#./configure --with-nrpe-user=nagios    --with-nrpe-group=nagios    --with-nagiosuser=nagios    --with-nagios-group=nagios    --enable-command-args    --enable-ssl

     [root@localhost ~]#make all

     [root@localhost ~]#make  install-plugin

   监控机上只运行到这一步就行,因为只需要nrpe中的check_nrpe插件

   8、 修改apache的配置文件/etc/httpd/conf/httpd.conf

    [root@localhost ~]#vim /etc/httpd/conf/httpd.conf

     User apache修改为User nagios

      Group apache修改为Group nagios

     DirectoryIndex index.html修改为DirectoryIndex index.php

     保存

   9、 为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问        编译安装nagios 4.0.3版本完成后,已自动配置httpd并设定了默认的htpasswd验证文件          /usr/local/nagios/etc/ htpasswd.users

      [root@localhost ~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin              #指定用户 nagiosadmin可以访问

   10、 启动httpd服务

      [root@localhost ~]#service httpd restart

      [root@localhost ~]#service nagios start

   11、 浏览器访问nagios站点

    http://192.168.124.143/nagios

  二、被监控机(192.168.124.203)安装nrpe及nagios-plugins

   1、 安装编译环境

     使用yum安装

     [root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel

   2、 编译安装nagios插件

   上传nagios-plugins-1.5.tar.gz至/root目录下

     [root@localhost ~]#tar -zxvf nagios-plugins-1.5.tar.gz

     [root@localhost ~]#cd nagios-plugins-1.5

     [root@localhost ~]#./configure  --with-mysql --with-nagios-user=nagios --with-nagios-group=nagios

     [root@localhost ~]#make && make install

   这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share,修改目录权限       [root@localhost ~]#useradd -s /sbin/nologin nagios

    [root@localhost ~]#chown  -R nagios:nagios /usr/local/nagios

   3、 编译安装nrpe

  上传nrpe-2.12.tar.gz至/root目录下

     [root@localhost ~]#tar -zxvf nrpe-2.12.tar.gz

     [root@localhost ~]#cd nrpe-2.12

     [root@localhost ~]#./configure --with-nrpe-user=nagios    --with-nrpe-group=nagios    --with-nagiosuser=nagios    --with-nagios-group=nagios    --enable-command-args    --enable-ssl

    [root@localhost ~]#make all

    [root@localhost ~]#make install-plugin

    [root@localhost ~]#make install-daemon

    [root@localhost ~]#make install-daemon-config

   #现在再查看/usr/local/nagios 目录就会发现有4个子目录

     [root@localhost ~]#make install-xinetd

     [root@localhost ~]#vim /etc/xinetd.d/nrpe

        修改在末尾项 only_from   = 192.168.124.0/24

        这里设置允许监控机所在的网段访问

    [root@localhost ~]#vim /etc/services

   #编辑/etc/services 文件,末尾增加NRPE服务内容

         在最后添加  nrpe   5666/tcp  #nrpe

    [root@localhost ~]#service xinetd restart

     [root@localhost ~]#netstat -ntulp|grep 5666

    #查看nrpe是否已启动并监听5666端口

   4、 测试nrpe是否正常工作

  在监控机(192.168.124.143)执行check_nrpe这个插件来测试与被监控机(192.168.124.203)的通讯

      [root@localhost ~]#/usr/local/nagios/libexec/check_nrpe -H 192.168.124.203        如显示   NRPE V2.12  ,则nrpe通讯正常

  三、监控机(192.168.124.143)上的配置

   1、 在commands.cfg文件末尾增加check_nrpe的定义

    [root@localhost ~]#vim /usr/local/nagios/etc/objects/commands.cfg

    #添加如下 代码

   define command{

       command_name   check_nrpe

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

    2、 定义对Nagios-Linux 主机的监控,创建nagios_linux.cfg文件并加入以下 代码内容

     [root@localhost ~]#vim /usr/local/nagios/etc/objects/nagios_linux.cfg

   define host{

     use       linux-server

     host_name     nagios-linux

     alias       nagios-linux

     address      192.168.124.67         #此处设置被监控机的IP地址       }

   define service{      #添加监控CPU负载的服务

     use         local-service

     host_name       nagios-linux

     service_description  CPU Load

      check_command     check_nrpe!check_load

         }

   define service{       #添加监控总进程数的服务

     use       local-service

     host_name     nagios-linux

     service_description  Total Processes

     check_command    check_nrpe!check_total_procs

         }

   上述代码分别定义了CPU Load(cpu负载)以及Total Processes(总进程数)的监 控服务,还可以在此文件中增加其他的监控服务

   3、 在nagios的主配置文件nagios.cfg末尾增加如下代码内容

    [root@localhost ~]#vim /usr/local/nagios/etc/nagios.cfg

   cfg_file=/usr/local/nagios/etc/objects/nagios_linux.cfg

   #在nagios的主配置文件中增 加被监控机的配置文件

   4、 重启各项服务

    [root@localhost ~]#service httpd restart

    [root@localhost ~]#service nagios restart

   5、 验证nagios是否能监控到本机(localhost)以及被监控机nagios-linux

         http://ip/nagios

   6、[root@localhost ~]#service httpd restart

    [root@localhost ~]#service nagios restart

    #重启验证新增的监控信息

ok!到此结束!希望对你有所帮助

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:搭建nagios监控步骤-创新互联
URL标题:http://cdkjz.cn/article/ccgeic.html
多年建站经验

多一份参考,总有益处

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

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

大客户专线   成都:13518219792   座机:028-86922220