阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

搭建Nagios监控系统

183次阅读
没有评论

共计 12927 个字符,预计需要花费 33 分钟才能阅读完成。

1、软件包准备

nagios-4.0.8.tar.gz

nagios-plugins-2.0.3.tar.gz

nrpe-2.15.tar.gz

httpd-2.2.23.tar.gz

 

2、Nagios Server 端安装

1)、安装相关依赖包

yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

2)、安装 Nagios

# useradd -s /sbin/nologin nagios

# configure –prefix=/usr/local/nagios

# make all

# make install

# make install-init

# make install-commandmode

# make install-config

# chkconfig nagios on

# chkconfig –list | grep nagios

3)、安装 Nagios 插件

# tar zxvf nagios-plugins-2.0.3.tar.gz

# cd nagios-plugins-2.0.3

# ./configure –prefix=/usr/local/nagios/

# make && make install

4)、安装配置 apache

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure –prefix=/usr/local/apache2

# make && make install

# vim /usr/local/apache2/conf/http.conf

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User daemon

Group daemon

修改为

User nagios

Group nagios

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改并增加为

<IfModule dir_module>

DirectoryIndex index.html index.php

</IfModule>

AddType application/x-httpd-php .php

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

增加验证配置,即在 httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/usr/local/nagios/sbin”>

 AuthType Basic

 Options ExecCGI

 AllowOverride None

 Order allow,deny

 Allow from all

 AuthName “Nagios Access”

 AuthUserFile /usr/local/nagios/etc/htpasswd

 Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share”

<Directory “/usr/local/nagios/share”>

 AuthType Basic

 Options None

 AllowOverride None

 Order allow,deny

 Allow from all

 AuthName “nagios Access”

 AuthUserFile /usr/local/nagios/etc/htpasswd

 Require valid-user

</Directory>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

创建上面的目录验证文件 htpasswd

# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios

# vim /usr/local/nagios/etc/cgi.cfg

修改配置文件中所有含有 nagiosadmin 的内容

nagiosadmin => nagiosadmin,nagios

# scp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

# vim /etc/init.d/httpd

添加以下内容

# chkconfig: 2345 85 15

# description: Apache is a World Wide Web Server

# chkconfig httpd on

# chkconfig –list | grep httpd

 

5)、安装配置 php

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

# make && make install

# service httpd start

# service nagios start

 

6)、安装 nrpe

# tar zxvf nrpe-2.15.tar.gz

# cd nrpe-2.15

# ./configure –enable-command-args

# make all

# make install-plugin

# /usr/local/nagios/libexec/check_nrpe -H 10.0.2.203

NRPE v2.15

 

7)、配置 commands.cfg,添加 check_nrpe 定义

vim /usr/local/nagios/etc/objects/commands.cfg

# ‘check_nrpe’ command definition

define command{

command_name    check_nrpe       

command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$                         

}

 

8、配置 hosts.cfg

vim /usr/local/nagios/etc/objects/hosts.cfg

define host{

use                    linux-server

host_name              node.3

alias                  node.3

address                10.0.2.203

}

 

9、配置 node.3.cfg(也就是 node.3 的 services.cfg 文件,为了便于管理,每台机器的 services.cfg 文件分开配置,并以主机名命名)

vim /usr/local/nagios/etc/objects/node.3.cfg

define service{

use                    local-service

host_name              node.3

service_description    Current Load

check_command          check_nrpe!check_load

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Check Disk disk

check_command          check_nrpe!check_disk

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Total Processes

check_command          check_nrpe!check_total_procs

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Current Users

check_command          check_nrpe!check_users

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Check Zombie Procs

check_command          check_nrpe!check_zombie_procs

contact_groups          admins

}

 

10)、配置 nagios.cfg

# vim /usr/local/nagios/etc/nagios.cfg

添加以下内容

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/node.3.cfg

 

11)、检查 nagios 配置文件,并重启 nagios 服务

# chown -R nagios.nagios /usr/local/nagios

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

# service nagios restart

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-09/106583p2.htm

3、Nagios Client 端的配置安装

1)、安装相关软件包

yum install -y xinetd openssl*

 

2)、添加用户

useradd nagios

passwd nagios

 

3)、安装 nagios 插件

# tar zxvf nagios-plugins-2.0.3.tar.gz

# cd nagios-plugins-2.0.3

# ./configure –prefix=/usr/local/nagios

# make && make install

# chown -R nagios.nagios /usr/local/nagios

 

4)、安装 nrpe

# tar zxvf nrpe-2.15.tar.gz

# cd nrpe-2.15

# ./configure –enable-command-args

# make all

# make install-plugin

# make install-daemon

# make install-daemon-config

# make install-xinetd

# vim /etc/services

在文件最后追加以下内容

nrpe            5666/tcp                # nrpe

# vim /etc/xinetd.d/nrpe

添加监控主机 IP

only_from      = 127.0.0.1 10.0.2.201

# vim /usr/local/nagios/etc/nrpe.cfg

修改

dont_blame_nrpe=1

# service xinetd restart

# lsof -i:5666

# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

NRPE v2.15

# vim /usr/local/nagios/etc/nrpe.cfg

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

修改

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda

 

4、添加 mysql 和 tomcat 的监控

1)、添加 mysql 监控

Nagios Server:

# vim /usr/local/nagios/etc/objects/commands

添加以下内容

# ‘check_mysql’ command definition

define command{

command_name    check_mysql

command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$

}

# vim /etc/ld.so.conf

追加以下内容

/usr/local/mysql/lib/# 因为 check_mysql 会提示找不到 libmysqlclient.so.18 文件

# /sbin/ldconfig -v

# /usr/local/nagios/libexec/check_mysql -H 10.0.2.203 -u mysql -p 123456

# vim /usr/local/nagios/etc/objects/node.3.cfg

追加以下内容

define service{

use                    local-service

host_name              node.3

service_description    Check MySQL

check_command          check_nrpe!check_mysql!mysql!123456

contact_groups          admins

}

 

Nagios Client:

# vim /usr/local/nagios/etc/nrpe.cfg

添加以下内容

command[check_mysql]=/usr/local/nagios/libexec/check_mysql -u $ARG1$ -p $ARG2$

 

# vim /etc/ld.so.conf

追加以下内容

/usr/local/mysql/lib/# 因为 check_mysql 会提示找不到 libmysqlclient.so.18 文件

# /sbin/ldconfig -v

 

2)、添加自定义 tomcat 监控

Nagios Server:

# vim /usr/local/nagios/etc/objects/commands

添加以下内容

# ‘check_tomcat’ command definition

define command{

command_name    check_tomcat

command_line    $USER1$/check_tomcat -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$

}

 

# vim /usr/local/nagios/etc/objects/node.3.cfg

追加以下内容

define service{

use                    local-service

host_name              node.3

service_description    Check Tomcat

check_command          check_nrpe!check_tomcat!tomcat

contact_groups          admins

}

 

# service nagios restart

 

Nagios Client:

# vim /usr/local/nagios/etc/nrpe.cfg

添加以下内容

command[check_tomcat]=/usr/local/nagios/libexec/check_tomcat $ARG1$

 

# vim /usr/local/nagios/libexec/check_tomcat

#!/bin/sh

name=`basename $0`

process=`ps aux |grep -w “$1” | grep -vE “grep|$name”|wc -l |tr -d ‘ ‘`

if [$process -ge 1]

then

  echo  “$1 proces running….”

  exit 0

else

  echo  “$1 proces no exist! “

  exit 2

fi

5、windows 系统的监控

解压 NSClient++-0.2.7.zip 到 C 盘根目录

命令行:cmd

>c:\NSClient++-0.2.7

>nsclient++ /install

>nsclient++ SysTray

命令行:services.msc

找到 NSClientpp 服务,双击打开,点击”登录“标签,在”允许服务与桌面交互“前打勾

编辑 c:\NSClient++-0.2.7\NSC.ini

[modules] 模块

去掉除 CheckWMI.dll 和 RemoteConfiguration.dll 以外行的”;“

[Settings]

去掉 password 行的注释,并设置密码 123456,同时需要在 Nagios Server 端 command.cfg 配置文件中 check_nt 命令定义处配置对应的密码

define command{

command_name    check_nt

command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123456 -v $ARG1$ $ARG2$

}

去掉 allowed_hosts 行的注释,并将本行修改为 allowed_hosts=127.0.0.1/32,10.0.2.201

[NSClient]

去掉 port 行前面的注释,并设置 port=12489

 

6、配置报警

1)、声音报警

Nagios Server 端

上传音乐文件到 /usr/local/nagios/share/media 文件夹中

# vim /usr/local/nagios/etc/cgi.cfg

取消以下行前的”#“

host_unreachable_sound=hostdown.wav

host_down_sound=hostdown.wav

service_critical_sound=critical.wav

service_warning_sound=warning.wav

service_unknown_sound=warning.wav

normal_sound=noproblem.wav

 

2)、邮件报警

# yum install -y sendmail*

# service sendmail start

# vim /usr/local/nagios/etc/objects/contacts.cfg

修改

emailnagios@local.com => email*******@qq.com

# service nagios restart

# vim /usr/local/nagios/etc/objects/templates.cfg

修改 generic-service 中

notification_interval60 => notification_interval5

 

修改 local-service 中

 max_check_attempts  4 => max_check_attempts  1

 normal_check_interval 5 => normal_check_interval 5

 retry_check_interval 2 => retry_check_interval 1

表示每五分钟发送一次邮件报警,关于 Nagios 报警时间的详细配置,请参考”关于 Nagios 报警时间间隔的配置“一文,见 http://www.linuxidc.com/Linux/2014-09/106584.htm。

Nagios 的详细介绍 :请点这里
Nagios 的下载地址 :请点这里

1、软件包准备

nagios-4.0.8.tar.gz

nagios-plugins-2.0.3.tar.gz

nrpe-2.15.tar.gz

httpd-2.2.23.tar.gz

 

2、Nagios Server 端安装

1)、安装相关依赖包

yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

2)、安装 Nagios

# useradd -s /sbin/nologin nagios

# configure –prefix=/usr/local/nagios

# make all

# make install

# make install-init

# make install-commandmode

# make install-config

# chkconfig nagios on

# chkconfig –list | grep nagios

3)、安装 Nagios 插件

# tar zxvf nagios-plugins-2.0.3.tar.gz

# cd nagios-plugins-2.0.3

# ./configure –prefix=/usr/local/nagios/

# make && make install

4)、安装配置 apache

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure –prefix=/usr/local/apache2

# make && make install

# vim /usr/local/apache2/conf/http.conf

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User daemon

Group daemon

修改为

User nagios

Group nagios

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改并增加为

<IfModule dir_module>

DirectoryIndex index.html index.php

</IfModule>

AddType application/x-httpd-php .php

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

增加验证配置,即在 httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/usr/local/nagios/sbin”>

 AuthType Basic

 Options ExecCGI

 AllowOverride None

 Order allow,deny

 Allow from all

 AuthName “Nagios Access”

 AuthUserFile /usr/local/nagios/etc/htpasswd

 Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share”

<Directory “/usr/local/nagios/share”>

 AuthType Basic

 Options None

 AllowOverride None

 Order allow,deny

 Allow from all

 AuthName “nagios Access”

 AuthUserFile /usr/local/nagios/etc/htpasswd

 Require valid-user

</Directory>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

创建上面的目录验证文件 htpasswd

# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios

# vim /usr/local/nagios/etc/cgi.cfg

修改配置文件中所有含有 nagiosadmin 的内容

nagiosadmin => nagiosadmin,nagios

# scp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

# vim /etc/init.d/httpd

添加以下内容

# chkconfig: 2345 85 15

# description: Apache is a World Wide Web Server

# chkconfig httpd on

# chkconfig –list | grep httpd

 

5)、安装配置 php

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

# make && make install

# service httpd start

# service nagios start

 

6)、安装 nrpe

# tar zxvf nrpe-2.15.tar.gz

# cd nrpe-2.15

# ./configure –enable-command-args

# make all

# make install-plugin

# /usr/local/nagios/libexec/check_nrpe -H 10.0.2.203

NRPE v2.15

 

7)、配置 commands.cfg,添加 check_nrpe 定义

vim /usr/local/nagios/etc/objects/commands.cfg

# ‘check_nrpe’ command definition

define command{

command_name    check_nrpe       

command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$                         

}

 

8、配置 hosts.cfg

vim /usr/local/nagios/etc/objects/hosts.cfg

define host{

use                    linux-server

host_name              node.3

alias                  node.3

address                10.0.2.203

}

 

9、配置 node.3.cfg(也就是 node.3 的 services.cfg 文件,为了便于管理,每台机器的 services.cfg 文件分开配置,并以主机名命名)

vim /usr/local/nagios/etc/objects/node.3.cfg

define service{

use                    local-service

host_name              node.3

service_description    Current Load

check_command          check_nrpe!check_load

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Check Disk disk

check_command          check_nrpe!check_disk

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Total Processes

check_command          check_nrpe!check_total_procs

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Current Users

check_command          check_nrpe!check_users

contact_groups          admins

}

 

define service{

use                    local-service

host_name              node.3

service_description    Check Zombie Procs

check_command          check_nrpe!check_zombie_procs

contact_groups          admins

}

 

10)、配置 nagios.cfg

# vim /usr/local/nagios/etc/nagios.cfg

添加以下内容

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/node.3.cfg

 

11)、检查 nagios 配置文件,并重启 nagios 服务

# chown -R nagios.nagios /usr/local/nagios

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

# service nagios restart

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-09/106583p2.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计12927字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中