您的位置:首页 > 移动开发 > IOS开发

运维监控工具之 Nagios (一)

2015-12-29 09:52 459 查看
Nagios的简要安装流程
一、安装环境
1234# uname -aLinux localhost 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux# cat /etc/issueCentOS release 6.3 (Final)
二、安装
1、安装前的准备工作

12345678910111213(1)解决安装Nagios的依赖关系:Nagios基本组件的运行依赖于httpd、gcc和gd。可以通过以下命令来检查nagios所依赖的rpm包是否已经完全安装# yum -y install httpd gcc glibc glibc-common gd gd-devel openssl-devel net-snmp net-snmp-devel net-snmp-utils snmp* bc xinetd make wget (php php-mysql)说明:以上软件包您也可以通过编译源代码的方式安装,只是后面许多要用到的相关文件的路径等需要按照您的源代码安装时的配置逐一修改。此外,您还得按需启动必要的服务,如httpd等。 (2)添加nagios运行所需要的用户和组:# groupadd nagcmd# useradd -G nagcmd nagios \\nagios要以nagcmd为附加组# passwd nagios把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:# usermod -a -G nagcmd apache# usermod -a -G nagios apache
2、编译安装nagios
12345678910111213141516# tar zxf nagios-3.3.1.tar.gz -C /var/www/html/ \\指定apache的DocumentRoot路径# cd nagios-3.3.1# ./configure --with-command-group=nagcmd --enable-event-broker \\(为NDOUtils做准备,若不添加,日后使用需重新编译nagios) # make all # make install \\安装nagios# make install-init \\安装nagios脚本,可使用service nagios start的脚本# make install-config \\安装生成配置文件# make install-commandmode \\安装一些命令模式,生成一些工具# make install-exfoliation \\4.0.X版本使用# make install-webconf \\安装web接口成/etc/httpd/conf.d/nagios.conf的配置文件# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios \\创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用 #cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ \\4.0.X版本使用#chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers \\4.0.X版本使用配置结束以后需要重新启动httpd# service httpd restart
3、编译、安装nagios-plugins
12345678nagios的所有监控工作都是通过插件完成的,因此,在启动nagios之前还需要为其安装官方提供的插件。http://www.nagios.org/download/pluginswget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz# tar zxf nagios-plugins-1.4.15.tar.gz # cd nagios-plugins-1.4.15# ./configure --with-nagios-user=nagios --with-nagios-group=nagios# make# make install
注意:以下插件是非必须安装的可以根据所需自行安装
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100编译安装nagios中文插件下载地址:http://sourceforge.net/projects/nagios-cn/files/sourcecode/# tar jxvf nagios-cn-3.2.3.tar.bz2# cd nagios-cn-3.2.3# ./configure --prefix=/usr/local/nagios/# make all# make install nagios性能分析图表:pnpRRDtool是一个图表生成工具解决依赖#yum install -y cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel安装rrdtool-1.4.9#tar zxvf rrdtool-1.4.9.tar.gz#./configure --prefix=/usr/local/rrdtool#make && make install安装pnp#tar -zxvf pnp-0.4.13.tar.gz#./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata --with-nagios-user=nagios --with-nagios-group-nagios#make all#make install#make install-config#make install-init设置pnp创建默认配置文件:cd /usr/local/nagios/etc/pnp/cp process_perfdata.cfg-sample process_perfdata.cfg cp npcd.cfg-sample npcd.cfgcp rra.cfg-sample rra.cfg chown -R nagios:nagios *修改 process_perfdata.cfg文件:vi /usr/local/nagios/etc/pnp/process_perfdata.cfgLOG_FILE = /usr/local/nagios/var/perfdata.log # Loglevel 0=silent 1=normal 2=debug LOG_LEVEL = 2 \\这里将日志级别改为2,即为debug模式修改nagios配置文件①增加小太阳标示修改templates.cfg,增加一个定义PNP的hosts和servicesdefine host { name hosts-pnp register 0 action_url /nagios/pnp/index.php?host=$HOSTNAME$ process_perf_data 1}define service { name services-pnp register 0 action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ process_perf_data }②修改nagios.cfg找到如下几项,去掉注释,修改后信息如下:process_performance_data=1 host_perfdata_command=process-host-perfdata service_perfdata_command=process-service-perfdata③修改commands.cfg# 'process-host-perfdata' command definitiondefine command{ command_name process-host-perfdata command_line /usr/local/nagios/libexec/process_perfdata.pl}# 'process-service-perfdata' command definitiondefine command{ command_name process-service-perfdata command_line /usr/local/nagios/libexec/process_perfdata.pl}④修改hosts.cfg文件和services.cfg文件define host{ use linux-server,hosts-pnp host_name web alias ixdba-web address 192.168.12.251 }define host{ use linux-server,hosts-pnp host_name mysql alias ixdba-mysql address 192.168.12.237 }define service{ use local-service,services-pnp host_name mysql service_description SSH check_command check_ssh }define service{ use local-service,services-pnp host_name web service_description http check_command check_http } 测试PNP功能所有配置完成之后,重新检查nagios配置文件是否正确,然后重启nagios/etc/init.d/nagios restart如果配置正确,此时就会生成响应主机的pnp文件# ls /usr/local/nagios/share/perfdata/webhttp.rrd http.xml PING.rrd PING.xml SSHD.rrd SSHD.xml最后打开网页:打开网页http://IP/nagios,选择主机选项,然后点击小太阳就可以看到图表,或者访问http://ip/nagios/pnp也可
4、配置并启动Nagios
12345678910111213141516171819202122232425(1)把nagios添加为系统服务并将之加入到自动启动服务队列:# chkconfig --add nagios# chkconfig nagios on (2)检查其主配置文件的语法是否正确:# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:# service nagios start (4)配置selinux如果您的系统开启了selinux服务,则默认为拒绝nagios web cgi程序的运行。您可以通过下面的命令来检查您的系统是否开启了selinux:#getenforce如果上面命令的结果显示开启了selinux服务,您可以通过下面的命令暂时性的将其关闭:#setenforce 0如果您想在以后完全关闭selinux,可以通过编辑/etc/sysconfig/selinux文件,将其中的selinux后面的值“force”修改为“disable”即可。当然,您也可以通过以下方式将nagios的CGI程序运行于SELinux/targeted模式而不用关闭selinux:# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin# chcon -R -t httpd_sys_content_t /usr/local/nagios/share (5)通过web界面查看nagios:http://your_nagios_IP/nagios登录时需要输入前面设定的web认证帐号和密码。注意:为了nagios系统的安全,建议您使用信息摘要强认证模式(如MD5),强制使用web的TSL/SSL安全通讯模式,并且通过访问控制列表设定能访问nagios的web界面的客户端地址。
三、Nagios的配置
下面是nagios的一些主要目录树形结构
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495/usr/local/nagios/etc/├── cgi.cfg├── hostgroups \\主机群组 (自定义)│ └── test_group.cfg \\建立不同的组,便于管理├── hosts \\监控的所有主机目录 (自定义)│ └──test_hosts \\基于主机的不同建立不同的组│ ├── 10.10.10.21.cfg \\每个被监控端有单独的 .cfg文件,便于后期维护│ ├── 10.10.10.22.cfg│ └── 10.10.10.23.cfg├── services \\根据主机组的分类,分别建立不能的service(自定义)│ └── test_services.cfg│├── htpasswd.users \\用于登录web 的用户信息├── nagios.cfg \\nagios的主配置文件├── nrpe.cfg 的主配置文件└── objects ├── commands.cfg \\命令 ├── contacts.cfg \\联系人 ├── localhost.cfg ├── printer.cfg ├── switch.cfg ├── templates.cfg \\监控模板 ├── timeperiods.cfg \\时间 └── windows.cfg \\window主机监控模板 部分自定义模板的内容#cat ../etc/hostgroups/test_group.cfg \\主机群组的内容define hostgroup{ hostgroup_name wzt_group \\组名 alias wzt group \\别名 } #cat ../etc/hosts/test_hosts/10.10.10.21.cfg \\每被监控端配置内容define host { use test_host \\引用 ../etc/objects/templates.cfg 里面自定义的 wzt_host 的配置信息 host_name 10.10.10.21_test \\被监控名字,自定义 hostgroups test_group \\属于哪个群组 address 10.10.10.21 \\被监控端 ip } #cat ../etc/services/test_servoce.cfg \\被监控的服务列表define service{ use test_service \\引用 ../etc/objects/templates.cfg 里面自定义的 wzt_service 的配置信息 hostgroup_name test_group \\属于哪个群组,监控这个群组内所有的主机 service_description Host Alive \\监控的名字,用于在web 上显示 check_command check-host-alive \\使用nrpe收集此信息使用的命令 }define service{ use test_service hostgroup_name test_group service_description Current Load \\当前负载状态 check_command check_nrpe!check_load }define service{ use test_service hostgroup_name test_group service_description Disk \\磁盘信息 check_command check_nrpe!check_disk }define service{ use test_service hostgroup_name test_group service_description Total Processes \\进程总数 check_command check_nrpe!check_total_procs }define service{ use test_service hostgroup_name test_group service_description Current Users \\当前登录用户 check_command check_nrpe!check_users }define service{ use test_service hostgroup_name test_group service_description Zombie Procs \\僵死进程总数 check_command check_nrpe!check_zombie_procs }define service{ use test_service hostgroup_name test_group service_description HTTP \\http check_command check_nrpe!check_http }define service{ use test_service hostgroup_name test_group service_description Memory \\内存信息 check_command check_nrpe!check_mem }define service{ use test_service hostgroup_name test_group service_description Cpu \\cpu使用情况 check_command check_nrpe!check_cpu }
四、客户端安装:
基于NRPE监控远程Linux主机
123451、NRPE简介Nagios监控远程主机的方法有多种,其方式包括SNMP、NRPE、SSH和NCSA等。这里介绍其通过NRPE监控远程Linux主机的方式。NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端。而其执行的开销远低于基于SSH的检测方式,而且检测过程并不需要远程主机上的系统帐号等信息,其安全性也高于SSH的检测方式。
12345678910112、监控端配置安装NRPE# tar -zxvf nrpe-2.12.tar.gz# cd nrpe-2.12.tar.gz# ./configure --with-nrpe-user=nagios \ --with-nrpe-group=nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --enable-command-args \ --enable-ssl# make all# make install-plugin //只需要安装 check_nrpe 插件
3、被监控端安装配置

