《Nagios可视化插件开发》—19/2/18——监控主机的公有服务和私有服务

公有服务思路

  1.     在/usr/local/nagios/etc/objects目录下编写对象文件
  2.     在/usr/local/nagios/etc/nagios.cfg文件里指定刚编写的对象文件
  3.     重启Nagios测试验证

监控远程主机的私有服务

  1.     重新编写xxx.cfg文件,或者直接放到上面创建的remote.cfg文件里
  2.     下面定义的命令比如check_remote_root,是被监控主机上的命令,监控机可以调用它

 

监控端

  •  vim  /usr/local/nagios/etc/objects/remote.cfg    //先定义需要监控的对象主机(放在脚本里要删除)
  • define host{
  •   use                    linux-server
  •   host_name                    172.16.5.127                //主机名,最好是/etc/hosts里对应的IP(放在脚本里要删除)
  •   alias                    172.16.5.127                   //显示web上的名字(放在脚本里要删除)
  •   address                    172.16.5.127                   //实际监控的主机IP          (放在脚本里要删除)
  • }

//以下定义一个主机组,方便监控相同服务(放在脚本里要删除)

  • define hostgroup{
  •   hostgroup_name                   remote linux-servers
  •   alias                    remote Linux Servers
  •   merbers                    172.16.5.127
  • }

//以下定义要监控主机的哪些服务(放在脚本里要删除)

  • define service{
  •         use                          local-service
  •         hostgroup_name               remote linux-servers
  •         service_description          PING
  •         check_command                check_ping!100.0,20%!500.0,60%
  •         }

 

  • define service{
  •         use                          local-service
  •         hostgroup_name               remote linux-servers
  •         service_description          HTTP
  •         check_command                check_http
  •         }

//在nagios.cfg中添加路径(放在脚本里要删除)

  • vim /usr/local/nagios/etc/nagios.cfg
  • cfg_file=/usr/local/nagios/etc/objects/remote.cfg

//重启服务

  • service nagios restart

//远程监控主机时监控机需要修改配置文件

  • vim remote.cfg
  • define service{
  •          use                     local-service
  •          host_name               172.16.5.127
  •          service_description     Root Partition
  •          check_command           check_nrpe!check_remote_root
  •          }

 

  • define service{
  •          use                     local-service
  •          host_name               172.16.5.127
  •          service_description     Current Users
  •          check_command           check_nrpe!check_remote_users
  •          }

 

  • define service{
  •          use                     local-service
  •          host_name               172.16.5.127
  •          service_description     Total Processes
  •          check_command           check_nrpe!check_remote_total_procs
  •          }

 

  • define service{
  •          use                     local-service
  •          host_name               172.16.5.127
  •          service_description     Current Load
  •          check_command           check_nrpe!check_remote_load
  •          }

 

  • efine service{
  •          use                     local-service
  •          host_name               172.16.5.127
  •          service_description     Swap Usage
  •          check_command           check_nrpe!check_remote_swap
  •          }

//在command.cfg上添加nrpe的命令

  • vim command.cfg
  • define command{
  •   command_name                    check_nrpe
  •   command_line                    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  •   }

 

被监控端

  下载软件安装包

  •     nrpe插件

    http://sourceforge.net/projects/nagios/files/nrpe-2.x/ 或 wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

  •     插件包

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

  创建用户和用户组

  •     useradd nagios
  •     groupadd nagiosgroup
  •     usermod -G nagiosgroup nagios

  解压plugin安装包

  •     tar -xf nagios-plugins-2.0.3.tar.gz
  •     cd nagios-plugins-2.0.3
  •     ./configure
  •     make && make install

  解压nrpe软件包

  •     tar -xf nrpe-2.15.tar.gz
  •     cd nrpe-2.15
  •    ./configure --enable-command-args
  •     make all
  •     make install-plugin
  •     make install-daemon
  •     make install-daemon-config
  •     make install-xinetd

  配置文件

  •     vim /etc/xinetd.d/nrpe
  •     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       = 127.0.0.1 172.16.5.128  //加上nagios服务器的IP,允许它来访问
  •     }
  •   vim /etc/services--配置文件
  •     nrpe                     5666/tcp                          #NRPE

  vim nrpe.cfg--添加以下命令

  •     command[check_remote_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  •     command[check_remote_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  •     command[check_remote_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda2
  •     command[check_remote_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
  •     command[check_remote_swap]=/usr/local/nagios/libexec/check_swap -w 40%% -c 20%%

  下载xinetd

  •     yum -y install xinetd
  •     service xinetd start
  •     netstat -nltp | grep xinetd

  测试--被监控机

  •     /usr/local/nagios/libexec/check_users  -w 5 -c 10

  测试--监控机

  •     /usr/local/nagios/libexec/check_nrpe -H 172.16.5.127 -c check_remote_users

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值