Nagios配置安装详解

 

nagios.html

Nagios监控服务

nagios监控的主要内容:

  1. 本地资源:负载uptime,CPU(top,sar),磁盘(df),内存(free),io,raid级别,温度,passwd文件的变化,本地所有文件指纹识别
  2. 网络服务:端口,URL,丢包,进程数,网络流量
  3. 其他设备:交换机端口流量,路由器,打印机,windows等
  4. 业务数据:用户登陆失败次数,用户登陆网站次数,输入验证码失败次数,某个API接口流量并发,网站订单,支付交易数量
  5. 监控软件本身仅仅是一个平台,我们想监控的内容,理论上只要在服务器命令行可以获取到就可以被监控软件监控

nagios主要功能

  • 网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)
  • 主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)
  • 可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)
  • 可以通过配置Nagios远程执行插件远程执行脚本
  • 远程监控支持SSH或SSL加通道方式进行监控
  • 简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)
  • 包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)
  • 可并行服务检查
  • 能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查
  • 当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知
  • 能够自定义事件处理机制重新激活出问题的服务或主机
  • 自动日志循环
  • 支持冗余监控
  • 包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等

nagios主要组成部分

主程序Nagios+插件Nagios-plugins和一些可选的附加程序(NRPE、NSClient++、NSCA)等

  • 服务器端必须安装nagios主程序和nagios-plugins
  • 客户端必须安装nagios-plugins
  • NRPE半被动模式:工作于被监控端,用于在被监控的远程linux主机上执行脚本插件获取数据回传给监控端,以实现对这些主机资源的监控,守护进程开启端口5666

NRPE运行原理


Nagios 通过NRPE 来远端管理服务

  1. Nagios 执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。

  2. 通过SSL,check_nrpe 连接远端机子上的NRPE daemon

  3. NRPE 运行本地的各种插件去检测本地的服务和状态(check_disk,..etc)

  4. 最后,NRPE 把检测的结果传给主机端的check_nrpe,check_nrpe 再把结果送到Nagios状态队列中。

  5. Nagios 依次读取队列中的信息,再把结果显示出来。

nagios服务端安装

安装部署LAMP环境
[root@localhost ~]# yum install gcc php httpd php-gd gd gd-devel mysql* -y
ntpdate统一系统时间
[root@localhost ~]# ntpdate cn.pool.ntp.org
 2 Aug 21:34:56 ntpdate[1533]: step time server 110.75.186.249 offset 2631012.350036 sec
安装nagios的相关依赖库文件
[root@localhost ~]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel unzip
创建安装目录和用户组并且授权

(因为nagios配置文件中默认安装目录是/usr/local/nagios为了避免不必要的修改)

