Check_MK是一款通用的Nagios/Icinga數據採集插件,主要由三個子項目組成。它採用了新的方法從操作系統和網絡組件中收集數據和淘汰老式的NRPE、check_by_ssh、NSClient和check_snmp。其優點能夠自動檢測主機上的監控項目,並且在監控端的CPU使用率也顯著減少。其遵循CPL v2,是開源的免費軟件。
工作原理,摘自其官網上的一幅原理圖像
1、Nagios每一次對所監控的主機每進行一次檢查的時間間隔觸發一個活動檢查。這種主動檢查將會觸發check_mk插件。
2、check_mk通過TCP連接到目標主機。目標主機上的check_mk_agent檢索有關該主機的所有相關數據, 並將其以ASCII文本形式返回給服務器端(這樣的模式類似於zabbix哈~)。
3、check_mk提取performanca數據直接返回給rrd。
4、check_mk提取相關數據,比較所設置的warning/critical 閥值,然後返回這臺主機通過Nagios的被動的服務檢查的檢查結果。
由於check_mk的圖比較炫而且其監控主機也比較方便,類似cacti一樣可以直接在web頁面進行添加,個人覺得很不錯,先上一些我配置完成的check_mk監控的圖。
由於check_mk是nagios的一個插件,所以必須先配置安裝好nagios,關於nagios的安裝與配置在51cto上已經有很多大神給出各種平臺的詳細配置文檔,需要的朋友可以讀一下,這裏我就不多介紹nagios.
以下安裝配置check_mk,由於網上關於check_mk的資料比較少,筆者只好照着官方文檔學習了下,無奈筆者連CECT-4都沒過,想必各位也能估摸出筆者的英語水平,以下內容若有理解偏差或者出入很大,還請各位諒解。
開篇:
由於check_mk是由python語言編寫的,所以必須要準備python的環境,並且python的版本最低也得2.3但是check_mk又不兼容python3,所以請確定你的python版本;另外check_mk需要作爲非獨立守護進程運行,所以請安裝超級守護進程xinetd。瞭解xinetd的相關內容,請移步:基於Tcp Wrapper和Xinetd的服務訪問控制
環境配置:
安裝pnp4nagios
1.下載pnp4nagios http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.2.tar.gz/download
2.pnp4nagios是一個輸出插件,用來創建和顯示由nagios收集的數據,rrdtool繪畫出來的圖像因此還需要安裝rrdtool-perl php-gd rrdtool rrdtool-php rrdtool-devel包。
rrdtool、rrdtool-devel的地址:http://packages.express.org/rrdtool/
rrdtool-php的地址:http://pkgs.org/download/rrdtool-php
rrdtool的組件和附加組件版本儘量一致,儘量請以rrdtool-php的版本來決定版本號
#yum localinstall -y --nogpgcheck rrdtool-*
#yum install php-gd
#tar xzf pnp4nagios-0.6.2.tar.gz
#cd pnp4nagios-0.6.2
#./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-httpd-conf=/etc/httpd/conf.d
#make all
#make fullinstall(也可根據提示一步一步執行make install, install-webconf, install-init, and install-config.)
3.編輯nagios.cfg開啓以下幾項:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
host_perfdata_file=/tmp/host-perfdata
service_perfdata_file=/tmp/service-perfdata
host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
host_perfdata_file_mode=a
service_perfdata_file_mode=a
host_perfdata_file_processing_interval=0
service_perfdata_file_processing_interval=0
host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file
4.增加以下內容:
event_broker_options=-1
broker_module=/usr/local/pnp4nagios/lib/npcdmod.o config_file=/usr/local/pnp4nagios/etc/npcd.cfg'
這裏要安裝自己當前的環境設置模塊和配置文件的目錄路徑
5.啓動npcd
#service npcd start
6.重新啓動nagios
#service nagios restart
7.重新啓動apache.讓pnp4nagios.conf加載進來
#killall -9 httpd
#apachectl start
訪問:http://localhost/pnp4nagios
安裝check_mk
1.下載check_mk http://mathias-kettner.de/download/check_mk-1.2.0p2.tar.gz
#wget http://mathias-kettner.de/download/check_mk-1.2.0p2.tar.gz
2.check_mk的安裝包解壓安裝後,跟其他的軟件不一樣安裝後就可以刪除
#tar xvf check_mk-1.2.0p2.tar.gz
#cd check_mk-1.2.0p2
#./setup.sh
根據提示進行符合自己的設置,絕大部分的選項它都會檢測你當前的環境配置
____ _ _ __ __ _ __
/ ___| |__ ___ ___| | __ | \/ | |/ / | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | |___| | | | __/ (__| < | | | | . \ \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |_____|
Check_MK setup Version: 1.2.0p2
Welcome to Check_MK. This setup will install Check_MK into user defined directories. If you run this script as root, installation paths below /usr will be suggested. If you run this script as non-root user paths in your home directory will be suggested. You may override the default values or just hit enter to accept them.
Your answers will be saved to /root/.check_mk_setup.conf and will be reused when you run the setup of this or a later version again. Please delete that file if you want to delete your previous answers.
* Found running Nagios process, autodetected 20 settings.
1) Installation directories of check_mk
Executable programs
Otherwise youalways have to specify the installation path when calling check_mk:
( default --> /usr/bin):
安裝check_mk命令的路徑,默認即可
Check_MK configuration
( default --> /etc/check_mk):
安裝check_mk的配置文件路徑,默認即可
Check_MK software
( default --> /usr/share/check_mk):
指定安裝check_mk軟件的安裝,這裏我繼續使用默認
documentation
( default --> /usr/share/doc/check_mk):
指定check_mk的文檔安裝目錄,如果上一個選項你更改了安裝路徑,建議這裏也作出修改,儘量保持父目錄一致,我使用默認
check manuals
( default --> /usr/share/doc/check_mk/checks):
指定檢測手冊的安裝路徑,這裏我使用默認
working directory of check_mk
( default --> /var/lib/check_mk):
指定check_mk的工作目錄,以創建緩存文件等
2) Configuration of Linux/UNIX Agents
extensions for agents
( default --> /usr/lib/check_mk_agent):
指定check_mk的客戶端的目錄
configuration dir for agents
( default --> /etc/check_mk):
指定check_mk客戶端的配置文件目錄
3) Integration with Nagios
Name of Nagios user
( default --> nagios):
指定你的nagios的運行用戶。
User of Apache process
( default --> apache):
指定你的apache的運行用戶,這裏我的是apache
Common group of Nagios+Apache
( default --> nagios):
指定你的apache的運行用戶和nagios運行用戶的共同組名,默認是nagios
Nagios binary
( autodetected --> /usr/local/apache/htdocs/nagios/bin/nagios):
指定nagios命令的目錄,這裏該安裝程序會自動檢測出你的當前環境的配置,所以基本上默認即可
Nagios main configuration file
( autodetected --> /usr/local/apache/htdocs/nagios/etc/nagios.cfg):
指定nagios的主配置文件
Nagios object directory
( autodetected --> /usr/local/apache/htdocs/nagios/etc/service):
指定nagios定義的對象目錄,即nagios中配置的cfg_dir
Nagios startskript
( autodetected --> /etc/init.d/nagios):
nagios的SysV風格的啓動腳本
Nagios command pipe
( autodetected --> /usr/local/apache/htdocs/nagios/var/rw/nagios.cmd):
指定nagios啓動後生成的命令接口文件目錄
Check results directory
( autodetected --> /usr/local/apache/htdocs/nagios/var/spool/checkresults):
指定nagios的檢測結果目錄
Nagios status file
( autodetected --> /usr/local/apache/htdocs/nagios/var/status.dat):
指定nagios的狀態文件的路徑
Path to check_icmp
( autodetected --> /usr/local/nagios/libexec/check_icmp):
指定check_mk附帶的check_icmp的命令的安裝目錄,服務器端通過該命令來檢測多個監控主機
4) Integration with Apache
URL Prefix for Web addons
( default --> /):
指定通過web訪問時的別名。
Apache config dir
( autodetected --> /etc/httpd/conf.d):
指定apache的擴展配置文件目錄,check_mk會在該目錄下生成適用於apache的一個配置文件。
HTTP authentication file
( autodetected --> /usr/local/apache/htdocs/nagios/etc/htpasswd.users):
指定訪問check_mk時的身份驗證文件,這裏它會使用nagios的用戶驗證文件
HTTP AuthName
( autodetected --> Nagios Access):
用於指定AuthName的提示信息。
5) Integration with PNP4Nagios 0.6
PNP4Nagios templates
( autodetected --> /usr/local/pnp4nagios/share/templates):
用於指定pnp4Nagios的模版目錄
6) Check_MK Livestatus Module
compile livestatus module
( default --> yes):
這裏詢問是否要編譯livestatus模塊到nagios,具體的livestatus我還不瞭解,只是知道在執行此操作後,當nagios啓動時會生成一個名爲live的socket套接字文件,用於check_mk通信用的。
check_mk's binary modules
( default --> /usr/lib/check_mk):
指定之前check_mk命令的安裝目錄
Unix socket for Livestatus
( default --> /usr/local/apache/htdocs/nagios/var/rw/live):
指定livestatus的Unix的套接字文件生成的目錄以及名字
Backends for other systems
( default --> /usr/share/check_mk/livestatus):
指定與其他操作系統通信的livestatus的目錄
----------------------------------------------------------------------
You have chosen the following directories:
Executable programs /usr/bin
Check_MK configuration /etc/check_mk
Check_MK software /usr/share/check_mk
documentation /usr/share/doc/check_mk
check manuals /usr/share/doc/check_mk/checks
working directory of check_mk /var/lib/check_mk
extensions for agents /usr/lib/check_mk_agent
configuration dir for agents /etc/check_mk
Name of Nagios user nagios
User of Apache process apache
Common group of Nagios+Apache nagios
Nagios binary /usr/local/apache/htdocs/nagios/bin/nagios
Nagios main configuration file /usr/local/apache/htdocs/nagios/etc/nagios.cfg
Nagios object directory /usr/local/apache/htdocs/nagios/etc/service
Nagios startskript /etc/init.d/nagios
Nagios command pipe /usr/local/apache/htdocs/nagios/var/rw/nagios.cmd
Check results directory /usr/local/apache/htdocs/nagios/var/spool/checkresults
Nagios status file /usr/local/apache/htdocs/nagios/var/status.dat
Path to check_icmp /usr/local/nagios/libexec/check_icmp
URL Prefix for Web addons /
Apache config dir /etc/httpd/conf.d
HTTP authentication file /usr/local/apache/htdocs/nagios/etc/htpasswd.users
HTTP AuthName Nagios Access
PNP4Nagios templates /usr/local/pnp4nagios/share/templates
compile livestatus module yes
check_mk's binary modules /usr/lib/check_mk
Unix socket for Livestatus /usr/local/apache/htdocs/nagios/var/rw/live
Backends for other systems /usr/share/check_mk/livestatus
Proceed with installation (y/n)? y
此刻將會將之前的所有配置列出來,作出一個最後的確認。
(Compiling MK Livestatus.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................)
Installation completed successfully.
Please restart Nagios and Apache in order to update/active check_mk's web pages.
You can access the new Multisite GUI at http://localhost/check_mk/
3.重啓apache和nagios
#killall -9 httpd
#apachectl start
#service nagios restart
4.訪問http://localhost/check_mk/
錯誤1: 提示沒有mod_python模塊 解決方法1: #wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz #tar zxvf mod_python-3.3.1.gz #cd mod_python-3.3.1 #./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/bin/python #make apxs:Error: Command failed with rc=65536 make[1]: *** [mod_python.so] Error 1 make[1]: Leaving directory `/root/ndo/src/mod_python-3.3.1/src' make: *** [do_dso] Error 2 原因是 Apache 的版本還太高 mod_python 未支持 #vim src/connobject.c 把!(b == APR_BRIGADE_SENTINEL(b) || 改爲!(b == APR_BRIGADE_SENTINEL(bb) || #make clean #make #make install 在httpd.conf中增加 LoadModule python_module modules/mod_python.so 重啓apache,重新訪問正常。 錯誤2: Your web server cannot create the directory ,or cannot set the group to or cannot set the permissions to.Please make sure that:Reason:[Error 13]Permission denied:'/var/lib/check_mk/web/admin' 解決方法2: #chown apache:apache /var/lib/check_mk/web 錯誤3: Livestatus problem:Cannot connect to 'unix:/usr/local/apache/htdocs/nagios/var/rw/live':[Error 13]Permission denied 解決方法3: #vim /usr/local/apache/htdocs/nagios/etc/nagios 添加如下內容: broker_module=/usr/lib/check_mk/livestatus.o /usr/local/apache/htdocs/nagios/var/rw/live #usermod -G apache,nagios nagios #chown nagios:nagios /usr/local/apache/htdocs/nagios/var/rw/live #service nagios restart #tail /usr/local/apache/htdocs/nagios/var/nagios.log 出現如下內容,則表示正常了,刷新重試。錯誤消失 [1347850110] Event broker module '/usr/lib/check_mk/livestatus.o' initialized successfully. [1347850110] livestatus: Timeperiod cache not updated, there are no timeperiods (yet) [1347850110] livestatus: Livestatus 1.2.0p2 by Mathias Kettner. Socket: '/usr/local/apache/htdocs/nagios/var/rw/live' [1347850110] livestatus: Please visit us at http://mathias-kettner.de/ [1347850110] livestatus: Hint: please try out OMD - the Open Monitoring Distribution [1347850110] livestatus: Please visit OMD at http://omdistro.org [1347850110] livestatus: Removed old left over socket file /usr/local/apache/htdocs/nagios/var/rw/live [1347850110] livestatus: Finished initialization. Further log messages go to /usr/local/apache/htdocs/nagios/var/livestatus.log |
5.一切訪問正常,安裝check_mk客戶端:
Linux主機
#wget http://mathias-kettner.de/download/check_mk-agent-1.2.0p2-1.noarch.rpm
#rpm -ivh check_mk-agent-1.2.0p2-1.noarch.rpm
指定被監控端的IP
#vim /etc/xinetd.d/check_mk
修改only_from = “監控端IP”
重啓xinetd
#service xinedt restart
windows主機
下載http://mathias-kettner.de/download/check-mk-agent-1.2.0p2.exe
安裝即可
編輯安裝目錄下的check_mk.example.ini
修改only_from = “監控端IP”
重啓Check_MK_Agent服務即可。
6.監控Linux主機
#vim /etc/check_mk/main.mk
修改all_hosts,填寫每一個被監控機的IP地址,中間用,隔開,這裏的IP地址如果在nagios中你作爲hostname使用的話,請修改nagios中的hostname或者將其註釋掉,否則兩者將會衝突報錯。
all_hosts = [ "172.23.136.139","172.23.136.149","172.23.136.155" ]
保存退出後:
執行以下命令:
#check_mk -I
檢查所有可檢測的項目
df 8 new checks
logwatch 14 new checks
mem.win 2 new checks
systemtime 2 new checks
uptime 2 new checks
winperf_phydisk 2 new checks
winperf_processor.util 2 new checks
#check_mk -O
創建或更新Nagios配置,並且重新加載Nagios
Generating Nagios configuration...OK
Validating Nagios configuration...OK
Precompiling host checks...OK
Reloading Nagios...OK
7、訪問http://localhost/check_mk
發現並未出現定義的那些主機
#vim /etc/check_mk/multisite.mk
將admin_users = [ "nagiosadmin" ] 修改爲登陸到nagios的用戶名,即htpasswd定義的用戶名,我這裏是admin
admin_users = [ "admin" ]
保存退出,重新刷新,即可看到剛纔定義的主機了
在長時間的觀察發現,這些定義的主機的服務器基本上已正常,但是主機確實down的狀態
錯誤提示: Waring:This plugin must be either run as root or setuid root" 解決方法: 找到當初安裝check_mk時附帶的check_icmp命令 #chown root:nagios check_icmp #chmod u+s check_icmp 發現主機馬上就處於up狀態了 |
對於從web界面直接添加主機的方法,點擊左下角的一個Hosts & Folders按鈕,點擊New host即可
其他功能筆者這在琢磨,例如監控cluster還有那個wato等,由於界面是全英的,所以對於筆者這樣的英語水平的確吃力,有興趣的朋友可以自行研究下。同樣歡迎朋友補充check_mk的其他功能。