概述:
操作系統版本:CentOS release 6.3 (Final) 64位
nagios版本:Nagios Core 4.0.6
pnp4nagios版本:pnp4nagios-0.6.22
mk-livestatus版本:mk-livestatus-1.2.5i5p2
check_mk版本:check_mk-1.2.5i5p2
python版本:Python-2.7.8
httpd是rpm安裝的,版本為:
httpd-2.2.15-30.el6.centos.x86_64
httpd-devel-2.2.15-30.el6.centos.x86_64
一、安裝python模塊
tar xzvf Python-2.7.8.tgz
首先需要安裝python,在源碼安裝python時,需要加上參數
CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/python
否則,在后續安裝mod_python模塊的時候會報錯:
libpython2.7.a: could not read symbols: Bad value
類似這樣的問題,都可以采用在編譯的時候,加上CFLAGS="-O3 -fPIC" 參數
make
make install
添加python軟連接:ln -s /usr/local/python/bin/python2.7 /usr/bin/python
安裝mod_python,版本為:mod_python-3.3.1
tar zxf mod_python-3.3.1.tgz
安裝:
./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/bin/python
make
make install
注意:
1.在執行make的時候,可能會報錯,提示connobject.c:142出錯:
vi src/connobject.c
修改
!(b == APR_BRIGADE_SENTINEL(b) ||
為
!(b == APR_BRIGADE_SENTINEL(bb) ||
make
make install
執行完成之后,可以找到mod_python.so模塊
[root@cdn18 mod_python-3.3.1]# find / -name "mod_python.so"
/usr/lib64/httpd/modules/mod_python.so
在httpd.conf中增加
LoadModule python_module modules/mod_python.so
重啟apache,重新訪問正常。
二、安裝mk-livestatus
tar xzvf mk-livestatus-1.2.5i5p2.tar.gz
cd mk-livestatus-1.2.5i5p2
./configure --help
./configure --with-nagios4
此處一定要指定with-nagios4,否則,nagios4版本會安裝不上,報錯如下,說庫文件未定義,nagios也無法重啟
[1407810436] Error: Could not load module '/usr/local/lib/mk-livestatus/livestatus.o' -> /usr/local/lib/mk-livestatus/livestatus.o: undefined symbol: last_command_check
[1407810436] Error: Failed to load module '/usr/local/lib/mk-livestatus/livestatus.o'.
[1407810436] Error: Module loading failed. Aborting.
make
make install
三、安裝check_mk
tar xzvf check_mk-1.2.5i5p2.tar.gz
cd check_mk-1.2.5i5p2
./setup.sh
[root@cdn18 check_mk-1.2.5i5p2]# ./setup.sh
____ _ _ __ __ _ __
/ ___| |__ ___ ___| | __ | \/ | |/ /
| | | '_ \ / _ \/ __| |/ / | |\/| | ' /
| |___| | | | __/ (__| < | | | | . \
\____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\
|_____|
Check_MK setup Version: 1.2.5i5p2
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.
* Read 32 settings from previous setup from /root/.check_mk_setup.conf.
1) Installation directories of check_mk
Executable programs
Directory where to install executable programs such as check_mk itself.
This directory should be in your search path ($PATH). Otherwise you
always have to specify the installation path when calling check_mk:
( previous --> /usr/bin):
Check_MK configuration
Directory where check_mk looks for its main configuration file main.mk.
An example configuration file will be installed there if no main.mk is
present from a previous version:
( previous --> /etc/check_mk):
Check_MK software
The base directory for the software installation of Check_MK. This
directory will get the subdirectories checks, modules, web, locale and
agents. Note: in previous versions it was possible to specify each of
those directories separately. This is no longer possible:
( previous --> /usr/share/check_mk):
documentation
Some documentation about check_mk will be installed here. Please note,
however, that most of check_mk's documentation is available only online at
http://mathias-kettner.de/check_mk.html:
( previous --> /usr/share/doc/check_mk):
check manuals
Directory for manuals for the various checks. The manuals can be viewed
with check_mk -M <CHECKNAME>:
( previous --> /usr/share/doc/check_mk/checks):
working directory of Check_MK
Check_MK will create log files, automatically created checks and
other files into this directory. The setup will create several subdirectories
and makes them writable by the Nagios process:
( previous --> /var/lib/check_mk):
2) Configuration of Linux/UNIX Agents
extensions for agents
This directory will not be created on the server. It will be hardcoded
into the Linux and UNIX agents. The agent will look for extensions in the
subdirectories plugins/ and local/ of that directory:
( previous --> /usr/lib/check_mk_agent):
configuration dir for agents
This directory will not be created on the server. It will be hardcoded
into the Linux and UNIX agents. The agent will look for its configuration
files here (currently only the logwatch extension needs a configuration file):
( previous --> /etc/check_mk):
3) Integration with Nagios
Name of Nagios user
The working directory for check_mk contains several subdirectories
that need to be writable by the Nagios user (which is running check_mk
in check mode). Please specify the user that should own those
directories:
( previous --> nagios):
User of Apache process
Check_MK WATO (Web Administration Tool) needs a sudo configuration,
such that Apache can run certain commands as root. If you specify
the correct user of the apache process here, then we can create a valid
sudo configuration for you later::
( previous --> apache):
Common group of Nagios+Apache
Check_mk creates files and directories while running as nagios.
Some of those need to be writable by the user that is running the webserver.
Therefore a group is needed in which both Nagios and the webserver are
members (every valid Nagios installation uses such a group to allow
the web server access to Nagios' command pipe)::
( previous --> nagcmd):
Nagios binary
The complete path to the Nagios executable. This is needed by the
option -R/--restart in order to do a configuration check.:
( previous --> /usr/local/nagios/bin/nagios):
Nagios main configuration file
Path to the main configuration file of Nagios. That file is always
named 'nagios.cfg'. The default path when compiling Nagios yourself
is /usr/local/nagios/etc/nagios.cfg. The path to this file is needed
for the check_mk option -R/--restart:
( previous --> /usr/local/nagios/etc/nagios.cfg):
Nagios object directory
Nagios' object definitions for hosts, services and contacts are
usually stored in various files with the extension .cfg. These files
are located in a directory that is configured in nagios.cfg with the
directive 'cfg_dir'. Please specify the path to that directory
(If the autodetection can find your configuration
file but does not find at least one cfg_dir directive, then it will
add one to your configuration file for your conveniance):
( previous --> /usr/local/nagios/etc/check_mk.d):
Nagios startskript
The complete path to the Nagios startskript is used by the option
-R/--restart to restart Nagios.:
( previous --> /etc/init.d/nagios):
Nagios command pipe
Complete path to the Nagios command pipe. check_mk needs write access
to this pipe in order to operate:
( previous --> /usr/local/nagios/var/rw/nagios.cmd):
Check results directory
Complete path to the directory where Nagios stores its check results.
Using that directory instead of the command pipe is faster.:
( previous --> /usr/local/nagios/var/spool/checkresults):
Nagios status file
The web pages of check_mk need to read the file 'status.dat', which is
regularily created by Nagios. The path to that status file is usually
configured in nagios.cfg with the parameter 'status_file'. If
that parameter is missing, a compiled-in default value is used. On
FHS-conforming installations, that file usually is in /var/lib/nagios
or /var/log/nagios. If you've compiled Nagios yourself, that file
might be found below /usr/local/nagios:
( previous --> /usr/local/nagios/var/status.dat):
Path to check_icmp
check_mk ships a Nagios configuration file with several host and
service templates. Some host templates need check_icmp as host check.
That check plugin is contained in the standard Nagios plugins.
Please specify the complete path (dir + filename) of check_icmp:
( previous --> /usr/local/nagios/libexec/check_icmp):
4) Integration with Apache
URL Prefix for Web addons
Usually the Multisite GUI is available at /check_mk/ and PNP4Nagios
is located at /pnp4nagios/. In some cases you might want to define some
prefix in order to be able to run more instances of Nagios on one host.
If you say /test/ here, for example, then Multisite will be located
at /test/check_mk/. Please do not forget the trailing slash.:
( previous --> /):
Apache config dir
Check_mk ships several web pages implemented in Python with Apache
mod_python. That module needs an apache configuration section which
will be installed by this setup. Please specify the path to a directory
where Apache reads in configuration files.:
( previous --> /etc/httpd/conf.d):
HTTP authentication file
Check_mk's web pages should be secured from unauthorized access via
HTTP authenticaion - just as Nagios. The configuration file for Apache
that will be installed contains a valid configuration for HTTP basic
auth. The most conveniant way for you is to use the same user file as
for Nagios. Please enter your htpasswd file to use here:
( previous --> /usr/local/nagios/etc/htpasswd.users):
HTTP AuthName
Check_mk's Apache configuration file will need an AuthName. That
string will be displayed to the user when asking for the password.
You should use the same AuthName as for Nagios. Otherwise the user will
have to log in twice:
( previous --> Nagios Access):
5) Integration with PNP4Nagios 0.6
PNP4Nagios templates
Check_MK ships templates for PNP4Nagios for most of its checks.
Those templates make the history graphs look nice. PNP4Nagios
expects such templates in the directory pnp/templates in your
document root for static web pages:
( previous --> /usr/local/pnp4nagios/share/templates):
RRD files
Configure the directory PNP4Nagios stores the RRD database files in:
( previous --> /usr/local/pnp4nagios/var/perfdata):
rrdcached socket
If you use the rrdcached to process performance data from Nagios,
you can configure the socket of the rrdcached here to make the prediction
feature use it:
( previous --> /tmp/rrdcached.sock):
6) Check_MK Livestatus Module
compile livestatus module
The well known MK Livestatus broker module is part of Check_MK.
It provides direct access to Nagios internal data structures. It aims to
supersede status.dat and also NDO. The Livestatus Module does not only
allow extremely fast access to the status of your services and hosts, it
does also provide live data (which status.dat does not). Also - unlike NDO -
Livestatus does not cost you even measurable CPU performance, does not need
any disk space and also needs no configuration.
Livestatus is neccessary when you want to use Multisite. It is also
the preferred backend for NagVis.
Please answer 'yes', if you want to compile and integrate the
Livestatus module into your Nagios. You need 'make' and the GNU
C++ compiler installed in order to do this:
( previous --> yes):
Nagios / Icinga version
The version is required for the compilation of the livestatus module.
Depending on the major version (3 or 4) different nagios headers are included:
( previous --> 4.0.6):
check_mk's binary modules
Directory for architecture dependent binary libraries and plugins
of check_mk:
( previous --> /usr/lib/check_mk):
Unix socket for Livestatus
The Livestatus Module provides Nagios status data via a unix
socket. This is similar to the Nagios command pipe, but allows
bidirectional communication. Please enter the path to that pipe.
It is recommended to put it into the same directory as Nagios'
command pipe:
( previous --> /usr/local/nagios/var/rw/live):
Backends for other systems
Directory where to put backends and configuration examples for
other systems. Currently this is only Nagvis, but other might follow
later.:
( previous --> /usr/share/check_mk/livestatus):
7) Check_MK Event Console
Install Event Console
The Check_MK Event Console is a full featured event processing
module that integrates with Multisite. It has an own daemon and
several methods for retrieving events. It even has an integrated
syslog daemon. Please answer 'yes', if you want to enable the
Event Console.:
( previous --> no):
----------------------------------------------------------------------
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 nagcmd
Nagios binary /usr/local/nagios/bin/nagios
Nagios main configuration file /usr/local/nagios/etc/nagios.cfg
Nagios object directory /usr/local/nagios/etc/check_mk.d
Nagios startskript /etc/init.d/nagios
Nagios command pipe /usr/local/nagios/var/rw/nagios.cmd
Check results directory /usr/local/nagios/var/spool/checkresults
Nagios status file /usr/local/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/nagios/etc/htpasswd.users
HTTP AuthName Nagios Access
PNP4Nagios templates /usr/local/pnp4nagios/share/templates
RRD files /usr/local/pnp4nagios/var/perfdata
rrdcached socket /tmp/rrdcached.sock
compile livestatus module yes
Nagios / Icinga version 4.0.6
check_mk's binary modules /usr/lib/check_mk
Unix socket for Livestatus /usr/local/nagios/var/rw/live
Backends for other systems /usr/share/check_mk/livestatus
Install Event Console no
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/
========================
至此,check_mk安裝完成
打開check_mk的web頁面,報錯如下:
Livestatus problem:Cannot connect to 'unix:/usr/local/nagios/var/rw/live':[Error 13]Permission denied
解決方法:
check_mk,安裝完成之后,web報錯:
Cannot connect to 'unix:/usr/local/nagios/var/rw/live': [Errno 13] Permission denied
Livestatus problem: Cannot connect to 'unix:/usr/local/nagios/var/rw/live': [Errno 13] Permission denied
這個文件,nagios用戶本身是有權限的,而且,文件是自動生成,權限是nagios:nagios的,但是因為這個socket文件是apache用戶操作的,所以apache需要寫權限。
默認的live文件權限是:srw-rw---- 1 nagios nagios 0 Aug 12 16:30 live
#vim /usr/local/nagios/etc/nagios.cfg
添加如下內容:
broker_module=/usr/lib/check_mk/livestatus.o /usr/local//nagios/var/rw/live
#usermod -G apache,nagios,nagcmd nagios
#usermod -G apache,nagios,nagcmd apache
#service nagios restart
#tail /usr/local//nagios/var/nagios.log
本身,執行chmod 777 live文件就可以解決,或者是chown -R nagios:apache live,因為這個socket文件是apache用戶組寫的,或者直接將apache用戶加入到nagios和nagcmd用戶組,但是,最好的方法是將apache用戶加到nagios用戶組。
如果是采用的賦權修改live的方式,因為每次重啟nagios,都會重新生成這個live文件,所以最好在nagios的啟動腳本里面加入chown -R nagios:apache live命令
四、安裝check_mk客戶端:
Linux主機
#rpm -ivh check_mk-agent-1.2.5i5p2-1.noarch.rpm
指定被監控端的IP
#vim /etc/xinetd.d/check_mk
修改only_from = “監控端IP”(服務端IP)
重啟xinetd
#service xinedt restart
windows主機
下載http://mathias-kettner.de/download/check-mk-agent-1.2.5i5p2.exe
安裝即可
編輯安裝目錄下的check_mk.example.ini
修改only_from = “監控端IP”(服務端IP)
重啟Check_MK_Agent服務即可。
五、監控Linux主機
#vim /etc/check_mk/main.mk
修改all_hosts,填寫每一個被監控機的IP地址,中間用,隔開,這里的IP地址如果在nagios中你作為hostname使用的話,請修改nagios中的hostname或者將其注釋掉,否則兩者將會沖突報錯。
all_hosts = [ '192.168.203.10','192.168.203.20' ]
保存退出后:
執行以下命令:
#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
發現並未出現定義的那些主機
#vim /etc/check_mk/multisite.mk
將admin_users = [ "nagiosadmin" ] 修改為登陸到nagios的用戶名,即htpasswd定義的用戶名,我這里是admin
admin_users = [ "nagios" ]
保存退出,重新刷新,即可看到剛才定義的主機了
在長時間的觀察發現,這些定義的主機的服務器基本上已正常,但是主機確實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界面配置主機,web配置主機之后,也需要執行check_mk -I,check_mk -O,但是,不需要收到修改客戶端的配置文件的only_from
對於從web界面直接添加主機的方法,點擊左下角的一個Hosts & Folders按鈕,點擊New host即可,如下:


http://www.newsmth.net/nForum/#!article/Python/101637
http://grass51.blog.51cto.com/4356355/994819
解決問題參考以上鏈接
