project06监控系统Nagios-创新互联

监控系统(nagios[报警]+cacti[监控]) | zabbix (zabbix-proxy)

成都创新互联是一家集网站建设,云浮企业网站建设,云浮品牌网站建设,网站定制,云浮网站建设报价,网络营销,网络优化,云浮网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

 1> 监控系统资源(私有资源 cpu|内存|磁盘)

          (公共资源 服务 ssh|ftp|httpd)

          (网络资源 交换机|路由器)

 2> 报警(商业短信|邮件|微信API)

本章目录:

       1、Nagios的概述

       2、Nagios的部署

       3、讲解Nagios配置文件之间的关系(重点)

       4、配置Nagios监控本机的私有服务和公共服务

       5、使用NRPE配置Nagios监控远程主机的私有服务和公共服务

       6、为Nagios增加短信报警功能

1、Nagios的概述

   Nagios是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监控,在状态变差和变好的时候给出告警信息。

   Nagios最初被设计为在Linux系统之上运行,然而它同样可以在类Unix的系统之上运行。

   Nagios更进一步的特征包括:

       监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);    --公共服务

       监控主机资源(处理器负荷、磁盘利用率等);                --私有服务

       简单地插件设计使得用户可以方便地扩展自己服务的检测方法;

       并行服务检查机制;

       当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);

       具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;

       可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等;

nagios的组成:

   1、nagios的核心组件

   2、nagios监控插件

   3、nagios web页面(html/cgi/php)

   4、nrpe远程主机私有服务的监控组件

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

nagios部署

 参看官方安装手册

ftp://192.168.0.254/notes/weekend/project/software/nagios/docs_INSTALL/toc.html

1) 下载软件

[root@nagios ~]# lftp 192.168.0.254

lftp 192.168.0.254:~> cd notes/weekend/project/software/

lftp 192.168.0.254:/notes/weekend/project/software> mirror nagios/

lftp 192.168.0.254:/notes/weekend/project/software> exit

2) 软件依赖包

   Apache

   PHP

   GCC compiler

   GD development libraries

[root@nagios ~]# yum install httpd php

[root@nagios ~]# yum install gcc glibc glibc-common

[root@nagios ~]# yum install gd

--iso 没有gd-devle包

[root@nagios ~]# yum -y localinstall /root/nagios/gd-devel-2.0.35-10.el6.x86_64.rpm

3) 新建用户与组

[root@nagios ~]# /usr/sbin/useradd -m nagios

[root@nagios ~]# echo 123 | passwd --stdin nagios

[root@nagios ~]# /usr/sbin/groupadd nagcmd

[root@nagios ~]# /usr/sbin/usermod -a -G nagcmd nagios

[root@nagios ~]# /usr/sbin/usermod -a -G nagcmd apache

4) 解压与编译nagios核心软件

 (1) 解压

[root@nagios ~]# tar xf /root/nagios/nagios-cn-3.2.0.tar.bz2 -C/usr/local/src/

 (2) 编译

[root@nagios ~]# cd /usr/local/src/nagios-cn-3.2.0/

[root@nagios nagios-cn-3.2.0]# ./configure --with-command-group=nagcmd

[root@nagios nagios-cn-3.2.0]# make all

make install       --安装软件

make install-init  --安装启动脚本

make install-config --安装配置文件

make install-commandmode --安装命令模式

 (3)安装与配置

[root@nagios nagios-cn-3.2.0]# make install

[root@nagios nagios-cn-3.2.0]# make install-init

[root@nagios nagios-cn-3.2.0]# make install-config

[root@nagios nagios-cn-3.2.0]# make install-commandmode

 (4) 定义web配置文件

[root@nagios nagios-cn-3.2.0]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf/etc/httpd/conf.d/nagios.conf

--设置登录密码 帐号nagiosadmin密码123

[root@nagios nagios-cn-3.2.0]# htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

[root@nagios nagios-cn-3.2.0]# service httpd restart

5) 安装nagios的插件

 (1) 解压

[root@nagios ~]# tar xf /root/nagios/nagios-plugins-1.4.14.tar.gz -C/usr/local/src/

 (2) 编译

[root@nagios ~]# cd /usr/local/src/nagios-plugins-1.4.14/

[root@nagios nagios-plugins-1.4.14]# ./configure --with-nagios-user=nagios--with-nagios-group=nagios

[root@nagios nagios-plugins-1.4.14]# make && make install

6) 启动nagios

 --定义启动脚本

[root@nagios ~]# chkconfig --add nagios

[root@nagios ~]# chkconfig nagios on

 --检测配置文件语法

[root@nagios ~]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg |grepTotal

Total Warnings: 0

Total Errors:  0

 --启动

[root@nagios ~]# service nagios start

 --关闭selinux

[root@nagios ~]# getenforce

Permissive

7) 访问nagios

http://localhost/nagios

+++++++++++++++++讲解Nagios配置文件之间的关系(重点)+++++++++++++

监控一台主机包括的内容:主机是否活着/公共服务/私有服务

配置文件的组成:       --全局变量(变量的调用使用use命令)

/usr/local/nagios/etc/nagios.cfg   --主配置文件,实现配置文件总调度

/usr/local/nagios/etc/resource.cfg     --资源

/usr/local/nagios/etc/objects/commands.cfg --监控使用的命令(通知的命令|监控私有服务的命令|监控公共服务的命令)

/usr/local/nagios/etc/objects/contacts.cfg --联系人(nagiosadmin-->nagios@localhost)

/usr/local/nagios/etc/objects/timeperiods.cfg  --监控周期(7x24 5x8(1-5))

/usr/local/nagios/etc/objects/templates.cfg --模板(通知|genric-host| linux-server| local-server)

**********监控命令 commands.cfg*************** 24个命令模板

# 'notify-host-by-email' command definition  ---使用邮件通知主机(私有服务)

define command{

       command_name   notify-host-by-email

       command_line   /usr/bin/printf "%b" "*****Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:$HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time:$LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert:$HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

       }

邮件内容(通知宏|主机宏|日期/时间宏|...)

***** Nagios *****

Notification Type: $NOTIFICATIONTYPE$ (PROBLEM)

Host: $HOSTNAME$ (nagios.uplooking.com)

State: $HOSTSTATE$ (宕机)

Address: $HOSTADDRESS$ (192.168.0.1)

Info: $HOSTOUTPUT$ (TTP WARNING: HTTP/1.1 403 Forbidden)

Date/Time: $LONGDATETIME$ (Tue Apr26 15:22:03 CST 2016)

邮件主题

/bin/mail -s "** PROBLEM Host Alert: nagios.uplooking.com is 宕机"

# 'notify-service-by-email' command definition  ---使用邮件通知服务 (公共服务)

# 'check-host-alive' command definition --检测主机是否存活

# 'check_local_disk' command definition --磁盘使用率

# 'check_local_load' command definition  --cpu负载

# 'check_local_users' command definition --用户登录数

# 'check_local_swap' command definition  --swap分区

....

####################################################################################

**********联系人 contacts.cfg*************** 1个联系人 1个联系组

define contact {

       contact_name                  HugoBoss   ---联系人的名称

       use                           generic-contact --使用那个模板

       alias                         康康 --别名

       email                         hugoboss@hugo.cc --邮件地址

}

define contactgroup{

       contactgroup_name      admins

       alias                  Nagios Administrators

       members                nagiosadmin, HugoBoss --组的成员

       }

####################################################################################

****************监控周期 timeperiods.cfg*********************************  5个模板

[root@nagios ~]# grep timeperiod_name/usr/local/nagios/etc/objects/timeperiods.cfg

       timeperiod_name 24x7 --全年

   timeperiod_name workhours ---工作日

   timeperiod_name none ---全年不通知

       timeperiod_nameus-holidays ---美国节假日

       timeperiod_name24x7_sans_holidays --除了美国节假日以外的全年

####################################################################################

****************监控模板 templates.cfg********************************* 8个模板

# CONTACT TEMPLATES --联系人模板

define contact{

       name                           generic-contact --模板名称

       service_notification_period    24x7 ---服务的通知周期

       host_notification_period       24x7 ---主机的通知周期

       service_notification_options   w,u,c,r,f,s --通知服务的类型

       host_notification_options      d,u,r,f,s  --通知主机的类型

       service_notification_commands  notify-service-by-email ---通知服务的邮件方式

       host_notification_commands     notify-host-by-email    ---通知主机的邮件方式

       register                       0  ---只是一个模板 不能当成监控对象使用

       }

# HOST TEMPLATES --主机模板

define host{

       name                           generic-host

define host{

       name                           linux-server    模板名称

       use                            generic-host    调用那个模板

       check_period                   24x7            监控周期

       check_interval                 5               检测时间 5分钟

       retry_interval                 1               失败重试 1分钟

       max_check_attempts             10              大尝试次数 10次

       check_command                  check-host-alive 检测主机命令

       notification_period            workhours        通知周期

       notification_interval          120         通知间隔 120分钟

       notification_options           d,u,r        通知类型 d:宕机 u:主机不能到达 r:恢复

       contact_groups                 admins      通知组

       register                       0

       }

name windows-server

name generic-printer

name generic-switch

# SERVICE TEMPLATES

define service{

       name                           generic-service

define service{

       name                           local-service

       use                            generic-service

[root@nagios ~]# grep name /usr/local/nagios/etc/objects/templates.cfg

       name                           generic-contact    ; The name of this contact template

       name                           generic-host   ; The name of this host template

   name               linux-server   ;The name of this host template

   name           windows-server ;The name of this host template

   name           generic-printer ;The name of this host template

   name           generic-switch ;The name of this host template

       name                           generic-service    ; The 'name' of this service template

   name               local-service      ;The name of this service template

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:project06监控系统Nagios-创新互联
标题URL:http://myzitong.com/article/dchoch.html