sdfouhdso888 发表于 2019-1-12 14:19:17

Centos7上yum安装nagios

  本次安装未加入客户端,就是配置本机成为监控对象

一、nagios简介
    Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
   Nagios 可以监控的功能有:
1
2
3
4
5
6
7
8
9
10
11
1、监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
2、监控主机资源(处理器负荷、磁盘利用率等);
3、简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
4、并行服务检查机制;
5、具备定义网络分层结构的能力,用"parent"主机定义来表达网络主机间的关系,
   这种关系可被用来发现和明晰主机宕机或不可达状态;
6、当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
7、具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;
8、自动的日志回滚;
9、可以支持并实现对主机的冗余监控;
10、可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等。
  二、安装Nagios基础支持套件和添加用户
  

1).创建nagios用户和用户组(先进行该步骤,不然编译nagios时会报错)
1
2
# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios# chown -R nagios.nagios /usr/local/nagios
2).安装httpd和php
1
2
# yum install httpd*    ##安装Web服务器Apache相关服务,nagios提供了web监控界面,通过web                           界面可以看到被监控主机运行状态
# yum install php*      ##安装PHP相关服务
  三、安装Nagios
                yum -y install nagiosnagios-plugins   nagios-snmp-plugins
               chkconfig --add   nagios   
               chkconfig nagios on  1)添加管理账号nagcmd,并将apache,nagios都加入nagcmd用户组;将apache加入nagios用户组,并且更改nagios目录属主属组。
useradd -s /sbin/nologin   nagcmd
usermod-G    nagcmd nagios
usermod-G    nagcmd apache
usermod-G    nagios    apache
chown   -R    nagios.nagcmd/usr/share/nagios/html/*  2)这里我们的php是直接安装的php;这里php与httpd是通过模块的方式连接
yum -y install httpd php*  
1)这里还是需要对/etc/httpd/conf.d/nagios.conf进行一下编辑,根据系统版本进行更改,我这里是CentOS7-2,列出配置
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.Customize the paths, etc. as
# needed to fit your system.
ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/"

#SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
    require valid-user
   
      # Apache 2.4
      
      #   Require all granted
         # Require local
         Require valid-user
      
   
   
      # Apache 2.2
   # Order allow,deny
   # Allow from all
      #Order deny,allow
      #Deny from all
      #Allow from 127.0.0.1
      Require valid-user
   

Alias /nagios "/usr/share/nagios/html"
#proxyrequests off
#proxypassmatch ^/(.*\.php)$fcgi://127.0.0.1:9000/usr/share/nagios/html/$1

#SSLRequireSSL
   Options None
   AllowOverride None
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   require valid-user
   
      # Apache 2.4
      
      #   Require all granted
         # Require local
         Require valid-user
      
   
   
      # Apache 2.2
   # Order allow,deny
   # Allow from all
      #Order deny,allow
      #Deny from all
      #Allow from 127.0.0.1
      Require valid-user
   


3).关闭SELinux和防火墙:
a、临时关闭(不用重启机器):
1
2
# setenforce 0                     ##设置SELinux 成为permissive模式(关闭SELinux)
# setenforce 1                     ##设置SELinux 成为enforcing模式   (开启SELinux)
  
b、修改配置文件需要重启机器:
1
# vi /etc/selinux/config
  

4).验证程序是否配置正确
1
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  5)这里创建登录用户
htpasswd -c-m/etc/nagios/passwd   sjf       (Enter输入密码)  
6).启用服务并进入nagios
1
2
3
# systemctl start httpd.service
# systemctl start snmpd.service
# systemctl start nagios.service
http://s1.运维网.com/wyfs02/M01/8A/6D/wKiom1gvEiqx-URTAALGW8HQfOs546.png-wh_500x0-wm_3-wmp_4-s_2211943475.png
  

  四、这里的安装就完成了
  由于时间有限,这里就不演示图形界面pnp4nagios插件的演示了,这个有机会可以给大家展示nagios的使用。
  

  

  





页: [1]
查看完整版本: Centos7上yum安装nagios