![【移动应用开发技术】Nagios监控自动化_第1页](http://file4.renrendoc.com/view/5f63eedd7a969d6332cef7c74086279e/5f63eedd7a969d6332cef7c74086279e1.gif)
![【移动应用开发技术】Nagios监控自动化_第2页](http://file4.renrendoc.com/view/5f63eedd7a969d6332cef7c74086279e/5f63eedd7a969d6332cef7c74086279e2.gif)
![【移动应用开发技术】Nagios监控自动化_第3页](http://file4.renrendoc.com/view/5f63eedd7a969d6332cef7c74086279e/5f63eedd7a969d6332cef7c74086279e3.gif)
![【移动应用开发技术】Nagios监控自动化_第4页](http://file4.renrendoc.com/view/5f63eedd7a969d6332cef7c74086279e/5f63eedd7a969d6332cef7c74086279e4.gif)
![【移动应用开发技术】Nagios监控自动化_第5页](http://file4.renrendoc.com/view/5f63eedd7a969d6332cef7c74086279e/5f63eedd7a969d6332cef7c74086279e5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Nagios监控自动化
一、安装nagios下载/download.php?id=25308&ResourceID=7183tarfvxznagios-3.2.0.tar.gzcdnagios-3.2.0注:默认使用nagios用户,如果使用别的用户,必须在这里指定useraddnagiosmakeallmakeinstallmakeinstall-initmakeinstall-comandmodemakeinstall-configmakeinstall-webconfvim/etc/httpd/conf/httpd.confUsernagiosGroupnagiosservicehttpdrestart由于nagios的web控制台必须使用用户验证登陆,所以htpasswd-c/usr/local/nagios/etc/htpasswd.users
nagios以后再添加用户就不用加-c了vim/usr/local/nagios/etc/cgi.cfg
在所有的nagiosadmin后面添加nagiosservicenagiosstart访问:http://localhost/nagios但此时的nagios监控到的localhost居然是down状态原因是nagios是通过/usr/local/nagios/libexec下的各种插件来获取主机信息的,而此时此路径下没有安装任何的插件tarfvxz
/tmp/nagios-plugins-1.4.13.tarcdnagios-plugins-1.4.13./configure--prefix=/usr/local/nagios/makemakeinstall再访问:http://localhost/nagios就会发现localhost是up状态了二、配置/usr/local/nagios/etc/nagios.cfg是nagios的主配置文件,通过配置此文件指定各个单独配置文件的路径使得其生效cfg_file=/usr/local/nagios//etc/objects/commands.cfg(用什么监控?)cfg_file=/usr/local/nagios//etc/objects/contacts.cfg(有问题联系谁?)cfg_file=/usr/local/nagios//etc/objects/timeperiods.cfg(什么时间监控?默认即可)cfg_file=/usr/local/nagios//etc/objects/localhost.cfg(监控谁?包括主机和服务两种)
为了方便管理,我们需要在此文件中为每一个被监控的主机单独指定一个配置文件cfg_file=/usr/local/nagios//etc/objects/40.cfgcfg_file=/usr/local/nagios//etc/objects/42.cfg注:关于40.cfg的书写,请参考附件中的脚本注:commands.cfg文件中USER1代表/usr/local/nagios/libexec$HOSTADDRESS$是系统自带的变量,自动调用localhost.cfg文件中定义的主机definehost区域中的address$ARG1$是用户自定义的变量,需要在localhost.cfg文件中的check_command后添加!变量值localhost.cfg中的check_command调用的就是commands.cfg中的command_mand_name调用/usr/local/nagios/libexec中的check_*
但是,此时的nagios还只能监控本机,不能够监控远程主机。
如果要监控远程主机,需要配合使用nrpe。
原理:nagios服务端通过check_nrpe-H被监控的IP-c"command"把"command"命令传送给被监控端也就是nrpe服务端,nrpe服务端接收到命令后查找主配置文件nrpe.cfg中command["command"]匹配"command",然后去执行对应的本地插件,把执行结果返回给
nagios服务端
注:nrpr的服务端是安装在被监控主机的,可以理解为nrpe是一个***程序
被监控端安装nrpetarfvxznrpe-2.12.tar.gzcdnrpe-2.12./configure--prefix=/usr/local/nagios2--with-nrpe-user=apache--with-nrpe-group=apache--with-nagios-user=apache--with-nagios-group=apachemakeallmakeinstall-daemonmakeinstall-daemon-configmakeinstall-xinetdmakeallecho"nrpe5666/tcp">>/etc/servicestarfvxz/home/yuchunyun/libexec.tgz-C/usr/local/nagios(把nagios服务端的插件拷贝过来)注:nrpe服务有两种启动方式。1:依赖于xinetd服务。2:单独配置文件方式启动。方式1:请确保xinetd服务已安装sed-is//41/g/etc/xinetd.d/nrpe/etc/init.d/xinetdrestartnetstat-nutlp|grepxinetd
会发现nrpe开启的的默认5666端口是以xinetd核心守护进程方式启动方式2:/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-dps-ef|grepnrpe会发现nrpe是一个单独的进程日志tail-f
/usr/local/nagios/var/nagios.log检查错误/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfgNagios的check_*插件是用过返回值来判断的0成功
1警告
2严重错误
3未知三、自动化添加被监控主机先执行host.sh#!/bin/bash
#作者:yuchunyun
#时间:2014/03/14
#用途:此脚本用于监控主机nagios添加被监控端的主机定义
#用法:使用此脚本之前,请确保被监控端已安装nrpe服务,且本机具备连接其NRPE的权限
cfg_path=/usr/local/nagios//etc/objects
nagios_cfg=/usr/local/nagios/etc/nagios.cfg
read-p"pleaseinputthehostname(like41):"hostname
read-p"pleaseinputthealise(like141):"alise
read-p"pleaseinputtheipaddress(like41):"ip
host=`sed-n/$hostname/p$nagios_cfg`
if["$host"=""];then
echo"cfg_file=$cfg_path/$hostname.cfg">>$nagios_cfg
echo"definehost{
host_name$hostname
alias$alise
address$ip
check_commandcheck-host-alive
notification_optionsd,u,r
check_interval1
max_check_attempts2
contact_groupsadmins
notification_interval10
notification_period24x7
}">$cfg_path/$hostname.cfg
echo"#############################"
echo"thehost:$hostnamehadaddok"
echo"#############################"
else
echo"thehost:$hostnamehadalreadyexisted!!!"
fi再执行service.sh#!/bin/bash
#作者:yuchunyun
#时间:2014/03/14
#用途:此脚本用于监控主机nagios配置被监控端上的服务监控
#用法:使用此脚本之前请确保已用host.sh脚本定义了该被监控主机。由于监控插件有限,所以只能提供下面列出的监控模板!
cfg_path=/usr/local/nagios/etc/objects
nagios_cfg=/usr/local/nagios/etc/nagios.cfg
nagios_bin=/usr/local/nagios/bin/nagios
read-p"pleaseinputthehostnameyouhasbeenadded:"hostname
host=`sed-n/$hostname/p$nagios_cfg`
if["$host"=""];then
echo"thehost:$hostnameisundefind!!!"
else
for((i=0;i<10;i++));
do
echo"pleasechoosesomeservicestomonitor"
echo"###Example###
IDSERVICECOMMAND
1TotalUser>check_users;#监控系统登录人数
2SystemLoad>check_load;#监控系统负载
3TotalProces>check_total_procs;#监控系统进程数
4Disk>check_disk;#监控磁盘使用情况
5Memory>check_free_memory;#监控内存使用情况
6Contect>check_contect_est;#监控活动的网络连接数
7Httpdprocess>check_httpd_proces;#监监控apache进程数
8Nginxprocess>check_nginx_proces;#监控nginx进程数
9Phpprocess>check_php_proces;#监控php进程数
10Mysqlprocess>check_mysql_proces;#监控Mysql进程数
11Javaprocess>check_java_proces;#监控Java进程数
12quit"
echo-n"pleaseinpouttheIDyouwantcheck(1-10):"
readid
if[$id-eq1];then
echo"defineservice{
host_name$hostname
service_descriptionTotalUser
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_users
}">>$cfg_path/$hostname.cfg
echo"TotalUserhadmonitoredOK!"
elif[$id-eq2];then
echo"defineservice{
host_name$hostname
service_descriptionSystemLoad
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_load
}">>$cfg_path/$hostname.cfg
echo"SystemLoadhadmonitoredOK!"
elif[$id-eq3];then
echo"defineservice{
host_name$hostname
service_descriptionTotalProces
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_total_procs
}">>$cfg_path/$hostname.cfg
echo"TotalProceshadmonitoredOK!"
elif[$id-eq4];then
echo"defineservice{
host_name$hostname
service_descriptionDisk
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_disk
}">>$cfg_path/$hostname.cfg
echo"DiskhadmonitoredOK!"
elif[$id-eq5];then
echo"defineservice{
host_name$hostname
service_descriptionMemory
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_free_memory
}">>$cfg_path/$hostname.cfg
echo"MemoryhadmonitoredOK!"
elif[$id-eq6];then
echo"defineservice{
host_name$hostname
service_descriptionContect
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_contect
}">>$cfg_path/$hostname.cfg
echo"ContecthadmonitoredOK!"
elif[$id-eq7];then
echo"defineservice{
host_name$hostname
service_descriptionHttpdprocess
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_httpd_proces
}">>$cfg_path/$hostname.cfg
echo"HttpdprocesshadmonitoredOK!"
elif[$id-eq8];then
echo"defineservice{
host_name$hostname
service_descriptionNginxprocess
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_nginx_proces
}">>$cfg_path/$hostname.cfg
echo"NginxprocesshadmonitoredOK!"
elif[$id-eq9];then
echo"defineservice{
host_name$hostname
service_descriptionPhpprocess
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_nrpe!check_php_proces
}">>$cfg_path/$hostname.cfg
echo"PhpprocesshadmonitoredOK!"
elif[$id-eq10];then
echo"defineservice{
host_name$hostname
service_descriptionMysqlprocess
check_period24x7
normal_check_interval2
retry_check_interval1
max_check_attempts5
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 学校校服采购项目合同模板
- 公园绿化养护合同
- 《有机磷中毒机制》课件
- 房地产企业劳动合同模板
- 杂志代理销售合同
- 厂房租赁合同正式样本
- 智能机器人销售与维护合同
- 3-1 《别了“不列颠尼亚”》说课稿 2024-2025学年统编版高中语文选择性必修上册
- 绿化养护劳动合同范本
- 船舶运输及售后服务合同
- 上海专科层次自主招生考试习题集①(含答案)
- 班级管理交流-班主任工作经验交流课件(共28张ppt)
- 建筑装饰工程计量与计价试题一及答案
- 名校介绍南京大学ppt
- 三聚氰胺 工艺过程概述
- 腹腔镜外科介绍课件
- (6)-2.2老虎会唱歌-高密泥叫虎
- 级2班小组合作学习加减分细则
- 综合交通运输概论
- 通用税务自查情况说明报告(7篇)
- 现浇箱梁施工危险源辨识与分析
评论
0/150
提交评论