1234567891011121314151617181920212223242526272829301)先添加nagios用户# groupadd nagios # useradd -g nagios -M -s /sbin/nologin nagios安装依赖关系:# yum -y install openssl-devel net-snmp net-snmp-devel net-snmp-utils snmp* bc xinetd 2)NRPE依赖于nagios-plugins,因此,需要先安装之# tar zxf nagios-plugins-1.4.15.tar.gz # cd nagios-plugins-1.4.15# ./configure --with-nagios-user=nagios --with-nagios-group=nagios# make all# make instal 3)安装NRPE# tar -zxvf nrpe-2.12.tar.gz# cd nrpe-2.12.tar.gz# ./configure --with-nrpe-user=nagios \ --with-nrpe-group=nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --enable-command-args \ --enable-ssl# make all# make install-plugin //安装check_nrpe 这个插件# make install-daemon //安装deamon# make install-daemon-config //安装配置文件# make install-xinetd //nrpe的守护进程#echo "nrpe 5666/tcp # nrpe" >> /etc/services \\添加nrpe服务修改守护进程的配置文件 “/etc/xinetd.d/nrpe” ,主要在 only_from 后面添加监控端ipsed -i '/only_from/s/$/ 10.10.10.20/' /etc/xinetd.d/nrpe \\添加监控端 ip
5)客户端启动NRPE
123# service xinetd restart \\启动 nrpe 的守护进程 # netstat -tnlp | grep 5666 \\测试是否监听#/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 \\测试nrpe是否安装成功,若出现版本号,则成功安装
6)配置允许远程主机监控的对象
12345678910在被监控端,可以通过NRPE监控的服务或资源需要通过nrpe.conf文件使用命令进行定义,定义命令的语法格式为:command[<command_name>]=<command_to_execute>。比如:command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 160 -c 200command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 10%command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 85 -c 95 \\监控内存,系统默认没有此命令,需要自行添加 check_mem.sh 的脚本command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 85 -c 95 \\监控cpu,系统默认没有此命令,需要自行添加 check_cpu.sh 的脚本
五、基于NSClinet++监控Windows主机

12345678910111213NSClient下载地址:http://www.nsclient.org/nscp/downloads1、基于check_ntWindows端要启用的模块:[modules]CheckSystem.dllCheckDisk.dllFileLogger.dllNSClientListener.dll[settings]allowed_hosts =修改配置后要重启服务:nsclient++ /stopnsclient++ /start
本文出自 “行 者--->” 博客,请务必保留此出处/article/4509458.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: