欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Nagios部署维护

程序员文章站 2022-05-16 20:31:46
...

                                    Nagios部署维护

  • 安装环境及软件版本

系统版本

rhel-server-5.3-x86_64

IP:

192.168.19.29

Nagios软件

nagios-3.5.0.tar.gz

Nagios插件

nagios-plugins-1.4.16.tar.gz

Apache版本

httpd-2.2.24.tar.gz

Php版本

php-5.4.13.tar.gz

 

 

  • 为PHP添加GD库

Nagios组件的运行依赖于httpd,gcc和php,php的运行又依赖于GD库

  1. 下载GD库和php相关组件
zlib-1.2.7.tar.gz

libpng-1.2.29.tar.gz

freetype-2.4.11.tar.gz

jpegsrc.v9.tar.gz

gd-2.0.33.tar.gz
  1. 按顺序安装GD库

安装zlib:

tar zxvf zlib-1.2.7.tar.gz

cd zlib-1.2.7

./configure

make

make install

安装libpng

tar zxvf libpng-1.2.29.tar.gz

cd libpng-1.2.29/scripts

mv makefile.linux ../makefile

cd ..

make

make install

注意:这里的makefile不是用./configure生成,而是直接从scripts/里拷贝一个!

 

安装freetype

tar zxvf freetype-2.4.11.tar.gz

cd freetype-2.4.11

./configure

make

make install

安装jpeg

tar zxvf jpegsrc.v9.tar.gz

cd jpeg-9

./configure –enable-shared

make

make test

make install

注意:这里configure一定要带--enable-shared参数,否则不会生成共享库!

 

安装GD

tar zxvf gd-2.0.33.tar.gz

cd gd-2.0.33

./configure --with-png --with-freetype --with-jpeg 

make  

make install 

 

  • 编译安装nagios
  1. 在linux防火墙上开启80,5666端口
  2. 创建nagios运行所需用户和组

[aaa@qq.com ~]# groupadd nagios

[aaa@qq.com ~]# useradd –G nagios nagios

[aaa@qq.com ~]#passwd nagios

  1. 安装nagios

[aaa@qq.com nagios]# cd software/

[aaa@qq.comios software]# tar zxvf nagios-3.5.0.tar.gz

[aaa@qq.com software]# cd nagios

[aaa@qq.com nagios]# ./configure --prefix=/home/nagios/nagios

[aaa@qq.com nagios]# make all

[aaa@qq.com nagios]# make install     安装主要程序,CGI及HTML文件

[aaa@qq.com nagios]# make install-init  把nagios做成运行脚本,nagios随开机启动

[aaa@qq.com nagios]# make install-commandmode  给外部命令访问nagios配置文件的权限

[aaa@qq.com nagios]# make install-config      把配置文件的例子复制到nagios的安装目录

 

 

  1. 验证程序是否正确安装

[aaa@qq.com nagios]# ll

总计 24

drwxrwxr-x  2 nagios nagios 4096 05-06 10:11 bin

drwxrwxr-x  3 nagios nagios 4096 05-06 10:13 etc

drwxrwxr-x  2 nagios nagios 4096 05-06 10:11 libexec

drwxrwxr-x  2 nagios nagios 4096 05-06 10:11 sbin

drwxrwxr-x 10 nagios nagios 4096 05-06 10:11 share

drwxrwxr-x  5 nagios nagios 4096 05-06 10:12 var

如果etc、bin、 sbin、 share、 var、libexec六个目录存在,则表明程序被正确安装,下边是六个目录功能的简要说明:

etc

Nagios配置文件位置,包括*.cfg文件,对象模板,密码文件

bin

Nagios执行程序所在目录,这个目录只有两个文件nagios,nagiostats

sbin

Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录

share

Nagios网页文件所在的目录

var

Nagios日志文件、spid 等文件所在的目录

libexec

Nggios插件安装目录,未装插件之前此目录为空

 

 

  • 安装nagios插件

[aaa@qq.com nagios]# cd software/

[aaa@qq.com software]# tar zxvf nagios-plugins-1.4.16.tar.gz

[aaa@qq.com software]# cd nagios-plugins-1.4.16

[aaa@qq.com nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios

[aaa@qq.com nagios-plugins-1.4.16]#make

[aaa@qq.com nagios-plugins-1.4.16]#make install

 

注意:nagios插件指定的安装路径为nagios安装路径/home/nagios/nagios,安装完成后将在目录/home/nagios/nagios/libexec中生成许多插件,这正是nagios所需的。

 

  • 安装apache

Apache的运行依赖于apr,apr-util和pcre三个包

  1. 下载apache依赖包

[aaa@qq.com nagios]# cd software/

[aaa@qq.com software]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz 

[aaa@qq.com software]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz

[aaa@qq.com software]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip

 

  1. 安装apache依赖包

安装apr

[root @nagios software]# tar -zxvf apr-1.4.5.tar.gz

[root @nagios software]# cd  apr-1.4.5 

[root @nagios apr-1.4.5]# ./configure --prefix=/usr/local/apr

[root @nagios apr-1.4.5]# make && make install

 

安装apr-util

[root @nagios software]# tar -zxvf apr-util-1.3.12.tar.gz

[root @nagios software]# cd apr-util-1.3.12

[root @nagios apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr/bin/apr-1-config

[root @nagios apr-util-1.3.12]# make && make install

 

安装pcre:

[root @nagios software]#unzip -zxvf pcre-8.10.zip

[root @nagios software]#cd pcre-8.10

[root @nagios pcre-8.10]#./configure –prefix=/usr/local/pcre

[root @nagios pcre-8.10]# make && make install

 

  1. 拷贝ape和apr-util源码到apache源码目录

[root @nagios software]# cp -rf apr-1.4.6 httpd-2.4.1/srclib/apr

[root @nagios software]# cp -rf apr-util-1.4.6 httpd-2.4.1/srclib/apr-util

 

  1. 安装apache

[root @nagios software]# tar zxvf httpd-2.2.24.tar.gz

[root @nagios software]# cd httpd-2.2.24

[aaa@qq.com httpd-2.2.24]# ./configure  --prefix=/home/nagios/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-included-apr  --enable-so --enable-mods-shared=most

[aaa@qq.com httpd-2.2.24]# make

[aaa@qq.com httpd-2.2.24]# make  install

 

 

  • 安装PHP运行环境

[aaa@qq.com ~]# cd /home/nagios/software/gd_software/

[aaa@qq.com gd_software]# tar zxvf php-5.4.13.tar.gz

[aaa@qq.com gd_software]# cd php-5.4.13

[aaa@qq.com php-5.4.13]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php --with-apxs2=/home/nagios/apache/bin/apxs

[aaa@qq.com php-5.4.13]# make

[aaa@qq.com php-5.4.13]# make test

=====================================================================

 

You may have found a problem in PHP.

This report can be automatically sent to the PHP QA team at

http://qa.php.net/reports and http://news.php.net/php.qa.reports

This gives us a better understanding of PHP's behavior.

If you don't want to send the report immediately you can choose

option "s" to save it.  You can then email it to aaa@qq.com later.

Do you want to send this report now? [Yns]: n

[aaa@qq.com php-5.4.13]# make install

注意:PHP应该在apache之后安装,否则无法在apache的modules下生成libphp5.so文件,导致不能登录页面。

  • 配置Apache
  1. 编辑apache/conf/httpd.conf文件

[aaa@qq.com conf]# vi httpd.conf

 

  1. 将apache运行用户改为nagios

 

User example  

Group example 

改为

User nagios  

Group nagios

 

  1. 修改索引页

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

改为

<IfModule dir_module>

    DirectoryIndex index.php index.html

</IfModule>

 

  1. 修改apache和nagios所属用户和组

[aaa@qq.com nagios]# chown -R nagios:nagios apache/

[aaa@qq.com nagios]# chown -R nagios:nagios nagios/

  1. 在httpconf文件末尾增加以下内容

#setting for nagios

ScriptAlias /nagios/cgi-bin  /home/nagios/nagios/sbin

<Directory "/home/nagios/nagios/sbin">      

    AuthType Basic

    Options ExecCGI

    AllowOverride None

    Order allow,deny

    Allow from all

    AuthName "Nagios Access"

    AuthUserFile  /home/nagios/nagios/etc/htpasswd

    Require valid-user

</directory>

Alias /nagios  /home/nagios/nagios/share

<Directory "/home/nagios/nagios/share">      

    AuthType Basic

    Options None

    AllowOverride None

    Order allow,deny

    Allow from all

    AuthName "nagios Access"

    AuthUserFile  /home/nagios/nagios/etc/htpasswd 

    Require valid-user

</directory>

LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php .phtml

AddType applicatoin/x-httpd-php-source .phps

AddDefaultCharset utf-8

  1. 生成用户验证文件

[aaa@qq.com nagios]# /home/nagios/apache/bin/htpasswd -c   /home/nagios/nagios/etc/htpasswd jsbzb

New password:

Re-type new password:

Adding password for user jsbzb

 

修改生成的密码文件的用户和属组

[aaa@qq.com nagios]# cd nagios/etc/

[aaa@qq.com etc]# chown nagios:nagios htpasswd

疑问:密码中不能有字母,否则无法登录,只能用数字。

  • 启动nagios和apache并登录
  1. apache配置完成后执行如下命令,检查配置是否正确

[aaa@qq.com etc]# /home/nagios/apache/bin/apachectl -t

Syntax OK

  1. 用root用户启动nagios和apache

[aaa@qq.com nagios]# ./apache/bin/apachectl start&

[aaa@qq.com nagios]# service nagios start

 

  • 至此,nagios安装完成,验证配置

在浏览器中输入地址:http://192.168.19.29/nagios,出现下图登录等待窗口,输入之前创建的用户和密码登录。

Nagios部署维护

 

登录成功后进入nagios首页

Nagios部署维护

  • 安装nagios的snmp采集插件

nagios-snmp-plugins是一套用Perl编写的通过SNMP方式监控主机的插件程序。

配置check_snmp_int.pl这些插件的使用时需要配置cpan,CPAN是Comprehensive Perl Archive Network的缩写.。它是一个巨大的Perl软件收藏库,收集了大量有用的Perl模块(modules)及其相关的文件。这里主要是使用Perl-Net-SNMP模块。

  1. 安装Perl-Net-SNMP模块

有两种方式安装:

A)通过CPAN来安装

#perl -MCPAN -e shell

cpan> install Net::SNMP

 

B) 手工安装

首先去官方网站下载以下几个模块:

Crypt::DES

Digest::MD5

Digest::SHA1

Digest::HMAC

Net::SNMP

 

下载后对于每个模块依次按照下面的方式安装

#tar zxvf *.tar.gz   表示模块名,具体请按上面提到的模块替换

#cd             表示模块名,具体请按上面提到的模块替换

#perl Makefile.pl

#make test

#make install

注意:Net::SNMP模块必须在最后安装。至此Net::SNMP手动安装完毕

  1. 安装snmp采集插件

[aaa@qq.com software]# tar zxvf nagios-snmp-plugins.1.1.1.tgz

[aaa@qq.com software]# cd nagios_plugins

[aaa@qq.com nagios_plugins]# ./install.sh

 

 

  • 安装配置NRPE(for linux)

Nagios nrpe 能够实现调用远程主机上的nagios插件及其脚本来实现远程监控。

  1. 服务器端安装nrpe插件

[aaa@qq.com Client]# tar zxvf nrpe-2.14.tar.gz

[aaa@qq.com Client]# cd nrpe-2.14

[aaa@qq.com nrpe-2.14]# ./configure --prefix=/home/nagios/nagios

[aaa@qq.com nrpe-2.14]# make all

[aaa@qq.com nrpe-2.14]# make install-plugin

[aaa@qq.com nrpe-2.14]# cd /home/nagios/nagios/libexec/

[aaa@qq.com libexec]# ll

总计 6812

-rwxr-xr-x 1 nagios nagios 382372 05-07 17:23 check_apt

-rwxr-xr-x 1 nagios nagios   2247 05-07 17:23 check_breeze

-rwxr-xr-x 1 nagios nagios 159218 05-07 17:23 check_by_ssh

lrwxrwxrwx 1 nagios nagios      9 05-07 17:23 check_clamd -> check_tcp

-rwxr-xr-x 1 nagios nagios 112929 05-07 17:23 check_cluster

-rwxrwxr-x 1 nagios nagios  65885 05-08 10:37 check_nrpe

………省略

Nagios只要拥有NRPE的扩展插件功能就可以了,所以在Nagios监测服务器安装NRPE工作到这步就可以了。

 

  1. 客户端安装nrpe插件

Nrpe插件依赖于gcc、openssl、openssl-devel三个包,如果没有需要先安装。

检查

rpm –q gcc

rpm –q openssl openssl-devel

安装

yum -y install gcc gcc-c++

yum -y install openssl openssl-devel

 

创建nagios用户

[aaa@qq.com ~]# groupadd -g 501 nagios

[aaa@qq.com ~]# useradd -u 500 -g nagios nagios

[aaa@qq.com ~]# passwd nagios

nagios用户密码统一使用:zzb1201

 

