check_MK安装部署(nagios4版本)

概述:

  操作系统版本: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

  httpdrpm安装的,版本为:

  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用户加入到nagiosnagcmd用户组,但是,最好的方法是将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

 

六、访问http://localhost/check_mk

发现并未出现定义的那些主机

#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

解决问题参考以上链接

check_MK安装部署(nagios4版本),,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。