namedhao 发表于 2019-1-14 10:44:39

nagios 监控linux 主机

  1.解决时间同步问题
当然前提是你的服务器已经安装了ntp的程序,如果没有安装可以:
yum -y install ntp
/usr/sbin/ntpdate pool.ntp.org
  uptime
  2.安装Nagios所需要的基础包
yum -y install gcc glibc glibc-common
yum -y install gd gd-devdel
  yum -y install openssl-devel
  3.创建nagios 用户
  useradd nagios
  4.下载安装最新nagios插件

  wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
  tar zxvf nagios-plugins-1.5.tar.gz
  cd nagios-plugins-1.5
  ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  make && make install
  5.更改目录权限:

    chown nagios.nagios /usr/local/nagios
   chown -R nagios.nagios /usr/local/nagios/libexec
6.安装nrpe插件
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download
tar zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
http://blog.运维网.com/attachment/201311/150236626.jpg
make all
make install-plugin
make install-daemon

make install-daemon-config


7.将NRPE deamon作为xinetd 下的一个服务运行
   yum -y install xinetd
   make install-xinetd
显示如下
http://blog.运维网.com/attachment/201311/150758110.jpg
可以看到创建了这个文件/etc/xinetd.d/nrpe,编辑这个脚本:
   vim /etc/xinetd.d/nrpe
http://blog.运维网.com/attachment/201311/151001131.jpg
8.编辑/etc/services这个文件,添加nrpe服务
   vim /etc/services
在最后添加如下:
  #Local services
  nrpe 5666/tcp         #nrpe
  



  重启xinetd的服务:
  service xinetd restart
查看nrpe是否已经启动:


  # netstat -at |grep nrpe
  tcp      0      0 *:nrpe                      *:*                         LISTEN
  # netstat -an |grep 5666
  tcp      0      0 :::5666                     :::*                        LIST
查看nrpe 是否正常工作 

  /usr/local/nagios/libexec/check_nrpe -H localhost
  

  8.查看nrpe的监控命令:
  
  vim /usr/local/nagios/etc/nrpe.cfg
http://blog.运维网.com/attachment/201311/163932486.jpg
  上面这5行定义的命令分别是检测登陆用户数,cpu负载,sda1的容量,僵尸进程,总进程数
  

  9.配置监控端:
  先安装openssl-devel
  yum -y install openssl-devel
  安装nrpe
  tar -zxvf nrpe-2.8.1.tar.gz
  cd nrpe-2.8.1
  ./configure --enable-ssl --with-ssl-lib=/usr/lib/
  make all
  make install-plugin
  只运行之一步就行了,因为只需要check_nrpe这个插件
  测试与被监控机的通信:
        /usr/local/nagios/libexec/check_nrpe -H 192.168.1.243
  返回nrpe的版本说明通信正常
  


10.在command.cfg里添加外部构件nrpe
   vi /usr/local/nagios/etc/objects/commands.cfg
    添加
   #check nrpe
   define command{
      command_name check_nrpe
      command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
      }
配置被监控主机:

  vim /usr/local/nagios/etc/nagios.cfg
  添加:
        cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg

  
  11.配置mylinux.cfg
  cd /usr/local/nagios/etc/objects/
  touch mylinux.cfg
  chown nagios.nagios mylinux.cfg
  vim mylinux.cfg
  写入如下:
  define host{
          use             linux-server
          host_name   mylinux
          alias            mylinux
          address      192.168.1.243
      }
define service{
      use                      generic-service
      host_name             mylinux
      service_description   HTTP
      check_command       check_http
       }
define service{
      use                      generic-service
      host_name             mylinux
      service_description   SSH
      check_command       check_ssh
       }
define service{
      use                      generic-service
      host_name             mylinux
      service_description   check-swap
      check_command      check_nrpe!check_swap
               }
define service{
      use                      generic-service
      host_name             mylinux
      service_description   check-load
       check_command         check_nrpe!check_load
               }
define service{
      use                      generic-service
      host_name             mylinux
       service_description   check-disk
       check_command      check_nrpe!check_disk
}
define service{
       use                      generic-service
      host_name             mylinux
       service_description   check-users
       check_command      check_nrpe!check_users
               }
define service{
      use                  generic-service
      host_name         mylinux
      service_descriptionotal_procs
      check_command   check_nrpe!check_total_procs
             }
  检查配置文件是否错误:
      /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

  http://blog.运维网.com/attachment/201311/112604631.jpg
  12.重启nagios: service nagios restart

  13.查看web

  http://blog.运维网.com/attachment/201311/112733939.jpg
  完成!
  

  

  

  

  

  




页: [1]
查看完整版本: nagios 监控linux 主机