拷贝以下三个文件到客户端,从服务器(192.168.19.29)下载以下程序

服务器目录:/home/nagios/software/Client

nagios-plugins-1.4.16.tar.gz

nrpe-2.14.tar.gz

check_linux_stats.pl

Sys-Statistics-Linux-0.66.tar.gz

 

 

安装nagios插件

[aaa@qq.com ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz

[aaa@qq.com ~]# cd nagios-plugins-1.4.16

[aaa@qq.com nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios

[aaa@qq.com nagios-plugins-1.4.16]# make

[aaa@qq.com nagios-plugins-1.4.16]# make install

[aaa@qq.com nagios-plugins-1.4.16]# chown -R nagios:nagios /home/nagios/nagios

 

安装nrpe插件

[aaa@qq.com ~]# tar -zxvf nrpe-2.14.tar.gz

[aaa@qq.com ~]# cd nrpe-2.14

[aaa@qq.com nrpe-2.14]# ./configure --prefix=/home/nagios/nagios

[aaa@qq.com nrpe-2.14]# make all

[aaa@qq.com nrpe-2.14]# make install-plugin

[aaa@qq.com nrpe-2.14]# make install-daemon

[aaa@qq.com nrpe-2.14]# make install-daemon-config

[aaa@qq.com localhost nrpe-2.14]# make install-xinetd

 

打开防火墙规则

检查防火墙是否开启,哪果没有开启,则跳过此步

service iptables status

iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

service iptables save

安装Sys-Statistics-Linux-0.66.tar.gz

[aaa@qq.com software]# tar zxvf Sys-Statistics-Linux-0.66.tar.gz

[aaa@qq.com software]# cd Sys-Statistics-Linux-0.66

[aaa@qq.com Sys-Statistics-Linux-0.66]# perl Makefile.PL

[aaa@qq.com Sys-Statistics-Linux-0.66]# make

[aaa@qq.com Sys-Statistics-Linux-0.66]# make test

[aaa@qq.com Sys-Statistics-Linux-0.66]# make install

 

  1. 配置客户端nrpe参数
  1. 编辑/etc/xinetd.d/nrpe文件,增加远程服务器地址

only_from       = 127.0.0.1 192.168.19.29     两地址之间用空格隔开

 

重启xinetd服务

service xinetd restart

 

编辑/home/nagios/nagios/etc/nrpe.cfg,修改或增加以下内容

server_address= xxx.xxx.xxx.xxx(本机地址)

allowed_hosts=127.0.0.1, 172.16.84.254 ,192.168.19.29

注意:这里要增加两个地址:一个是本机网关地址,另一个是远程监控服务器地址

 

配置nrpe命令

 

command[check_users]=/home/nagios/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/home/nagios/nagios/libexec/check_load -w 15,10,5 -c 20,15,10

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

#command[check_zombie_procs]=/home/nagios/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/home/nagios/nagios/libexec/check_procs -w 250 -c 400

 

command[check_mem]=/home/nagios/nagios/libexec/check_linux_stats.pl -M  -w 80,50 -c 90,50

command[check_diskstat_local]=/home/nagios/nagios/libexec/check_linux_stats.pl -D -w 10 -c 5 -p /,/boot,/home/csuser/Logs

command[check_diskstat_nas]=/home/nagios/nagios/libexec/check_linux_stats.pl -D -w 10 -c 5 -p /nas/homeapach,/httplogs,/nas/blogwww,/nas/uc,/nas/bar,/nas/hidden

command[check_cpu]=/home/nagios/nagios/libexec/check_linux_stats.pl  -C -w 80 -c 90

command[check_netword_usage]=/home/nagios/nagios/libexec/check_linux_stats.pl   -N -w 419430400 -c 838860800 -p eth0

 

  1. 安装check_linux_stat插件
  1. 拷贝check_linux_stats.pl到nagios/libexec目录下
  2. 修改check_linux_stats.pl的所属用户和属组

chown nagios:nagios check_linux_stats.pl

chmod 755 check_linux_stats.pl

 

  1. 启动nrpe

/home/nagios/nagios/bin/nrpe -c  /home/nagios/nagios/etc/nrpe.cfg -d

  1. 添加开机启动

echo '/home/nagios/nagios/bin/nrpe -c  /home/nagios/nagios/etc/nrpe.cfg -d' >> /etc/rc.d/rc.local

 

 

  1. 配置服务器端nrpe参数
  1. 如果是首次配置,请在/home/nagios/nagios/etc/objects目录下创建以自己命名的目录,监控对象以负责人分类,如:监控张三负责的服务器,创建目录zhangs
  2. 创建(首次)主机组和服务组文件

服务组:

[aaa@qq.com objects]$ vi servicegroups.cfg

 

define servicegroup {

        servicegroup_name    zhangs-linux-services

     alias   Zhangs Linux Services

}

 

主机组

[aaa@qq.com objects]$vi hostgroups.cfg

define hostgroup{

        hostgroup_name  zhangs-linux-servers ; The name of the hostgroup

        alias           Zhangs Linux Servers ; Long name of the group

        members         localhost

        }

把主机组文件和服务组文件添加到nagios.cfg

[aaa@qq.com etc]$ vi nagios.cfg

cfg_file=/home/nagios/nagios/etc/objects/hostgroups.cfg

cfg_file=/home/nagios/nagios/etc/objects/servicegroups.cfg

 

  1. 添加联系人和联系人组(首次)

[aaa@qq.com objects]$ vi contacts.cfg

添加以下内容

define contact{

        contact_name                    zhangs

        use                             generic-contact

        alias                           zhangs

        email                           aaa@qq.com

        }

 

define contactgroup{

        contactgroup_name        zhangs-cg

        alias                     zhangs-cg

        members                 jsbzb,zhangs         #添加值班邮箱和自己常用邮箱,多个联系人之间用逗号隔开

        }

 

  1. 在zhangsan目录下创建对象

vi zhangs-rhel5-linux.cfg

说明:命名规则按 “负责人-机器名-系统类型” 定义,太长可以简写。

添加以下内容

define host{

use         linux-server

host_name   zhangs-rhel5-linux

alias       zhangs-rhel5-linux

address     172.16.84.161

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Current Load

check_command       check_nrpe!check_load

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Current Users  

check_command       check_nrpe!check_users

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Total Processes

check_command       check_nrpe!check_total_procs

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Mem Usage

check_command       check_nrpe!check_mem

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Disk Stat

check_command       check_nrpe!check_diskstat_local

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Disk Stat

check_command       check_nrpe!check_diskstat_nas

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           zhangs-rhel5-linux

service_description Cpu Usage

check_command       check_nrpe!check_cpu

servicegroups           zhangs_linux_services

contact_groups          zhangs-cg

}

 

define service{

use                 generic-service

host_name           wangy-homeuc1-linux

service_description Network Usage

check_command       check_nrpe!check_netword_usage

servicegroups           wangy-linux-services

contact_groups          zhangs-cg

}

 

  1. 编辑nagios.cfg文件

vi /home/nagios/nagios/etc/nagios.cfg

添加刚创建的对象文件

#zhangs object config files

cfg_file=/home/nagios/nagios/etc/objects/zhangs/ zhangs-rhel5-linux.cfg

 

  1. 编辑主机组文件hostgroups.cfg添加新加主机

[aaa@qq.com objects]$vi hostgroups.cfg

define hostgroup{

        hostgroup_name  zhangs-linux-servers ; The name of the hostgroup

        alias           Zhangs Linux Servers ; Long name of the group

        members         localhost, zhangs-rhel5-linux

        }

 

 

  1. 验证nagios配置

[aaa@qq.com ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg

………………

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected during the pre-flight check

 

  1. 重新装载nagios配置

service nagios reload

  1. 刷新页面查看增加结果

 

  • 安装配置NSClient++(for windows)

监控Windows需要在windows安装一个插件nsclient++,有32位和64位,根据实际安装

  1. nsclient++获取方法:
  1. ftp到监控服务器(192.168.19.29)/home/nagios/software/Client目录下下载
  2. 下载地址:http://nsclient.org/nscp/downloads

 

  1. 客户端安装配置nsclient++
  1. 下载nsclient++后安装

安装过程十分简单,直接点击下一步,下一步即可。安装过程注意如下图的设置即可

Nagios部署维护

 

  1. 配置nsclient++,配置文件是NSC.ini。用记事本编辑nsc.ini,修改以下几项

去掉注释符号";",除了CheckWMI.dll和RemoteConfiguration.dll

[modules]

NRPEListener.dll

NSClientListener.dll

NSCAAgent.dll

CheckWMI.dll

FileLogger.dll

CheckSystem.dll

CheckDisk.dll

CheckEventLog.dll

CheckHelpers.dll

FileLogger.dll

CheckSystem.dll

CheckDisk.dll

NSClientListener.dll

NRPEListener.dll

SysTray.dll

CheckEventLog.dll

CheckHelpers.dll

;CheckWMI.dll

CheckNSCP.dll

CheckExternalScripts.dll

NSCAAgent.dll

LUAScript.dll

;RemoteConfiguration.dll

NRPEClient.dll

CheckTaskSched.dll

 

去掉nrpe口令,加”;”即可

[Settings]

;# OBFUSCATED PASSWORD

;obfuscated_password=Jw0KAUUdXlAAUwASDAAB

;# PASSWORD

;password=secret-password

 

配置端口和监控服务器地址

[Settings]

allowed_hosts=192.168.19.29

注意:如果是新华社机房的机器,应该是allowed_hosts=172.16.84.254

[NSClient]

port=12489

 

  1. 启动客户端nsclient++

从 开始-程序-NSClient++ 找到Start NSClient++ (x64),并点击启动。

在安装目录下执行NSClient++ -start,停止服务执行NSClient++ -stop

  1. 验证端口,5666和12489

netstat -an | more

Nagios部署维护

 

  1. 服务器端配置
  1. 编辑主机组文件hostgroups.cfg添加新主机组

[aaa@qq.com objects]$vi hostgroups.cfg

define hostgroup{

        hostgroup_name  zhangs-linux-servers ; The name of the hostgroup

        alias           Zhangs Linux Servers ; Long name of the group

        members         localhost, zhangs-rhel5-linux

        }

define hostgroup{

    hostgroup_name  zhangs-windows-servers ; The name of the hostgroup

    alias           Zhangs Windows Servers ; Long name of the group

members       zhangs-lenovopc-win7

        }

  1. 编辑服务组文件servicegroups.cfg添加新服务

[aaa@qq.com objects]$ vi servicegroups.cfg

 

define servicegroup {

servicegroup_name    zhangs-linux_services

alias   Zhangs Linux Services

}

define servicegroup {

        servicegroup_name    zhangs_windows_services

        alias   Zhangs Windows Services

}

 

  1. 编辑联系人文件,增加联系人和联系人组

define contact{

        contact_name                    zhangs

        use                             generic-contact

        alias                           zhangs

        email                           aaa@qq.com

        }

define contactgroup{

           contactgroup_name        zhangs-cg

           alias                    zhangs-cg

           members                  jsbzb,zhangs

           }

 

  1. 在自己的目录(没有请创建)下创建对象配置文件

vi zhangs-lenovopc-win7.cfg

define host{

use             windows-server

host_name       zhangs-lenovopc-win7

alias           zhangs-lenovopc-win7

address         192.168.16.157

}

 

define service {

                                     host_name               zhangs-lenovopc-win7        

                                     service_description     Check Cpuload        

                                     use                     generic-service        

                                     check_command           check_nt!CPULOAD!-l 5,70,80,10,80,90

                servicegroups                   zhangs_windows_services

contact_groups          zhangs-cg

}

 

define service {

                                     host_name               zhangs-lenovopc-win7        

                                     service_description     Check Uptime        

                                     use                     generic-service

                                     check_command           check_nt!UPTIME

                servicegroups                   zhangs_windows_services

                contact_groups          zhangs-cg

}

 

define service {

                                     host_name               zhangs-lenovopc-win7        

                                     service_description     Check Note        

                                     use                     generic-service

                                     check_command           check_nt!PROCSTATE! -d SHOWALL -l YoudaoNote.exe        

                servicegroups                   zhangs_windows_services

                contact_groups          zhangs-cg

}

 

define service {

        host_name               zhangs-lenovopc-win7

        service_description     Memory Usage

        use                     generic-service

        check_command           check_nt!MEMUSE!-w 80 -c 90

        servicegroups                   zhangs_windows_services

        contact_groups          zhangs-cg

}

 

define service {

        host_name               zhangs-lenovopc-win7

        service_description     Drive C:\ Space

        use                     generic-service

        check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90

        servicegroups                   zhangs_windows_services

        contact_groups          zhangs-cg

}

define service {

        host_name               zhangs-lenovopc-win7

        service_description     Drive D:\ Space

        use                     generic-service

        check_command           check_nt!USEDDISKSPACE!-l d -w 80 -c 90

        servicegroups                   zhangs_windows_services

        contact_groups          zhangs-cg

}

 

  1. 注册windows主机

编辑nagios/etc/nagios.cfg文件,添加以下内容

#weiyq object config files

cfg_file=/home/nagios/nagios/etc/objects/zhangs/zhangs-lenovopc-win7.cfg

 

  1. 验证nagios配置

[aaa@qq.com ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg

………………

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected during the pre-flight check

 

  1. 重新装载配置

service nagios reload

 

 

 

 

 

 

  • 网络设备监控配置(Cisco)

简介:此处以Cisco为例,其它网络设备检控命令可能需要调整。Cisco交换机都支持SNMP协议,只需要简单的设置即可开启。在安装Nagios之前,必须已经安装Net-Utils及其开发组件,参考本文第十步。由于使用check_snmp检测的结果不够人性化,大部分的结果都需要重新调整。使用Perl脚本调用NET::SNMP模块,实现收集监控结果,并重新输出,更易阅读和使用。

 

比较好的perl脚本有如下几个

从服务器(192.168.19.29)的目录/home/nagios/software/net_perl下载

check_snmp_cisco_loadavg.pl

check_snmp_cisco_memutil.pl

check_snmp_cisco_ifstatus.pl

check_snmp_int.pl

check_snmp_env.pl

 

监控服务器端配置步骤:

  1. 增加perl脚本
  1. 拷贝check_snmp_cisco_loadavg.pl、check_snmp_cisco_memutil.pl、check_snmp_cisco_ifstatus.pl三个文件到/home/nagios/libexec目录下
  2. 修改脚本属组和权限

chown nagios:nagios check_snmp_cisco_*.pl

chmod 755 check_snmp_cisco_*.pl

 

  1. 编辑命令配置文件commands.cfg,增加网络监控命令

vi nagios/etc/objects/commands.cfg

 

#net command add by wangyong 20130514

 

define command{

        command_name check_snmp_cisco_loadavg

        command_line $USER1$/check_snmp_cisco_loadavg.pl -H $HOSTADDRESS$ $ARG1$

        }

 

define command{

        command_name check_snmp_cisco_memutil

        command_line $USER1$/check_snmp_cisco_memutil.pl -H $HOSTADDRESS$ $ARG1$

        }

 

define command{

        command_name check_snmp_cisco_ifstatus

        command_line $USER1$/check_snmp_cisco_ifstatus.pl -H $HOSTADDRESS$  $ARG1$

        }

 

define command{

        command_name check_snmp_int

        command_line $USER1$/check_snmp_int.pl -H $HOSTADDRESS$  $ARG1$

        }

 

define command{

        command_name check_snmp_env

        command_line $USER1$/check_snmp_env.pl -H $HOSTADDRESS$  $ARG1$

}

 

  1. 添加网络主机对象

如果是第一次添加,在nagios/etc/objects目录下创建自己的对象目录

[aaa@qq.com objects]$ mkdir zhangs

进入zhangs目录,创建网络设备对象

vi zhangs-cisco2950-switch.cfg

 

define host{

use         generic-switch

host_name   zhangs-cisco2950-switch

alias       zhangs-cisco2950-switch

address     192.168.16.160(交换机地址)

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     PING

        check_command           check_ping!200.0,20%!600.0,60%

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

 

}

 

define service{

        use                     generic-service;

        host_name               zhangs-cisco2950-switch

        service_description     Uptime

        check_command           check_snmp!-C public -o sysUpTime.0

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Port 47 Link Status

        check_command           check_snmp!-C public -o ifOperStatus.47 -r 1 -m RFC1213-MIB

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     CPU Avg Load

        check_command           check_snmp_cisco_loadavg! -C public -w 70 -c 90

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Memery Usage

        check_command           check_snmp_cisco_memutil! -C public -w 70 -c 90

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Port 47 traffic Status

        check_command           check_snmp_cisco_ifstatus! -C public -i "FastEthernet0/47"

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     System Info

        check_command           check_snmp! -C public -o sysDescr.0

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Check Fan Ps Temp Status

        check_command           check_snmp_env!  -C public

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Vlan1 traffic status

        check_command           check_snmp_int! -C public  -n Vlan1 -f

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

define service{

        use                     generic-service

        host_name               zhangs-cisco2950-switch

        service_description     Check Port[41-47] status

        check_command           check_snmp_int! -C public  -n "Fast.*0.4[1234567]"

        servicegroups           zhangs-switch-services

contact_groups          zhangs-cg

}

 

  1. 添加网络服务组

[aaa@qq.com objects]$ vi servicegroups.cfg

define servicegroup {

       servicegroup_name    zhangs-switch-services

       alias   Zhangs Switch Services

}

 

  1. 添加网络主机组

[aaa@qq.com objects]$vi hostgroups.cfg

define hostgroup{

        hostgroup_name  zhangs-switch-servers ; The name of the hostgroup

        alias           Zhangs Switch Servers ; Long name of the group

        members       zhangs-cisco2950-switch

}

 

  1. 在nagios/etc/nagios.cfg中添加网络主机配置

[aaa@qq.com etc]$ vi nagios.cfg

 

cfg_file=/home/nagios/nagios/etc/objects/zhangs/ zhangs-cisco2950-switch.cfg

 

  1. 编辑联系人文件,增加联系人和联系人组

define contact{

        contact_name                    zhangs

        use                             generic-contact

        alias                           zhangs

        email                           aaa@qq.com

        }

define contactgroup{

           contactgroup_name        zhangs-cg

           alias                    zhangs-cg

           members                  jsbzb,zhangs

           }

 

  1. 检查配置正确性

[aaa@qq.com ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg

………………

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected during the pre-flight check

 

  1. 重新加载配置文件

service nagios reload

 

  1. 刷新监控页面查看添加结果。

 

 

  • Pnp4nagios安装配置

pnp4nagios是基于RRD轮循(环状)数据库中所提供的综合信息,以可视化图形的方式呈现给用户的一款nagios插件;

 

  1. 安装rrdtools

官网下载地址:http://oss.oetiker.ch/rrdtool/

yum install rrdtool-perl

 

  1. 检查PHP版本

PHP版本必须在5.2以上

[aaa@qq.com ~]# php -v

PHP 5.4.13 (cli) (built: May  6 2013 17:41:39)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

 

  1. 安装pnp4nagios

[aaa@qq.com ~]# cd /home/nagios/software/pnp4nagios/

[aaa@qq.com pnp4nagios]# tar zxvf pnp4nagios-0.6.21.tar.gz

[aaa@qq.com pnp4nagios]# cd pnp4nagios-0.6.21

[aaa@qq.com pnp4nagios-0.6.21]# ./configure --prefix=/home/nagios/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios

[aaa@qq.com pnp4nagios-0.6.21]# make all

[aaa@qq.com pnp4nagios-0.6.21]#  make install

[aaa@qq.com pnp4nagios-0.6.21]# make install-webconf

[aaa@qq.com pnp4nagios-0.6.21]# make install-config

[aaa@qq.com pnp4nagios-0.6.21]# make install-init

 

  1. 更改pnp4nagios属组

[aaa@qq.com nagios]# chown -R nagios:nagios  pnp4nagios/

 

  1. 配置pnp4nagios

这里我们使用Bulk Mode with NPCD模式

  1. 创建配置文件

[aaa@qq.com ~]$ cd pnp4nagios/etc/

[aaa@qq.com etc]$ mv misccommands.cfg-sample misccommands.cfg

[aaa@qq.com etc]$ mv nagios.cfg-sample nagios.cfg

[aaa@qq.com etc]$ mv rra.cfg-sample rra.cfg

 

[aaa@qq.com etc]$ cd pages/

[aaa@qq.com pages]$ mv web_traffic.cfg-sample web_traffic.cfg

 

[aaa@qq.com check_commands]$ mv check_all_local_disks.cfg-sample check_all_local_disks.cfg

[aaa@qq.com check_commands]$ mv check_nrpe.cfg-sample check_nrpe.cfg

[aaa@qq.com check_commands]$ mv check_nwstat.cfg-sample check_nwstat.cfg

 

  1. 删除install.php

[aaa@qq.com ~]$ cd pnp4nagios/share/

[aaa@qq.com share]$ mv install.php install.php.bak

 

  1. 启动服务

[aaa@qq.com nagios]# service npcd start

Starting npcd: done.

 

  1. 修改nagios配置文件,打开performance_data

[aaa@qq.com ~]$ vi nagios/etc/nagios.cfg

修改以下参数

process_performance_data=1

 

添加以下参数

host_perfdata_file=/home/nagios/pnp4nagios/var/host-perfdata

service_perfdata_file=/home/nagios/pnp4nagios/var/service-perfdata

 

service_perfdata_file=/home/nagios/pnp4nagios/var/service-perfdata

service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

service_perfdata_file_mode=a

service_perfdata_file_processing_interval=15

service_perfdata_file_processing_command=process-service-perfdata-file

 

#

# host performance data starting with Nagios 3.0

#

host_perfdata_file=/home/nagios/pnp4nagios/var/host-perfdata

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$

host_perfdata_file_mode=a

host_perfdata_file_processing_interval=15

host_perfdata_file_processing_command=process-host-perfdata-file

 

  1. 编辑nagios命令配置文件,添加以下命令

vi nagios/etc/objects/commands.cfg

 

注释原来的process-service-perfdata-file和process-host-perfdata-file

define command{

       command_name    process-service-perfdata-file

       command_line    /bin/mv /home/nagios/pnp4nagios/var/service-perfdata /home/nagios/pnp4nagios/var/spool/service-perfdata.$TIMET$

}

 

define command{

       command_name    process-host-perfdata-file

       command_line    /bin/mv /home/nagios/pnp4nagios/var/host-perfdata /home/nagios/pnp4nagios/var/spool/host-perfdata.$TIMET$

}

 

  1. 修改nagios模板文件

Vi nagios/etc/objects/templates.cfg

在 host 模板中加入

action_url      /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_

 

在service 模板中加入

action_url     /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

 

  1. 验证nagios配置

[aaa@qq.com ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg

………………

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected during the pre-flight check

  1. 重新加载nagios配置

[aaa@qq.com nagios]# service nagios reload

Running configuration check...done.

Reloading nagios configuration...done

 

  1. 修改apache配置

[aaa@qq.com ~]$ vi apache/conf/httpd.conf

 

在文件最后加入以下内容

Alias /pnp4nagios "/home/nagios/pnp4nagios/share"

<Directory "/home/nagios/pnp4nagios/share">

        AllowOverride None

        Order allow,deny

        Allow from all

<IfModule mod_rewrite.c>

        RewriteEngine On

        Options FollowSymLinks

        RewriteBase /pnp4nagios/

        RewriteRule ^(application|modules|system) - [F,L]

        RewriteCond %{REQUEST_FILENAME} !-f

        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule .* index.php/$0 [PT,L]

</IfModule>

</Directory>

 

  1. 重启apache服务

[aaa@qq.com nagios]# ./apache/bin/apachectl stop

[aaa@qq.com nagios]# ./apache/bin/apachectl start&

 

 

  • 安装配置check_oracle_health
  1. 安装客户端NRPE

参考第十一章节

 

  1. 设定系统环境变量

在root用户下,编辑.bash_profile,添加ORACLE环境变量,要和ORACLE用户的.bash_profile文件中的设置一样。

注:必须先配置环境变量,否则perloracle插件安装报错。

 

ORACLE_BASE=/u01/app/11.1.0

ORACLE_SID=zzbrac11

CRS_HOME=$ORACLE_BASE/crs

ORACLE_HOME=$ORACLE_BASE/db

PATH=$PATH:$CRS_HOME/bin:$ORACLE_HOME/bin:/usr/bin

LD_LIBRARY_PATH=$ORACLE_HOME/lib:$CRS_HOME/lib:/lib:/usr/lib

CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

export ORACLE_BASE ORACLE_SID CRS_HOME  ORACLE_HOME CLASSPATH PATH LD_LIBRARY_PATH

 

  1. 安装check_oracle_health

[aaa@qq.com software]# tar zxvf check_oracle_health-1.7.7.3.tar.gz

[aaa@qq.com software]# cd check_oracle_health-1.7.7.3

[aaa@qq.com check_oracle_health-1.7.7.3]# ./configure --prefix=/home/nagios/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --with-mymodules-dir=/home/nagios/nagios/libexec/ --with-mymodules-dyn-dir=/home/nagios/nagios/libexec/

 

[aaa@qq.com check_oracle_health-1.7.7.3]# make all

[aaa@qq.com check_oracle_health-1.7.7.3]# make install

 

[aaa@qq.com check_oracle_health-1.7.7.3]# chown -R nagios:nagios /home/nagios/nagios/

 

  1. 安装perl的oracle插件

[aaa@qq.com software]# tar zxvf DBI-1.609.tar.gz

[aaa@qq.com software]# cd DBI-1.609

[aaa@qq.com DBI-1.609]# perl Makefile.PL

[aaa@qq.com DBI-1.609]# make all

[aaa@qq.com DBI-1.609]# make install

 

[aaa@qq.com software]# tar zxvf DBD-Oracle-1.24a.tar.gz

[aaa@qq.com software]# cd DBD-Oracle-1.24

[aaa@qq.com DBD-Oracle-1.24]# perl Makefile.PL

[aaa@qq.com DBD-Oracle-1.24]# make all

[aaa@qq.com DBD-Oracle-1.24]# make install

 

  1. 配置检测命令

[aaa@qq.com ~]$ vi nagios/etc/nrpe.cfg

 

# The following is oracle command arguments

command[oracheck_conn_time]=/home/nagios/nagios/libexec/check_oracle_health --connect='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.84.59)(PORT=1521))(CONNECT_DATA=(SID=zzbrac11)))' --username NEWSBLOG --password NEWSBLOG --mode connection-time

command[oracheck_tnsping]=/home/nagios/nagios/libexec/check_oracle_health --connect='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.84.59)(PORT=1521))(CONNECT_DATA=(SID=zzbrac11)))'  --mode tnsping

 

  1. 重启客户端nrpe服务

/home/nagios/nagios/bin/nrpe -c /home/nagios/nagios/etc/nrpe.cfg -d

 

  1. 配置服务器端服务

参考十一章节第4小节

 

 

 

 

  • 安装配置check_mssql_health
  1. 安装check_mssql_health

[aaa@qq.com mssqlserver]# tar zxvf check_mssql_health-1.5.19.1.tar.gz

[aaa@qq.com mssqlserver]# cd check_mssql_health-1.5.19.1

[aaa@qq.com check_mssql_health-1.5.19.1]# ./configure --prefix=/home/nagios/nagios --with-nagios-user=nagios --with-nagios-group=nagios

[aaa@qq.com check_mssql_health-1.5.19.1]# make && make install

 

[aaa@qq.com libexec]# chown nagios:nagios /home/nagios/nagios/libexec/check_mssql_health

 

  1. 安装、配置freetds-0.82

说明:在linux下连接MSSQL比较困难,微软没有提供任何接口给开发人员。还好,MSSQL是从Sybase衍生出来的,有些人做了Sybase的Linux下的连接库,这些连接库同时也能支持MSSQL,FreeTDS就是这样的一个软件。

  1. 安装freetds-0.82

[aaa@qq.com mssqlserver]# tar xvzf freetds-0.82.tar.gz

[aaa@qq.com mssqlserver]# cd freetds-0.82

[aaa@qq.com freetds-0.82]# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib

[aaa@qq.com freetds-0.82]# make && make install

  1. 配置freetds-0.82

配置root用户环境变量

[aaa@qq.com ~]# vi .bash_profile

 

SYBASE=/usr/local/freetds

FREETDS_HOME=/usr/local/freetds

PATH=$FREETDS_HOME/bin:$PATH

 

export SYBASE FREETDS_HOME PATH

export  LD_LIBRARY_PATH=/usr/local/freetds/lib/

 

[aaa@qq.com ~]# source .bash_profile

 

配置sql servers

Vi /usr/local/freetds/etc/freetds.conf

 

#juyuan1 sql server

[server_juyuan1]

        host = 172.16.84.31

        port = 1433

        tds version = 7.0

 

增加 /usr/local/freetds/lib 到 /etc/ld.so.conf, 然后,运行ldconfig

[aaa@qq.com ~]# vi /etc/ld.so.conf

 

include ld.so.conf.d/*.conf

/usr/local/freetds/lib

 

[aaa@qq.com ~]# ldconfig

如果不增加/usr/local/freetds/lib,手工执行命令成功,但是nagios自动运行失败,错误如下:

cannot connect to xxx.xxx.xxx.xxx. install_driver(Sybase) failed: Can't load '/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Sybase/Sybase.so' for module DBD::Sybase: libct.so.4: 无法打开共享对象文件: 没有那个文件或目录 at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.

 

  1. 安装DBI和DBD-Sybase

[aaa@qq.com Client]# tar zxvf DBI-1.609.tar.gz

[aaa@qq.com Client]# cd DBI-1.609

[aaa@qq.com DBI-1.609]# perl Makefile.PL

[aaa@qq.com DBI-1.609]# make

[aaa@qq.com DBI-1.609]# make test

[aaa@qq.com DBI-1.609]# make install

 

[aaa@qq.com mssqlserver]# tar zxvf DBD-Sybase-1.15.tar.gz

[aaa@qq.com mssqlserver]# cd DBD-Sybase-1.15

[aaa@qq.com DBD-Sybase-1.15]# perl Makefile.PL

[aaa@qq.com DBD-Sybase-1.15]# make

[aaa@qq.com DBD-Sybase-1.15]# make test

注意:此处会有如下错误,可以忽略

Failed 11/13 test scripts, 15.38% okay. 216/241 subtests failed, 10.37% okay.

make: *** [test_dynamic] 错误 9

[aaa@qq.com DBD-Sybase-1.15]# make install

 

 

  1. 测试连接

[aaa@qq.com ~]# cd /home/nagios/nagios/libexec

[aaa@qq.com libexec]# ./check_mssql_health --server=serve_juyuan2 --username=sa --password=xxx --mode=connected-users

OK - 6 connected users | connected_users=6;50;80

 

这种方法绕过了配置文件(/usr/local/freetds/etc/freetds.conf)

[aaa@qq.com libexec]# ./check_mssql_health --hostname=192.168.16.157 -port=1433 --username=sa --password=xxx --mode=connected-users

 

  1. 添加模板

# 'check_mssql_health ' command definition

define command{

        command_name    check_mssql_health

        command_line    $USER1$/check_mssql_health $ARG1$

        }

 

  1. 添加服务

define service {

        host_name               liy-juyuan2-win2003

        service_description     Check Sqlserver Users

        use                     generic-service

        check_command           check_mssql_health! --server=server_juyuan2 --username=sa --password=1234juyuan --mode=connected-users

        servicegroups           liy-windows-services

        contact_groups          liy-cg

}

 

  • 安装NDOUtils
  1. 安装mysql数据库服务器

安装依赖包

yum -y install cmake ncurses ncurses-devel bison bison-devel boost boost-devel gcc-c++

mysql-5.7.11依赖boost_1_59_0.tar.gz

创建数据库用户和组

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

创建目录结构

mkdir -p /home/mysql/mysql5.7.17/data

mkdir -p /home/mysql/mysql5.7.17/binlog

mkdir -p /home/mysql/mysql5.7.17/logs

mkdir -p /home/mysql/mysql5.7.17/relaylog

mkdir -p /home/mysql/mysql5.7.17/etc

mkdir -p /var/lib/mysql

安装mysql

[aaa@qq.com ]$ cd software/

[aaa@qq.com software]$ tar zxvf mysql-5.7.17.tar.gz

[aaa@qq.com software]$ cd mysql-5.7.17/

 

cmake -DCMAKE_INSTALL_PREFIX="/home/mysql/mysql5.7.17" -DDEFAULT_CHARSET=utf8 -DMYSQL_DATADIR="/home/mysql/mysql5.7.17/data/" -DCMAKE_INSTALL_PREFIX="/home/mysql/mysql5.7.17/mysql" -DINSTALL_PLUGINDIR=plugin -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_DEBUG_SYNC=0 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=1 -DWITH_ZLIB=system -DWITH_EXTRA_CHARSETS=none -DMYSQL_MAINTAINER_MODE=OFF -DEXTRA_CHARSETS=all -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_BOOST=/home/mysql/software/mysql-5.7.17/boost

make

make install

 

[aaa@qq.com mysql]# chown -R mysql.mysql mysql5.7.17/

 

修改mysql配置文件

vim /etc/my.cnf

 

[mysqld]

#datadir=/var/lib/mysql

#socket=/var/lib/mysql/mysql.sock

basedir=/home/mysql/mysql5.7.17/mysql

datadir=/home/mysql/mysql5.7.17/data

socket=/home/mysql/mysql5.7.17/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

 

 

character-set-server = utf8

port = 3306

log-bin=/home/mysql/mysql5.7.17/binlog/mysql-bin

server-id = 1

 

[mysqld_safe]

#log-error=/var/log/mariadb/mariadb.log

#pid-file=/var/run/mariadb/mariadb.pid

 

log-error=/home/mysql/mysql5.7.17/logs/mysql.log

pid-file=/home/mysql/mysql5.7.17/mysql.pid

 

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

 

配置mysql服务

[aaa@qq.com mysql]# cp ./support-files/mysql.server /etc/init.d/mysql

 

初始化mysql

[aaa@qq.com ~]$ cd /home/mysql/mysql5.7.17/mysql/bin

[aaa@qq.com bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql/mysql5.7.17/mysql --datadir=/home/mysql/mysql5.7.17/data

 

启动mysql服务

[aaa@qq.com mysql]# service mysql start

Starting MySQL. SUCCESS!

 

[aaa@qq.com bin]# chkconfig mysql on

 

修改数据库root密码,创建ndo数据库和用户

[aaa@qq.com ~]# su - mysql

上一次登录:二 2月 21 10:58:40 CST 2017从 wangyong-pc.zzb.localpts/1 上

[aaa@qq.com ~]$

[aaa@qq.com ~]$ vim .bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

 

# User specific environment and startup programs

 

PATH=$PATH:$HOME/.local/bin:$HOME/bin:~/mysql5.7.17/mysql/bin

 

export PATH

 

 

ln -s /home/mysql/mysql5.7.17/mysql.sock /tmp/mysql.sock

 

[aaa@qq.com ~]$ mysql -uroot -p

 

mysql>  alter user 'root'@'localhost' IDENTIFIED BY 'mysql';

Query OK, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

mysql> create database ndodb;

Query OK, 1 row affected (0.00 sec)

 

mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON ndodb.* TO aaa@qq.com IDENTIFIED BY '123456';

Query OK, 0 rows affected, 1 warning (0.01 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

mysql>

 

mysql> GRANT ALL PRIVILEGES ON ndodb.* TO 'ndouser'@'192.168.19.29' IDENTIFIED BY '123456' WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

 

  1. 在nagios服务器上安装mysql客户端

下载以下包到nagios服务器

mysql-5.7.17-1.el5.x86_64.rpm

mysql-community-client-5.7.17-1.el5.x86_64.rpm

mysql-community-common-5.7.17-1.el5.x86_64.rpm

mysql-community-devel-5.7.17-1.el5.x86_64.rpm

mysql-community-libs-5.7.17-1.el5.x86_64.rpm

mysql-community-libs-compat-5.7.17-1.el5.x86_64.rpm

 

[aaa@qq.com software]# yum -y install mysql-*

 

  1. 在nagios服务器端安装NDOUtils

[aaa@qq.com software]$ tar zxvf ndoutils-2.1.2.tar.gz

[aaa@qq.com software]$ cd ndoutils-2.1.2

[aaa@qq.com ndoutils-2.1.2]# ./configure --enable-mysql --with-mysql-lib=/usr/lib --with-mysql-inc=/usr/include --disable-pgsql

[aaa@qq.com ndoutils-2.1.2]# make

[aaa@qq.com ndoutils-2.1.2]# make all

[aaa@qq.com ndoutils-2.1.2]# cp -v src/{ndomod-4x.o,ndo2db-4x,file2sock,log2ndo} /home/nagios/nagios/bin

[aaa@qq.com ndoutils-2.1.2]# chown -R nagios.nagios /home/nagios/nagios/bin

 

在nagios服务器端初始化mysql数据库

[aaa@qq.com db]# yum install perl-DBD-MySQL

[aaa@qq.com ndoutils-2.1.2]# cd db/

[aaa@qq.com db]# ./installdb -u ndouser -p 123456 -h 192.168.19.49 -d ndodb

 

配置nagios和NDOUtils配置文件

[aaa@qq.com ndoutils-2.1.2]# cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /home/nagios/nagios/etc/

“config/ndo2db.cfg-sample” -> “/home/nagios/nagios/etc/ndo2db.cfg-sample”

“config/ndomod.cfg-sample” -> “/home/nagios/nagios/etc/ndomod.cfg-sample”

 

[aaa@qq.com ndoutils-2.1.2]# cd /home/nagios/nagios/etc/

[aaa@qq.com etc]# mv ndo2db.cfg-sample ndo2db.cfg

[aaa@qq.com etc]# mv ndomod.cfg-sample ndomod.cfg

[aaa@qq.com etc]# chown nagios.nagios ndo*

 

[aaa@qq.com etc]# vim nagios.cfg

添加以下语句

broker_module=/home/nagios/nagios/bin/ndomod-4x.o config_file=/home/nagios/nagios/etc/ndomod.cfg

 

[aaa@qq.com etc]# vim ndo2db.cfg

lock_file=/home/nagios/nagios/var/ndo2db.pid

socket_name=/home/nagios/nagios/var/ndo.sock

db_name=ndodb

socket_type=tcp

db_servertype=mysql

db_host=localhost

db_port=3306

db_prefix=nagios_

db_user=ndouser

db_pass=123456

 

[aaa@qq.com etc]# vim ndomod.cfg

output_type=tcpsocket

output=127.0.0.1

 

启动ndo2db进程

[aaa@qq.com etc]# /home/nagios/nagios/bin/ndo2db-4x -c /home/nagios/nagios/etc/ndo2db.cfg

 

重新启动nagios服务

[aaa@qq.com etc]# service nagios restart

Running configuration check...

Stopping nagios:. done.

Starting nagios: done.

 

 

 

 

 

相关标签: nagios