如何部署Icinga服務端,部署Icinga服務端
Icinga是Nagios的一個變種,配置,使用方式幾乎一樣,而且完全相容Nagios的外掛程式。所以下面的部署方案對Nagios同樣使用。
它還推出了兩個中文版本,icinga-cn原版和icinga-pnp4nagios-cn,前者和Nagios幾乎一模一樣,只不過介面是中文的,而後者則整合了php4繪圖功能,能以圖形化的方式呈現系統的監控資訊,類似於Cacti。
Icinga服務端一般是指其核心,它提供的只是一個架構,並不能監控具體的資源,譬如CPU,記憶體,進程等。對這些的監控是通過Icinga外掛程式來實現的。
對遠程Linux主機的監控一般有兩種方式:
1. check_by_ssh外掛程式
譬如我要查看遠程Linux主機的磁碟空間的使用方式,
# /usr/local/icinga/libexec/check_by_ssh -H 192.168.244.134 -C 'df -h'
root@192.168.244.134's password: Filesystem Size Used Avail Use% Mounted on/dev/sda2 7.7G 5.8G 1.6G 79% /tmpfs 850M 0 850M 0% /dev/shm/dev/sda1 194M 27M 158M 15% /boot/dev/sda4 9.9G 7.2G 2.3G 77% /u01
該外掛程式能夠實現安全傳輸,使用SSH將會比NRPE外掛程式更安全,而且,通過這種方式,遠程被監控主機上不需要部署任何軟體,但是這會導致遠程主機和監控主機上的CPU負載過高。如果監控的主機比較多,這就會成為一個問題,因此,許多營運管理員選擇NRPE外掛程式,這樣會使CPU負載降低。
2. NRPE外掛程式
NRPE外掛程式的原理是允許Icinga在遠程主機上執行Nagios外掛程式,這樣就可監控遠程主機上的本地資源,譬如CPU,記憶體,SWAP等不會暴露給外部機器的系統資源。
原理如下:
所以本方案實現的是Icinga核心+Nagios外掛程式+NRPE外掛程式。同時,本方案中使用了IDOUtils,這樣,可將icinga的配置資訊和監控資料等儲存到資料庫中。
一、安裝依賴包
主要需安裝以下幾類包
ApacheGCC compilerC/C++ development librariesGD development librarieslibdbi/libdbi-drivers, database like MySQL or PostgreSQL
在Fedora/RHEL/CentOS系統中,具體如下:
# yum install httpd gcc glibc glibc-common gd gd-devel
# yum install libjpeg libjpeg-devel libpng libpng-devel
安裝MySQL及其開發包
# yum install mysql mysql-server libdbi libdbi-devel libdbi-drivers libdbi-dbd-mysql
二、建立賬戶
# /usr/sbin/useradd -m icinga
# passwd icinga
如果是要從WEB介面發送命令給Icinga,還需要多配置一個組,並將web使用者和icinga使用者加入到該組中。
# /usr/sbin/groupadd icinga-cmd
# /usr/sbin/usermod -a -G icinga-cmd icinga
# /usr/sbin/usermod -a -G icinga-cmd apache
三、下載Icinga及其外掛程式包
Icinga中文化項目的為:http://sourceforge.net/projects/icinga-cn/files/ ,在這裡,下載icinga-cn目錄下的icinga-cn-1.12.2.tar.xz。
Icinga plugins的為:http://sourceforge.net/projects/icinga-cn/files/icinga%20plugins/,在這裡,下載nagios-cn-plugins-2.0.3.tar.xz。
icinga nrpe的為:http://sourceforge.net/projects/icinga-cn/files/icinga%20plugins/,在這裡,下載icinga-nrpe-2.14.tar.gz。
四、安裝Icinga核心
即icinga-cn-1.12.2.tar.xz。
# cd /usr/src/
# tar xvf /root/icinga-cn-1.12.2.tar.xz
# cd icinga-cn-1.12.2/
編譯
# ./configure --with-command-group=icinga-cmd --enable-idoutils
編譯沒有問題,則輸出如下:
Web Interface Options: ------------------------ HTML URL: http://localhost/icinga/ CGI URL: http://localhost/icinga/cgi-bin/ Main URL: http://localhost/icinga/cgi-bin/status.cgi?allunhandledproblems UI THEME: ui_theme=ui-smoothnessReview the options above for accuracy. If they look okay,type 'make all' to compile the main program and CGIs.!!! Please take care about the upgrade documentation !!!
# make all
# make fullinstall
# make install-config
五、建立MySQL資料及IDOUtils
# mysql -u root -p
mysql> CREATE DATABASE icinga;Query OK, 1 row affected (0.00 sec)mysql> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';Query OK, 0 rows affected (0.00 sec)mysql> quit
# cd /usr/src/icinga-cn-1.12.2/module/idoutils/db/mysql/
# mysql -u root -p icinga < mysql.sql
修改IDOUtils的設定檔
# vim /usr/local/icinga/etc/ido2db.cfg
db_servertype=mysqldb_port=3306db_user=icingadb_pass=icinga
其實,預設就是這樣。
六、配置經典的WEB介面
# cd /usr/src/icinga-cn-1.12.2/
# make cgis
# make install-cgis
# make install-html
# make install-webconf
設定Icinga WEB介面的登入使用者和密碼
# htpasswd -c /usr/local/icinga/etc/htpasswd.users icingaadmin
如果要修改密碼,可通過以下命令
# htpasswd /usr/local/icinga/etc/htpasswd.users icingaadmin
重啟Apache服務,使上述設定生效
# service httpd restart
七、編譯和安裝Icinga外掛程式
# cd /usr/src/
# tar xvf /root/nagios-cn-plugins-2.0.3.tar.xz
# cd nagios-cn-plugins-2.0.3/
# ./configure --prefix=/usr/local/icinga --with-cgiurl=/icinga/cgi-bin --with-nagios-user=icinga --with-nagios-group=icinga
# make
# make install
八、編譯和安裝NRPE外掛程式
# cd /usr/src/
# tar xvf /root/icinga-nrpe-2.14.tar.gz
# cd icinga-nrpe-2.14/
# ./configure
# make
# make install
# make install-plugin
# make install-init
# make install-xinetd
# make install-daemon-config
其實make install-plugin,make install-init,make install-xinetd, make install-daemon-config也可以不執行,具體作用執行完make後有說明,建議都執行下。
九、調整SELinux策略
最簡單的是直接關閉
臨時關閉:# setenforce 0
永久關閉:# vim /etc/sysconfig/selinux
SELINUX=disabled
十、開啟IDOUtils和Icinga服務
啟動IDOUtils服務
# service ido2db start
驗證Icinga的設定檔
# /usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg
輸出如下:
Icinga 1.12.2Copyright (c) 2009-2015 Icinga Development Team (http://www.icinga.org)Copyright (c) 2009-2013 Nagios Core Development Team and Community ContributorsCopyright (c) 2009-2014 icinga-cn中文化組Copyright (c) 1999-2009 Ethan GalstadLast Modified: 02-14-2015License: GPL讀取配置資料...警報: 未知 'event_profiling_enabled' 配置設定. 將其從配置中移除! Read main config file okay...Processing object config directory '/usr/local/icinga/etc/conf.d'...Processing object config file '/usr/local/icinga/etc/objects/commands.cfg'...Processing object config file '/usr/local/icinga/etc/objects/contacts.cfg'...Processing object config file '/usr/local/icinga/etc/objects/notifications.cfg'...Processing object config file '/usr/local/icinga/etc/objects/timeperiods.cfg'...Processing object config file '/usr/local/icinga/etc/objects/templates.cfg'...Processing object config file '/usr/local/icinga/etc/objects/localhost.cfg'...Processing object config file '/usr/local/icinga/etc/objects/linux.cfg'...Processing object config directory '/usr/local/icinga/etc/modules'...Processing object config file '/usr/local/icinga/etc/modules/idoutils.cfg'... Read object config files okay...Running pre-flight check on configuration data...Checking services... 已檢查17服務.檢查主機... 已檢查2主機.檢查主機群組... 已檢查2主機群組.檢查服務組... 已檢查2服務組.檢查連絡人... 已檢查1連絡人.檢查連絡人群組... 已檢查1連絡人群組.檢查服務升級... 已檢查0服務升級.檢查服務依賴關係... 已檢查0服務依賴關係.檢查主機升級... 已檢查0主機升級.檢查主機依賴關係... 已檢查0主機依賴關係.檢查命令... 已檢查36命令.檢查時間段... 已檢查6時間段.檢查模組... 已檢查1模組.檢查主機之間的迴路...檢查迴路主機和服務的依賴性...檢查全域事件處理...檢查強迫性處理命令...檢查雜項設定...總計警報s: 0總計錯誤: 0Things look okay - No serious problems were detected during the pre-flight check
啟動Icinga服務
# service icinga start
設定開機自啟動
# chkconfig ido2db on
# chkconfig icinga on
十一、登入WEB介面進行測試
登入地址:http://192.168.244.145/icinga/
登入使用者名稱為:icingaadmin
登入密碼為第六步通過htpasswd命令設定的密碼。
總結:
1. 在上述方案中,IDOUtils和NRPE並不是必需的,如果只需搭建一個簡單的Icinga服務端,只需要Icinga核心和Nagios外掛程式。具體可參考:
http://docs.icinga.org/latest/en/quickstart-icinga.html
2. 官方的部署文檔在MySQL中建立icinga資料庫時,沒有指定字元集,而預設的字元集為latin1,這會導致中文的輸出結果為亂碼,所以,需顯性執行資料庫的預設字元集。
參考:
1. http://docs.icinga.org/latest/en/quickstart-idoutils.html
2. 《掌控-構建Linux系統Nagios監控伺服器》