由于工作原因,发现并使用了这个软件,用了它的版本2.0,开始使用的时候,中文文档几乎为0(至少没有百度出来),就看了官方英文说明。结合实际工作,写了如下文档,主要是一个最简单基本的使用,很多功能没有涉及,有待继续学习。一个好东西,值得分享。

  icinga 1.x 和nagios几乎一致,配置和使用都一样(本就是nagios的人出来做的icinga)。到了2.x时代,使用了多线程工作,可同时运行很多检测,运行效率提升,消耗的机器资源还很少(官方原话"We’ve seen one instance run 1 million active checks a minute to monitor 60,000 hosts without a creak.”)。配置和使用有了较多的不同,尤其是配置文件,配置逻辑和nagios一样,但是语法几乎不同。

  鉴于我对nagios的使用很少,至于两者之间的具体差异,可能有很多说得不对的地方。有兴趣的童鞋可以安装了icinga2.x,自己体验,或者去官网,有体验的demo。鉴于英文能力有限,很多地方直接摘抄原文,就没有详细翻译。 

  官方网站:https://www.icinga.org/icinga/icinga-2/


安装说明

1 简介:

详情请参考官网。

(1) 源码 http://packages.icinga.org

(2) 一些特征:多线程,高可用,支持ipv6等等。

2 安装

(1) 红帽/centos,可使用yum直接安装:  

readhat5,need EPEL repository,http://packages.icinga.org/epel/

yum install icinga2

chkconfig icinga2 on 35


(2) 查看已有功能


    # icinga2-enable-feature  : Verify

checker   : for executing checks

notification  : for sending notifications

mainlog : for writing the icinga2.log file


(3) yum安装,各种文件的默认路径:


Path


Description


/etc/icinga2


主要的配置文件


/etc/init.d/icinga2


启动脚本


/usr/bin/icinga2-*


Migration and certificate  build scripts.


/usr/sbin/icinga2*


icinga2 命令等


/usr/share/doc/icinga2


Documentation files that  come with Icinga 2.


/usr/share/icinga2/include


一些模板


/var/run/icinga2


PID file.


/var/run/icinga2/cmd


Command pipe and Livestatus  socket.


/var/cache/icinga2


status.dat/objects.cache.


/var/spool/icinga2


Used for performance data  spool files.


/var/lib/icinga2


Icinga 2 state file,  cluster feature replay log and configuration files.


/var/log/icinga2


日志



页面总览:

icinga2学习和使用(一)_icinga2


第一行为主机:

UP: 服务器可ping通的数量(即使服务器ssh失败,能ping通,也会是up

DOWN:服务器宕机的数量。用/分隔的3个数字分别是:未处理/已知晓/已处理

UNREACHEABEL:主机不可达

PENDING:待定。还未检测的。

TOTAL:有问题的服务器/总的服务器


第二行为服务:

OK: 表示服务检测正常

WARNING:服务处于警告状态。未处理/已知晓/处理

CRITICAL:服务处于严重状态。

UNKNOWN:服务状态为未知。

PENDING:服务待检测。

TOTAL:有问题的服务/总的服务


侧边栏(略,基本为字面意思,可参考nagios)


吐槽两句nagios 3.5。search真心没的icinga2方便,后者可以说是全文搜索,搜索很好用。

上图没有展示出来的,icinga的最右边有选框,多个主机,多个服务可以同时选择,一起进行某些操作(比如acknowledge),这个在nagios3.5里似乎就不行了...


基本使用:

1  配置文件(采用的yum安装):


cd /etc/icinga2/conf.d

users.conf    添加和修改主机,添加和修改报警收件人

groups.conf   主机分类

services.conf    添加服务,也可以自定义文件,里面的格式正确即可

templates.conf  定义报警检测频率,报警类型(criticalwaring...

commands.conf 定义命令,也可以用下面一个配置文件

/usr/share/icinga2/include/*  

详细配置说明见后文。

 

插件

cd /usr/lib64/nagios/plugins

也可以自定脚本,和nagios是一样的:

  做法为将结果打印出来,发送退出状态:

  • 0—normal

  • 1—warning

  • 2—critical

  • 3—unknown


启动

检测配置是否正确:/etc/init.d/icinga2 checkconfig  

    或者 /usr/sbin/icinga2 -c /etc/icinga2/icinga2.conf -C  

修改配置后重载配置文件:/etc/init.d/icinga2 reload

        也可以service icinga2 restart


修改页面登录密码

cd /etc/icinga

htpasswd -c passwd icingaadmin



3 configue file简介

(1) icinga2.conf

include_recursive "conf.d",这句保证所有放在conf.d目录下的文件都可以是配置文件,你可以自定义配置文件,不需要按照原有的名字。

(2) constants.conf

定义全局常量

(3)zones.conf

The zones.conf configuration file can be used to configure Endpoint and Zone objects required for a distributed zone setup. By default a local dummy zone is defined based on the NodeName constant defined in constants.conf.

(4) localhost.conf  监控服务器的一些监控配置

/**

* A host definition. You can create your own configuration files

* in the conf.d directory (e.g. one per host). By default all *.conf

* files in this directory are included.

*/


object Host "localhost" {

  import "generic-host"

  address = "127.0.0.1"

  address6 = "::1"

  vars.os = "Linux"

  vars.sla = "24x7"

}


Object: 用来定义单个主机或单个服务

import:导入generic-host 模板,定义检测频率等(详见templates.conf

addressipipv4)或者完整主机名

vars:用来自定义参数(可选的,不可选的都可以在这里定义),后面跟的.os等就是参数,前提是需要定义命令的时候定义这些参数名称,定义命令详见后文。


Tip

The directory tree and file organisation is just an example. You are free to define your own strategy. Just keep in mind to include the main directories in the icinga2.conf file.


The command object icinga for the embedded health check is provided by the Icinga Template Library (ITL) while http_ip, ssh, load, processes, users and disk are all provided by the plugin check commands which we enabled earlier by including the itl and plugins configuration file.


4 插件

RHEL/CentOS下也可以yum 安装

OS/Distribution


Package Name


Installation Path


RHEL/CentOS 

(EPEL)


nagios-plugins-all


/usr/lib/nagios/plugins or  /usr/lib64/nagios/plugins


others


nagios-plugins



如下连接可以找一些常用插件:


·        MonitoringExchange


·        Icinga Wiki


可以照如下方式,自定义插件位置:


# cp check_snmp_int.pl /opt/plugins

# chmod +x /opt/plugins/check_snmp_int.pl

# cat /etc/icinga2/constants.conf

......

const PluginDir = "/usr/lib/nagios/plugins"

const CustomPluginDir = "/opt/monitoring"


插件放在指定位置后,使用时需要在配置文件中定义为命令。详见后文。


For further information on your monitoring configuration read the monitoring basics.


5 DB IDO  (attention the high light) 

Only install the IDO feature if your web interface or reporting tool requires you to do so (for example, Icinga Web or Icinga Web 2). Icinga Classic UI does not use IDO as backend.

参考下面的页面安装说明。


6 Setting up Livestatus  

The MK Livestatus project implements a query protocol that lets users query their Icinga instance for status information. It can also be used to send commands.


7 界面安装

    三个可选 Classic UI   Icinga Web or Icinga Web 2 


(1)   Icinga Classic UI

安装包:

Distribution


Packages


Debian


icinga2-classicui


all others


icinga2-classicui-config  icinga-gui


验证:http://localhost/icinga         icingaadmin/icingaadmin

http设置/etc/httpd/conf.d/icinga.conf

修改登录密码:

cd /etc/icinga

htpasswd -c passwd icingaadmin


(2)Setting up Icinga Web

未设置,不做详细说明,请参考官方文档,这个界面和nagios差异很大,可以体验官方的demo。

Icinga 2 can write to the same schema supplied by Icinga IDOUtils 1.x which is an explicit requirement to run Icinga Web next to the external command pipe. Therefore you need to setup the DB IDO feature remarked in the previous sections.


8 运行 Icinga 2

先检查icinga2的配置

/etc/init.d/icinga2 checkconfig

or

/usr/sbin/icinga2 -c /etc/icinga2/icinga2.conf -C  


然后加载配置文件

/etc/init.d/icinga2 reload --config /etc/icinga2/icinga2.conf

--config选项可以指定一个或多个配置。如果默认配置,不需要写。


到了更新的版本, 已经可以不用先检查配置了, 直接reload, 就会检查配置, 不通过, 会有相关的提示.


下一篇将介绍icinga2的具体配置语法,逻辑和nagios一样,但是语法不同。

to be coutinue...........