Nagios简记

发表于 2023-05-10  889 次阅读


作者:Scanz

更新版本:V1(20170114初版,待更新格式)

----------------------------------------------

       什么是监控?

              监控 并 控制

       监控谁?

              服务器

       监控什么?

              1.硬件使用率

                     1)CPU

                     2)a内存

                     3)a存储

              2.系统运行情况

                     1)a进程数

                     2)a用户数

              3.服务的运行状态(停止 运行)

                     1)a停止

                     2)a运行

              4.网络接口流量

       如何监控?

              系统命令:

                     uptime top free iostat

                     ps aux | wc -l

                     users

                     service httpd status

              计划任务+脚本

搭建监控服务器(Nagios Cati Zabbix)

              1.部署监控服务的运行环境

              2.配置监控服务(修改服务的配置文件)

                     2.1监控本机

                     2.2监控远端主机

              3.启动监控服务

              4.查看监控信息

              5.监控报警(邮件 短信 微信)

       搭建Nagios监控服务器

              1.

                     yum -y install httpd php

                     /etc/init.d/httpd start

                     chkconfig httpd on

              2.装包

                     yum -y install gcc gcc-c++

                     useradd nagios

                     groupadd nagcmd

                     usermod -G nagcmd nagios

                     tar -xf nagios-3.2.1.tar.gz -C ./

                     cd nagios-3.2.1

                     ./configure \

                     --with-nagios-user=nagios \

                     --with-nagios-group=nagcmd \

                     --with-command-user=nagios \

                     --with-command-group=nagcmd \

                     make all

                     make install

                     make install-init          启动脚本

                     make install-commandmode   配置文件

                     make install-config

                     make install-webconf

                     bin           可执行命令

                     etc           配置文件

                     libexec       监控插件(nagios软件提供的监控命令)

                     sbin   cgi脚本文件

                     share  网页文件

                     var    变化文件

              3.安装监控插件

                     tar -xf nagios-plugins-1.4.14.tar.gz -C ./

                     cd nagios-plugins-1.4.14

                     ./configure

                     make

                     makc*

              4.修改配置文件

                     vim /etc/httpd/conf.d/nagios.conf

                            AuthUserFile /usr/local/nagios/etc/htpasswd.users (登录密码)

                     htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  (生成文件)

              4.启动nagiox监控服务(默认就监控本机)

                      /etc/init.d/nagios start

              5.在客户端查看监控信息

                     ping ip

                     http://ip/nagios

              默认监控项

                     cpu负载

                     登录系统的用户数

                     网站的服务状态

                     ping 检查主机连通性

                     根分区的使用情况

                     ssh服务的状态

                     交换分区的使用情况

                     总进程数量

              监控插件的使用

                     服务运行时自动调用插件目录下的监控插件对指定的资源做监控,调用插件时,运维人员可以自定义监控插件的监控阀值

                     监控阀值

                           警告

                           错误

                     当监控时若监控到的数据比警告值小是正常状态Ok绿色背景、

                     若监控到的数据比警告值大且小于错误值是警告状态warning 黄色背景

                     若监控到的数据比错误值大时是错误状态 critical 红色

                     /usr/local/nagios/libexec/check_* -h 查看插件用法

                     /usr/local/nagios/libexec/check_user -w 2 -c 5

                     /usr/local/nagios/libexec/check_disk -w 50% -c 30% /boot

                     /usr/local/nagios/libexec/check_swap -w 50% -c 30%

                     /usr/local/nagios/libexec/check_procs -w 10 -c 10 -s Z

              6.配置文件说明()

                     /usr/local/nagios/etc/

                           resource.cfg 宏定义文件

                           cgi.cfg

                           nagios.cfg 主配置文件 contacts.cfg

                     /usr/local/nagios/bin

                           nagios  -v  验证主配置文件是否有语法错误

                     /usr/local/nagios/etc/objects/

                           commands.cfg         定义监控命令(设置使用那个监控插件)

                                  define command{

                                  command_name    check-host-alive

                                  command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

                                  }

                                  变量在宏定义文件(resource.cfg)中定义格式:($...$=....)

                           contacts.cfg  指定接收报警信息的邮箱地址

                                  email  nagios@localhost

                                  1)要能和收件域通信

                                  2)本地 postfix 服务要起          

                           timeperiods.cfg      定义监控时间模板

                           templates.cfg 定义监控模板

                           localhost.cfg 设置监控本机的那些资源(阀值)

                                  define host{

                                         use                     linux-server     ; 指定模板名(在监控模板定义)

                                         host_name               localhost        ; 在nagios页面显示的host名

                                         alias                   localhost        ; 描述

                                         address                 127.0.0.1        ; 监控地址

                                         }

                                  define service{

                                         use                             local-service          ; 指定模板名

                                         host_name                       localhost       ;在nagios页面显示的host名

                                         service_description             SSH                    ; 描述信息(nagios页面显示)

                                         check_command                   check_ssh       ; 监控命令名(cinnabds.cfg(变量需要赋值)(check_local_disk!20%!10%!/))

                                         notifications_enabled           0

                                                }

              6.1 监控本机 localhostcfg

                     监控本机的引导分区和ftp服务的状态不监控交换分区,修改监控本机登录用户数量的警告改为1错误改为2

                     监控远端主机的私有数据(磁盘进程用户)

                           1在被监控的主机安装监控插件

                                  cd nagios-plugins

                                  yum -y install gcc gcc-c++

                                  ./configure

                                  make

                                  make install

                           2 在被监控的主机上运行nrpe服务

                                  cd nrpe

                                  安全套文件收集数据传给监控端传输时加密需要安装openssl

                                  yum -y install openssl openssl-devel xinetd

                                  cat ../doc/nagios.pdf

                                  useradd nagios

                                  group nagcmd

                                  usermod -G nagcmd nagios

                                  ./configure

                                  make all

                                  make install-plugins

                                  make install-darmon

                                  make install-darmon-config

                                  make install-xinetd

                                  vim /etc/xinet.d/nrpe

                                         disabled=no

                                  vim /etc/services

                                         nrep 5666/TCP #nrep

                                  chkconfig xinetd on

                                  service xinetd start

                                   iptables -I RH-Firewall-1-INPUT -p tcp -m tcp -dport 5666 -j ACCEPT

                           3 在监控服务器上获取nrpe服务收集的本地私有数据

                           4 在监控远端主机的配置文件里监控远端私有数据

本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

0

scanz个人博客