[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# useradd nagios -s /sbin/nologin -M
[root@localhost ~]# chown nagios:nagios /usr/local/nagios/
[root@localhost ~]# ll -d /usr/local/nagios/
drwxr-xr-x 2 nagios nagios 4096 Jul  3 10:41 /usr/local/nagios/
编译安装nagios
[root@localhost ~]# tar zxvf nagios-4.2.0.tar.gz
[root@localhost nagios-4.2.0]# ./configure --prefix=/usr/local/nagios/
*** Configuration summary for nagios 4.2.0 08-01-2016 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

[root@localhost nagios-4.2.0]# make all  #此过程中报错记得安装unzip
*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install
     - This installs the main program, CGIs, and HTML files

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

  make install-exfoliation
     - This installs the Exfoliation theme for the Nagios
       web interface

  make install-classicui
     - This installs the classic theme for the Nagios
       web interface

###### 整个安装过程如下:
     ./configure --prefix=/usr/local/nagios/
     make all
     make all
     make install
     make install-init
     make install-commandmode
     make install-config
     make install-webconf
检查是否生成了对应httpd的web配置文件
[root@localhost ~]# ls -al /etc/httpd/conf.d/
total 24
drwxr-xr-x 2 root root 4096 Aug  2 21:41 .
drwxr-xr-x 4 root root 4096 Jul  3 10:37 ..
-rw-r--r-- 1 root root 1679 Aug  2 21:41 nagios.conf
-rw-r--r-- 1 root root  674 May 10 17:42 php.conf
-rw-r--r-- 1 root root  392 May 11 15:29 README
-rw-r--r-- 1 root root  299 Feb  4 02:40 welcome.conf
查看nagios.conf文件确认需要创建网站登陆用户和密码文件

登陆名最好设置为nagios默认的nagiosadmin,文件为htpasswd.users

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

# 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/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted
#        Require host 127.0.0.1

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>

[root@localhost ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin
安装nagios-plugin
     tar zxvf nagios-plugins-2.1.2.tar.gz 
     cd nagios--p
     cd nagios-plugins-2.1.2
     ./configure --prefix=/usr/local/nagios/
     make && make install
启动nagios服务和httpd服务
[root@localhost ~]# /etc/init.d/httpd start
[root@localhost ~]# /etc/init.d/nagios start
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig nagios on

登陆网页localhost/nagios输入用户名和密码进入网站

NRPE服务安装

编译安装
 ./configure
 make all
 make install-plugin
 make install-daemon
 make install-daemon-config
 make install-xinetd
修改守护进程

在only from处添加监控主机的IP地址

[root@localhost nrpe-2.13]# vim /etc/xinetd.d/nrpe 
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
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,192.168.10.7
}
在/etc/services中添加nrpe和端口号

确认已经监听5666端口,服务端安装nrpe不需要添加主机ip,客户机需要添加主机ip
[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      26483/xinetd

nagios客户端安装配置

安装依赖文件
[root@server2 ~]# yum install gcc openssl openssl-devel xinetd unzip -y
服务器时间同步
[root@server2 ~]# ntpdate cn.pool.ntp.org
 2 Aug 22:18:37 ntpdate[1466]: step time server 120.25.108.11 offset 146310.412101 sec
创建安装路径和用户
[root@server2 ~]# mkdir /usr/local/nagios
[root@server2 ~]# useradd nagios -s /sbin/nologin -M
[root@server2 ~]# chown nagios:nagios /usr/local/nagios/
[root@server2 ~]# ll -d /usr/local/nagios/
drwxr-xr-x 2 nagios nagios 4096 Aug  2 22:19 /usr/local/nagios/
安装nagios-plugins
[root@server2 nagios-plugins-2.1.2]# tar zxvf nagios-plugins-2.1.2.tar.gz
[root@server2 nagios-plugins-2.1.2]# cd nagios-plugins-2.1.2
[root@server2 nagios-plugins-2.1.2]# ./configure --prefix=/usr/local/nagios/
[root@server2 nagios-plugins-2.1.2]# make && make install
编译安装NRPE
 ./configure
 make all
 make install-plugin
 make install-daemon
 make install-daemon-config
 make install-xinetd
修改守护进程

在only from处添加监控主机的IP地址

[root@localhost nrpe-2.13]# vim /etc/xinetd.d/nrpe 
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
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       = 192.168.10.7
}
在/etc/services中添加nrpe和端口号

确认已经监听5666端口,服务端安装nrpe不需要添加主机ip,客户机需要添加主机ip
[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      26483/xinetd

generated by haroopad

转载于:https://www.cnblogs.com/zhangsubai/p/5732081.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nagios安装配置可以按照以下步骤进行: 1. 首先,确保你的系统是Linux或者其他Nagios支持的系统。此外,安装Nagios之前,你需要安装Apache(http服务),因为它提供了一个直观的界面来查看监控信息。你可以在网上找到关于Apache的安装教程。 2. 安装完Apache之后,你需要下载Nagios安装包并解压。你可以从Nagios官方网站下载最新的稳定版本。 3. 解压后,进入解压后的目录,执行以下命令来编译和安装Nagios: ``` ./configure --with-command-group=nagcmd make all sudo make install sudo make install-init sudo make install-config sudo make install-commandmode ``` 4. 安装完成后,你需要进行一些配置。首先,你需要编辑Nagios配置文件,该文件位于`/usr/local/nagios/etc`目录下。你可以使用官方提供的示例配置文件作为起点,该文件已经安装在该目录下。你只需要做一处修改,即将`cfg_dir`的值设置为你自己的配置文件目录。 5. 接下来,你需要创建你自己的配置文件目录,并在该目录下创建你的主机和服务配置文件。你可以参考官方文档或者其他教程来了解如何编写这些配置文件。 6. 配置文件准备好后,你需要检查配置文件是否正确。你可以使用以下命令来检查配置文件: ``` sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ``` 7. 如果没有错误,你可以启动Nagios服务: ``` sudo service nagios start ``` 8. 现在,你可以通过浏览器访问Nagios的Web界面,输入你的服务器的IP地址或域名,然后登录。你将能够查看监控信息和配置监控项。 这是一个简单的Nagios安装配置的步骤概述。具体的安装配置细节可能会因系统版本和个人需求而有所不同。你可以参考Nagios官方文档和其他教程来获取更详细的信息和指导。 #### 引用[.reference_title] - *1* *3* [nagios安装配置详解1](https://blog.csdn.net/weixin_34138139/article/details/92970215)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [nagios安装配置](https://blog.csdn.net/giveme38/article/details/84524806)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值