12343052 发表于 2019-1-14 07:44:53

nagios系列-----通过yum安装Nagios

  通过yum安装Nagios
  前提先自行安装好Apache+php
  测试环境
  主监控机:CentOS 6.0
  被监控机:CentOS 6.2
  主监控机设置:
  1、安装epel
  # cat /etc/issue

  CentOS>  Kernel \r on an \m
  # rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm   这里应该对应你服务器的版本
  2、安装nagios、nagios-plugin与nrpe (nagios 3.3.1版本)
  # yum install nagios nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
  3、创建一个nagiosadmin 的用户用于Nagios的WEB接口登录,用户认证配置
  adduser nagiosadmin
  cd /usr/local/
  mkdir nagios
  cd nagios
  mkdir etc
  # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  New password:
  Re-type new password:
  Adding password for user nagiosadmin
  4、修改nagios.conf
  修改保存用户密码文件
  vi /etc/httpd/conf.d/nagios.conf
  AuthUserFile /etc/nagios/passwd 修改成–> AuthUserFile /etc/nagios/htpasswd.users
  保存退出
  5、修改cgi.cfg文件,找到use_authentication=1 这行,把1改成0
  find -name cgi.cfg -print    查找
  vi/etc/nagios/cgi.cfg
  6、启动apache与nagios
  # /etc/init.d/httpd restart
  # /etc/init.d/nagios start
  7、登陆http://localhost/nagios/,输入用户密码后查看是否正常运行
  注:别忘记了nagios后面那个/,不然……
  被监控机设置:
  1、安装需要软件
  # yum install nagios-plugins nagios-plugins-nrpe nrpe
  2、配置nrpe
  # vi /etc/nagios/nrpe.cfg 修改监控机的地址或域名
  allowed_hosts=127.0.0.1,192.168.5.11
  3、修改/etc/hosts.allow增加监控机ip
  # echo ‘nrpe:192.168.5.22′ >> /etc/hosts.allow
  4、检查 NRPE 是否正常:
  # /usr/lib/nagios/plugins/check_nrpe -H 192.168.5.11
  NRPE v2.12
  查看相应的端口:netstat -an |grep 5666
  防火墙开启5666 允许局域网IP或固定IP连接
  5、启动 NRPE 守护进程:
  # /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
  在回到监控机:
  添加nrpe的定义
  # vi commands.cfg
  # ‘check_nrpe’ command definition
  define command{
  command_name check_nrpe
  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  }
  增加主机监控配置项11.cfg
  define host{
  use linux-server
  host_name 192.168.5.11
  alias 192.168.5.11
  address 192.168.5.11
  }
  define service{
  use generic-service
  host_name 192.168.5.11
  service_description load
  check_command check_nrpe!check_load
  }
  define service{
  use generic-service
  host_name 192.168.5.11
  service_description PING
  check_command check_ping!100.0,20%!200.0,50%
  max_check_attempts 5
  normal_check_interval 1
  }
  define service{
  use generic-service
  host_name 192.168.5.11
  service_description FTP
  check_command check_ftp!21
  max_check_attempts 5
  normal_check_interval 1
  }
  define service{
  use generic-service
  host_name 192.168.5.11
  service_description SSH
  check_command check_ssh
  max_check_attempts 5
  normal_check_interval 1
  }
  define service{
  use generic-service
  host_name 192.168.5.11
  service_description HTTP
  check_command check_http
  max_check_attempts 5
  normal_check_interval 1
  }
  并把11.cfg添加到nagios主配置项
  # echo “cfg_file=/etc/nagios/objects/11.cfg” >> /etc/nagios/nagios.cfg
  其他机器如法炮制即可
  重启监控机nagios查看效果,关于短信通知参考另外一篇文章http://hi.baidu.com/yuanzelin8/blog/item/3b0bf2161010e771f2de3278.html
  #Linux

页: [1]
查看完整版本: nagios系列-----通过yum安装Nagios