icinga2學習和使用(一)

  由於工作原因,發現並使用了這個軟件,用了它的版本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


日誌



頁面總覽:

wKioL1THBjjTPUdEAAeGI87xwYw790.jpg


第一行爲主機:

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...........



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章