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
2. 按顺序安装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运行所需用户和组
[root@nagios ~]# groupadd nagios [root@nagios ~]# useradd –G nagios nagios [root@nagios ~]#passwd nagios |
3. 安装nagios
[root@nagios nagios]# cd software/ [root@nagios software]# tar zxvf nagios-3.5.0.tar.gz [root@nagios software]# cd nagios [root@nagios nagios]# ./configure --prefix=/home/nagios/nagios [root@nagios nagios]# make all [root@nagios nagios]# make install 安装主要程序,CGI及HTML文件 [root@nagios nagios]# make install-init 把nagios做成运行脚本,nagios随开机启动 [root@nagios nagios]# make install-commandmode 给外部命令访问nagios配置文件的权限 [root@nagios nagios]# make install-config 把配置文件的例子复制到nagios的安装目录
|
4. 验证程序是否正确安装
[root@nagios 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插件
[root@nagios nagios]# cd software/ [root@nagios software]# tar zxvf nagios-plugins-1.4.16.tar.gz [root@nagios software]# cd nagios-plugins-1.4.16 [root@nagios nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios [root@nagios nagios-plugins-1.4.16]#make [root@nagios 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依赖包
[root@nagios nagios]# cd software/ [root@nagios software]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz [root@nagios software]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz [root@nagios software]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip |
2. 安装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 |
3. 拷贝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 |
4. 安装apache
[root @nagios software]# tar zxvf httpd-2.2.24.tar.gz [root @nagios software]# cd httpd-2.2.24 [root@nagios 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 [root@nagios httpd-2.2.24]# make [root@nagios httpd-2.2.24]# make install |
六、 安装PHP运行环境
[root@nagios ~]# cd /home/nagios/software/gd_software/ [root@nagios gd_software]# tar zxvf php-5.4.13.tar.gz [root@nagios gd_software]# cd php-5.4.13 [root@nagios php-5.4.13]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php --with-apxs2=/home/nagios/apache/bin/apxs [root@nagios php-5.4.13]# make [root@nagios 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 qa-reports@lists.php.net later. Do you want to send this report now? [Yns]: n [root@nagios php-5.4.13]# make install |
注意:PHP应该在apache之后安装,否则无法在apache的modules下生成libphp5.so文件,导致不能登录页面。
七、 配置Apache
1. 编辑apache/conf/httpd.conf文件
[root@nagios conf]# vi httpd.conf
User example Group example 改为 User nagios Group nagios
<IfModule dir_module> DirectoryIndex index.html </IfModule> 改为 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
[root@nagios nagios]# chown -R nagios:nagios apache/ [root@nagios nagios]# chown -R nagios:nagios nagios/
#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 |
2. 生成用户验证文件
[root@nagios nagios]# /home/nagios/apache/bin/htpasswd -c /home/nagios/nagios/etc/htpasswd jsbzb New password: Re-type new password: Adding password for user jsbzb
修改生成的密码文件的用户和属组 [root@nagios nagios]# cd nagios/etc/ [root@nagios etc]# chown nagios:nagios htpasswd |
疑问:密码中不能有字母,否则无法登录,只能用数字。
八、 启动nagios和apache并登录
1. apache配置完成后执行如下命令,检查配置是否正确
[root@nagios etc]# /home/nagios/apache/bin/apachectl -t Syntax OK |
2. 用root用户启动nagios和apache
[root@nagios nagios]# ./apache/bin/apachectl start& [root@nagios nagios]# service nagios start |
九、 至此,nagios安装完成,验证配置
在浏览器中输入地址:http://192.168.19.29/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手动安装完毕
2. 安装snmp采集插件
[root@nagios software]# tar zxvf nagios-snmp-plugins.1.1.1.tgz [root@nagios software]# cd nagios_plugins [root@nagios nagios_plugins]# ./install.sh |
十一、 安装配置NRPE(for linux)
Nagios nrpe 能够实现调用远程主机上的nagios插件及其脚本来实现远程监控。
1. 服务器端安装nrpe插件
[root@nagios Client]# tar zxvf nrpe-2.14.tar.gz [root@nagios Client]# cd nrpe-2.14 [root@nagios nrpe-2.14]# ./configure --prefix=/home/nagios/nagios [root@nagios nrpe-2.14]# make all [root@nagios nrpe-2.14]# make install-plugin [root@nagios nrpe-2.14]# cd /home/nagios/nagios/libexec/ [root@nagios 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工作到这步就可以了。
2. 客户端安装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用户
[root@localhost ~]# groupadd -g 501 nagios [root@localhost ~]# useradd -u 500 -g nagios nagios [root@localhost ~]# 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插件
[root@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz [root@localhost ~]# cd nagios-plugins-1.4.16 [root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios [root@localhost nagios-plugins-1.4.16]# make [root@localhost nagios-plugins-1.4.16]# make install [root@localhost nagios-plugins-1.4.16]# chown -R nagios:nagios /home/nagios/nagios |
安装nrpe插件
[root@localhost ~]# tar -zxvf nrpe-2.14.tar.gz [root@localhost ~]# cd nrpe-2.14 [root@localhost nrpe-2.14]# ./configure -- prefix=/home/nagios/nagios [root@localhost nrpe-2.14]# make all [root@localhost nrpe-2.14]# make install-plugin [root@localhost nrpe-2.14]# make install-daemon [root@localhost nrpe-2.14]# make install-daemon-config [root@ 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
[root@HomeUC-1 software]# tar zxvf Sys-Statistics-Linux-0.66.tar.gz [root@HomeUC-1 software]# cd Sys-Statistics-Linux-0.66 [root@HomeUC-1 Sys-Statistics-Linux-0.66]# perl Makefile.PL [root@HomeUC-1 Sys-Statistics-Linux-0.66]# make [root@HomeUC-1 Sys-Statistics-Linux-0.66]# make test [root@HomeUC-1 Sys-Statistics-Linux-0.66]# make install |
3. 配置客户端nrpe参数
- 编辑/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 |
- 安装check_linux_stat插件
- 拷贝check_linux_stats.pl到nagios/libexec目录下
- 修改check_linux_stats.pl的所属用户和属组
chown nagios:nagios check_linux_stats.pl chmod 755 check_linux_stats.pl |
- 启动nrpe
/home/nagios/nagios/bin/nrpe -c /home/nagios/nagios/etc/nrpe.cfg -d |
- 添加开机启动
echo '/home/nagios/nagios/bin/nrpe -c /home/nagios/nagios/etc/nrpe.cfg -d' >> /etc/rc.d/rc.local |
4. 配置服务器端nrpe参数
- 如果是首次配置,请在/home/nagios/nagios/etc/objects目录下创建以自己命名的目录,监控对象以负责人分类,如:监控张三负责的服务器,创建目录zhangs
- 创建(首次)主机组和服务组文件
服务组: [nagios@localhost objects]$ vi servicegroups.cfg
define servicegroup { servicegroup_name zhangs-linux-services alias Zhangs Linux Services }
主机组 [nagios@localhost 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 [nagios@localhost etc]$ vi nagios.cfg cfg_file=/home/nagios/nagios/etc/objects/hostgroups.cfg cfg_file=/home/nagios/nagios/etc/objects/servicegroups.cfg |
- 添加联系人和联系人组(首次)
[nagios@nagios objects]$ vi contacts.cfg 添加以下内容 define contact{ contact_name zhangs use generic-contact alias zhangs email zhangs@zzb.com.cn }
define contactgroup{ contactgroup_name zhangs-cg alias zhangs-cg members jsbzb,zhangs #添加值班邮箱和自己常用邮箱,多个联系人之间用逗号隔开 } |
- 在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 } |
- 编辑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 |
- 编辑主机组文件hostgroups.cfg添加新加主机
[nagios@localhost 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 }
|
- 验证nagios配置
[root@localhost ~]# /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 |
- 重新装载nagios配置
service nagios reload |
- 刷新页面查看增加结果
十二、 安装配置NSClient++(for windows)
监控Windows需要在windows安装一个插件nsclient++,有32位和64位,根据实际安装
1. nsclient++获取方法:
a、 ftp到监控服务器(192.168.19.29)/home/nagios/software/Client目录下下载
b、 下载地址:http://nsclient.org/nscp/downloads
2. 客户端安装配置nsclient++
- 下载nsclient++后安装
安装过程十分简单,直接点击下一步,下一步即可。安装过程注意如下图的设置即可
- 配置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 |
- 启动客户端nsclient++
从 开始-程序-NSClient++ 找到Start NSClient++ (x64),并点击启动。
或
在安装目录下执行NSClient++ -start,停止服务执行NSClient++ -stop
- 验证端口,5666和12489
netstat -an | more
|
3. 服务器端配置
- 编辑主机组文件hostgroups.cfg添加新主机组
[nagios@localhost 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 } |
- 编辑服务组文件servicegroups.cfg添加新服务
[nagios@localhost 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 } |
- 编辑联系人文件,增加联系人和联系人组
define contact{ contact_name zhangs use generic-contact alias zhangs email zhangs@zzb.com.cn } define contactgroup{ contactgroup_name zhangs-cg alias zhangs-cg members jsbzb,zhangs } |
- 在自己的目录(没有请创建)下创建对象配置文件
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 } |
- 注册windows主机
编辑nagios/etc/nagios.cfg文件,添加以下内容 #weiyq object config files cfg_file=/home/nagios/nagios/etc/objects/zhangs/zhangs-lenovopc-win7.cfg |
- 验证nagios配置
[root@localhost ~]# /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 |
- 重新装载配置
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脚本
chown nagios:nagios check_snmp_cisco_*.pl chmod 755 check_snmp_cisco_*.pl |
2. 编辑命令配置文件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$ } |
3. 添加网络主机对象
如果是第一次添加,在nagios/etc/objects目录下创建自己的对象目录 [nagios@nagios 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 } |
4. 添加网络服务组
[nagios@nagios objects]$ vi servicegroups.cfg define servicegroup { servicegroup_name zhangs-switch-services alias Zhangs Switch Services } |
5. 添加网络主机组
[nagios@nagios 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 } |
6. 在nagios/etc/nagios.cfg中添加网络主机配置
[nagios@nagios etc]$ vi nagios.cfg
cfg_file=/home/nagios/nagios/etc/objects/zhangs/ zhangs-cisco2950-switch.cfg |
7. 编辑联系人文件,增加联系人和联系人组
define contact{ contact_name zhangs use generic-contact alias zhangs email zhangs@zzb.com.cn } define contactgroup{ contactgroup_name zhangs-cg alias zhangs-cg members jsbzb,zhangs } |
8. 检查配置正确性
[root@localhost ~]# /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 |
9. 重新加载配置文件
service nagios reload |
10. 刷新监控页面查看添加结果。
十四、 Pnp4nagios安装配置
pnp4nagios是基于RRD轮循(环状)数据库中所提供的综合信息,以可视化图形的方式呈现给用户的一款nagios插件;
1. 安装rrdtools
官网下载地址:http://oss.oetiker.ch/rrdtool/
yum install rrdtool-perl |
2. 检查PHP版本
PHP版本必须在5.2以上
[root@nagios ~]# 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 |
3. 安装pnp4nagios
[root@nagios ~]# cd /home/nagios/software/pnp4nagios/ [root@nagios pnp4nagios]# tar zxvf pnp4nagios-0.6.21.tar.gz [root@nagios pnp4nagios]# cd pnp4nagios-0.6.21 [root@nagios pnp4nagios-0.6.21]# ./configure --prefix=/home/nagios/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios [root@nagios pnp4nagios-0.6.21]# make all [root@nagios pnp4nagios-0.6.21]# make install [root@nagios pnp4nagios-0.6.21]# make install-webconf [root@nagios pnp4nagios-0.6.21]# make install-config [root@nagios pnp4nagios-0.6.21]# make install-init |
4. 更改pnp4nagios属组
[root@nagios nagios]# chown -R nagios:nagios pnp4nagios/ |
5. 配置pnp4nagios
这里我们使用Bulk Mode with NPCD模式
- 创建配置文件
[nagios@nagios ~]$ cd pnp4nagios/etc/ [nagios@nagios etc]$ mv misccommands.cfg-sample misccommands.cfg [nagios@nagios etc]$ mv nagios.cfg-sample nagios.cfg [nagios@nagios etc]$ mv rra.cfg-sample rra.cfg
[nagios@nagios etc]$ cd pages/ [nagios@nagios pages]$ mv web_traffic.cfg-sample web_traffic.cfg
[nagios@nagios check_commands]$ mv check_all_local_disks.cfg-sample check_all_local_disks.cfg [nagios@nagios check_commands]$ mv check_nrpe.cfg-sample check_nrpe.cfg [nagios@nagios check_commands]$ mv check_nwstat.cfg-sample check_nwstat.cfg |
- 删除install.php
[nagios@nagios ~]$ cd pnp4nagios/share/ [nagios@nagios share]$ mv install.php install.php.bak |
- 启动服务
[root@nagios nagios]# service npcd start Starting npcd: done. |
- 修改nagios配置文件,打开performance_data
[nagios@nagios ~]$ 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 |
- 编辑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$ } |
- 修改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$ |
- 验证nagios配置
[root@localhost ~]# /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 |
- 重新加载nagios配置
[root@nagios nagios]# service nagios reload Running configuration check...done. Reloading nagios configuration...done |
- 修改apache配置
[nagios@nagios ~]$ 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> |
- 重启apache服务
[root@nagios nagios]# ./apache/bin/apachectl stop [root@nagios nagios]# ./apache/bin/apachectl start& |
十五、 安装配置check_oracle_health
1. 安装客户端NRPE
参考第十一章节
2. 设定系统环境变量
在root用户下,编辑.bash_profile,添加ORACLE环境变量,要和ORACLE用户的.bash_profile文件中的设置一样。
注:必须先配置环境变量,否则perl的oracle插件安装报错。
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 |
3. 安装check_oracle_health
[root@zzbrac11 software]# tar zxvf check_oracle_health-1.7.7.3.tar.gz [root@zzbrac11 software]# cd check_oracle_health-1.7.7.3 [root@zzbrac11 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/
[root@zzbrac11 check_oracle_health-1.7.7.3]# make all [root@zzbrac11 check_oracle_health-1.7.7.3]# make install
[root@zzbrac11 check_oracle_health-1.7.7.3]# chown -R nagios:nagios /home/nagios/nagios/ |
4. 安装perl的oracle插件
[root@zzbrac11 software]# tar zxvf DBI-1.609.tar.gz [root@zzbrac11 software]# cd DBI-1.609 [root@zzbrac11 DBI-1.609]# perl Makefile.PL [root@zzbrac11 DBI-1.609]# make all [root@zzbrac11 DBI-1.609]# make install
[root@zzbrac11 software]# tar zxvf DBD-Oracle-1.24a.tar.gz [root@zzbrac11 software]# cd DBD-Oracle-1.24 [root@zzbrac11 DBD-Oracle-1.24]# perl Makefile.PL [root@zzbrac11 DBD-Oracle-1.24]# make all [root@zzbrac11 DBD-Oracle-1.24]# make install |
5. 配置检测命令
[nagios@zzbrac11 ~]$ 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 |
6. 重启客户端nrpe服务
/home/nagios/nagios/bin/nrpe -c /home/nagios/nagios/etc/nrpe.cfg -d |
7. 配置服务器端服务
参考十一章节第4小节
十六、 安装配置check_mssql_health
1. 安装check_mssql_health
[root@nagios mssqlserver]# tar zxvf check_mssql_health-1.5.19.1.tar.gz [root@nagios mssqlserver]# cd check_mssql_health-1.5.19.1 [root@nagios check_mssql_health-1.5.19.1]# ./configure --prefix=/home/nagios/nagios --with-nagios-user=nagios --with-nagios-group=nagios [root@nagios check_mssql_health-1.5.19.1]# make && make install
[root@nagios libexec]# chown nagios:nagios /home/nagios/nagios/libexec/check_mssql_health |
2. 安装、配置freetds-0.82
说明:在linux下连接MSSQL比较困难,微软没有提供任何接口给开发人员。还好,MSSQL是从Sybase衍生出来的,有些人做了Sybase的Linux下的连接库,这些连接库同时也能支持MSSQL,FreeTDS就是这样的一个软件。
- 安装freetds-0.82
[root@nagios mssqlserver]# tar xvzf freetds-0.82.tar.gz [root@nagios mssqlserver]# cd freetds-0.82 [root@nagios freetds-0.82]# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib [root@nagios freetds-0.82]# make && make install |
- 配置freetds-0.82
配置root用户环境变量
[root@nagios ~]# 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/
[root@nagios ~]# 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
[root@nagios ~]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf /usr/local/freetds/lib
[root@nagios ~]# 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. |
3. 安装DBI和DBD-Sybase
[root@nagios Client]# tar zxvf DBI-1.609.tar.gz [root@nagios Client]# cd DBI-1.609 [root@nagios DBI-1.609]# perl Makefile.PL [root@nagios DBI-1.609]# make [root@nagios DBI-1.609]# make test [root@nagios DBI-1.609]# make install |
[root@nagios mssqlserver]# tar zxvf DBD-Sybase-1.15.tar.gz [root@nagios mssqlserver]# cd DBD-Sybase-1.15 [root@nagios DBD-Sybase-1.15]# perl Makefile.PL [root@nagios DBD-Sybase-1.15]# make [root@nagios 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 [root@nagios DBD-Sybase-1.15]# make install |
4. 测试连接
[root@nagios ~]# cd /home/nagios/nagios/libexec [root@nagios 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) [root@nagios libexec]# ./check_mssql_health --hostname=192.168.16.157 -port=1433 --username=sa --password=xxx --mode=connected-users |
5. 添加模板
# 'check_mssql_health ' command definition define command{ command_name check_mssql_health command_line $USER1$/check_mssql_health $ARG1$ } |
6. 添加服务
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 } |