nagios部署文档实战.doc_第1页
nagios部署文档实战.doc_第2页
nagios部署文档实战.doc_第3页
nagios部署文档实战.doc_第4页
nagios部署文档实战.doc_第5页
免费预览已结束,剩余6页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实战nagios配置文档作者:chenzhj邮箱:QQ:158664987一、nagios服务器安装:1、 nagios server软件安装要求:操作系统:RedHat AS 5 EnterpriseNagios服务器软件安装环境:httpd;gcc;glibc;glibc-common;gd gd-devel;phpNagios软件包:nagios-3.2.1.tar.gz;nagios-plugins-1.4.14.tar.gz2、 nagios server环境安装:yum y install httpd gcc glibc glibc-common gd gd-devel php3、 nagios server服务器程序安装:创建nagios用户:#useradd nagios#groupadd nagcmd#usermod -G nagcmd nagios#/usr/sbin/usermod -G nagcmd apache安装nagios主程序软件包:A)#tar zxvf nagios-3.2.0.tar.gz#./configure -prefix=/usr/local/nagios -with-nagios-user=nagios -with-command-group=nagcmdB)#make allC)使用make install来安装主程序,CGI和HTML文件;D)使用make install-init在/etc/rc.d/init.d安装启动脚本;E)使用make install-cofig来安装示例配置文件,安装的路径是/usr/local/nagios/etc;.F)使用make install-commandmode来配置目录权限;G)使用make install-webconf安装Nagios的WEB配置文件到Apache的conf.d目录下;4、 创建一个nagiosadmin的用户用于Nagios的WEB接口登录:#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin5、 安装Nagios插件:#tar xzf nagios-plugins-1.4.14.tar.gz#./configure#make;make install6、 配置htpd和nagios启动方式:Chkconfig add httpdChkconfig add nagiosChkconfig level 3 httpd onChkconfig level 3 nagios on二、 Nagios服务器配置:1、 修改nagios.cfg主配置文件(添加修改信息):cfg_file=/usr/local/nagios/etc/objects/commands.cfgcfg_file=/usr/local/nagios/etc/objects/contacts.cfgcfg_file=/usr/local/nagios/etc/objects/contactsgroups.cfgcfg_file=/usr/local/nagios/etc/objects/timeperiods.cfgcfg_file=/usr/local/nagios/etc/objects/templates.cfgcfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/hostgroup.cfgcfg_file=/usr/local/nagios/etc/objects/servergroup.cfg把server目录配置前面的去掉,记得手动创建目录cfg_dir=/usr/local/nagios/etc/servers2、 修改CGI脚本控制文件cgi.cfg修改 /usr/local/nagios/etc/cgi.cfg是否开启验证,1是开启0是关闭use_authentication=1修改默认用户default_user_name=test多个用户之间用逗号隔开authorized_for_system_information=nagiosadmin,test authorized_for_configuration_information=nagiosadmin,testauthorized_for_system_commands=test authorized_for_all_services=nagiosadmin,testauthorized_for_all_hosts=nagiosadmin,testauthorized_for_all_service_commands=nagiosadmin,testauthorized_for_all_host_commands=nagiosadmin,test3、 定义监控时段,配置文件timeperiods.cfg(一般不用修改)修改/usr/local/nagios/etc/objects/timeperiods.cfg# notifications, etc. The classic 24x7 support nightmare. :-)define timeperiod timeperiod_name 24x7 alias 24 Hours A Day, 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 # workhours timeperiod definitiondefine timeperiod timeperiod_name workhours alias Normal Work Hours monday 09:00-17:00 tuesday 09:00-17:00 wednesday 09:00-17:00 thursday 09:00-17:00 friday 09:00-17:00 4、 定义联系人,配置文件contacts.cfgvi /usr/local/nagios/etc/objects/contacts.cfgdefine contact contact_name nagiosadminuse generic-contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-sms, notify-service-by-email host_notification_commands notify-host-by-sms, notify-host-by-email alias Nagios Admin email pager 1357082xxxxdefine contact contact_name gandj use generic-contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-sms alias Nagios Admin email pager 1356082xxxx # service_notification_period24x7; 服务出了状况通知的时间段# host_notification_period24x7; 主机出了状况通知的时间段# service_notification_options w,u,c,r;当服务出现w报警(warning),u未 知(unkown),c严重(critical),或者r从异常情况恢复正常,在这四种情况下通知联系人# host_notification_optionsd,u,r; 当主机出现d当机(down),u返回不可达(unreachable),r从异常情况恢复正常,在这3种情况下通知联系人#service_notification_commands notify-service-by-email;服务出问题通知采用的命令notify-service-by-email,这个命令是在commands.cfg中定义的;,作用是给联系人发邮件.#host_notification_commandsnotify-host-by-sms ; 主机出问题时采用手机方式通知联系人#email 联系人的邮箱账号;#sms 联系人的手机号;5、 定义联系人组,,配置文件contactsgroups.cfg修改/usr/local/nagios/etc/objects/contactsgroups.cfg# shanghai contactgroup#define contactgroup contactgroup_name shanghai-center alias Nagios Administrators members changyzh,gandj # shenzhen contactgroup#define contactgroup contactgroup_name shenzhen-center alias Nagios Administrators members lifeng, gandj 三、 采用nrpe方式进行主动监控:1、 Nagios服务器1.1、nrpe安装:#tar xzvf nrpe-2.12.tar.gz#./configure#make all#make install-plugin 在Nagios服务器端只要make install-plugin安装nrpe监控插件就可以1.2、修改配置文件 /usr/local/nagios/etc/objects/commands.cfg,增加主动监测调用命令define command command_name check_nrpe command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 1.3、nagios定义监控主机配置文件:#BBS#define host host_name BBS alias bbs address check_period 24x7 check_interval 10 retry_interval 1 max_check_attempts 10 check_command check-host-alive notification_period 24x7 notification_interval 120 notification_options d,u,r contact_groups Shenzhen-center #product#define host host_name product alias product address check_period 24x7 check_interval 10 retry_interval 1 max_check_attempts 10 check_command check-host-alive notification_period 24x7 notification_interval 120 notification_options d,u,r contact_groups shanghai-center #check_period 24x7 检查的时间段24x7,来自于在timeperiods.cfg中定义的#check_interval 10 检查间隔,每十分钟检查一次。#retry_interval 1 重新检查间隔1分钟。#max_check_attemp 10 尝试检查linux主机十次#check_command check-host-alive 监控的命令check-host-alive,这个命令来自commands.cfg,用来监控主机是否存活,#notification_period 24x7 提醒的周期, 24x7,来自于我们之前在timeperiods.cfg中定义的#notification_interval 120 提醒的间隔,每隔120秒提醒一次#notification_options d,u,r 指定什么情况下提醒,具体含义见之前contacts.cfg部 分的介绍#contact_groups shanghai-center 联系人组,来自于在contactgroups.cfg中定义的1.4、Nagios定义监控主机组:修改cfg_file=/usr/local/nagios/etc/objects/hostgroup.cfg#shanghai zone#define hostgroup hostgroup_name shanghai cener alias shanghai center Servers members BBS,product # members BBS,product 主机名称在hosts.cfg中定义的1.5、Nagios定义监控的服务:在/usr/local/nagios/etc/文件目录下面添加一个目录:servers在service目录下面创建一个文件以主机的名称或ip命名文件名,以方便以后针对特定的主机进行修改。vi /usr/local/nagios/etc/servers/shanghaicenter.cfgdefine service host_name shanghaicenter service_description CHECK-HTTP check_command check_nrpe!check_http max_check_attempts 5 normal_check_interval 10 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options w,u,c,r contact_groups admins define service host_name shanghaicenter service_description CHECK-MYSQL check_command check_nrpe!check_mysql max_check_attempts 5 normal_check_interval 10 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options w,u,c,r contact_groups admins #host_name shanghaicenter 主机名称,在hosts.cfg文件中定义#service_description CHECK-MYSQL 对监控的服务进行描述#check_command check_nrpe!check_mysql 监控调用的命令check_nrpe在文件为commands.cfg中定义;检查mysql命令定义在被监控机器的nrpe.cfg文件定义。#max_check_attempts 5 尝试检查服务5次#normal_check_interval 10 正常检查间隔10分钟。#retry_check_interval 2 重试间隔2分钟。#check_period 24x7 检查为24小时乘以7。#notification_interval 300 通知间隔300分钟。#notification_period 24x7 通知时间为24小时乘以7。#notification_options w,u,c,r 通知类型。#contact_groups admins 联系组。2、 Nrpe被监控主机安装配置:2.1、nagios-plugins插件安装:#tar xzf nagios-plugins-1.4.14.tar.gz#./configure#make;make install2.2、nrpe安装:#tar xzvf nrpe-2.12.tar.gz#./configure#make all2.3、修改文件/etc/services:nrpe 5666/tcp # NRPE2.4、添加nrpe到/etc/xinetd.dCp cp sample-config/nrpe.xinetd /etc/xinetd.d/nrpe编辑/etc/xinetd.d/nrpe# default: on# description: NRPE (Nagios Remote Plugin Executor)service nrpe flags = REUSE socket_type = stream port = 5666 wait = no user = nagios group = nagios server = /usr/local/nagios/bin/nrpe server_args = -c /usr/local/nagios/etc/nrpe.cfg -inetd log_on_failure += USERID disable = no only_from = 57.60.xxx.xx #nagios服务器ip2.5、编辑nrpe配置文件nrpe.cfgCopy nrpe配置文件 cp sample-config/nrpe.cfg /usr/local/nagios/etc/修改/usr/local/nagios/etc/nrpe.cfgallowed_hosts=,58.60.xxx.xx,58.60.xxx.xx #58.60.xxx.xx是nagios服务器ipcommandcheck_zombie_procs=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommandcheck_total_procs=/usr/local/nagios/libexec/check_procs -w 150 -c 200commandcheck_http=/usr/local/nagios/libexec/check_http -w 5 -c 10 -ssl -I -vcommandcheck_mysql=/usr/local/nagios/libexec/check_mysql -u root -p xxx -d database#定义监控的执行命令2.6、使用xinetd启动nrpe,检查运行。Service xinetd startNetstat ant|grep 5666tcp 0 0 :5666 :* LISTEN四、 fetion和邮件进行报警配置1、 fetion报警配置1.1、fetion机器人安装:参考网站:wget /fetion/downng/library_linux.tar.gzwget /fetion/dow . 406003-linux.tar.gzwget /fetion/downng/fetion20091117-linux.tar.gz#在安装飞信之前需要在/usr/lib目录下加上libACE 库文件,以便使飞信能够正常使用rootlocalhost src# tar zxvf library_linux.tar.gzrootlocalhost src# mv libACE* libcrypto.so.0.9.8 libssl.so.0.9.8/usr/lib#正式安装飞信 tar zxvf fetion20090406003-linux.tar.gz mv install/* /usr/local/fetion chmod -R 755 /usr/local/fetion chown -R nagios:nagios /usr/local/fetion#移动服务器更新,需要更新软件 tar zxvf fetion20091117-linux.tar.gz cp fx/* /usr/local/fetion vi /etc/ld.so.conf include ld.so.conf.d/*.conf ldconfig#测试fetion:Vi /etc/fetion.conf# This config file is for fetion robot tool.# Usage demo: ./fetion -config=/etc/fetion.conf -index=2# ID Mobile Password1 1355486* XXXXXX#/usr/local/fetion/fetion config=/etc/fetion.conf index=1 tomsg-gb=fetion test1.2、修改nagios命令调用文件commands.cfgVi /usr/local/nagios/etc/objects/commands.cfg#fetion2008# notify-host-by-sms command definitiondefine command command_name notify-host-by-sms command_line /usr/bin/printf %b * Nagios *nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n | /usr/local/fetion/fetion -config=/etc/fetion.conf -index=1 -to=$CONTACTPAGER$ -msg-gb=* $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ * # notify-service-by-sms command definitiondefine command command_name notify-service-by-sms command_line /usr/bin/printf %b * Nagios *nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$ | /usr/local/fetion/fetion -config=/etc/fetion.conf -index=1 -to=$CONTACTPAGER$ -msg-gb=* $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ * 1.3、报警接受者配置vi /usr/local/nagios/etc/objects/contacts.cfgdefine contact contact_name nagiosadminuse generic-contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-sms, notify-service-by-email host_notification_commands notify-host-by-sms, notify-host-by-email alias Nagios Admin email pager 1357082xxxx2、 邮件报警配置2.1、sendEmail安装:tar zxvf sendEmail-v1.55.tar.gzcd sendEmail-v1.55cp sendEmail /usr/local/binchmod 0755 /usr/local/bin/sendEmailchown nagios:nagios /usr/local/bin/sendEmail#测试sendEmail发邮件:/usr/local/bin/sendEmail t s u “from nagios” xu chenzhj xp * m “nagios test”#解释:-f 表示发送者的邮箱-t 表示接收者的邮箱-s 表示SMTP服务器的域名或者ip-u 表示邮件的主题-xu 表示SMTP验证的用户名-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)-m 表示邮件的内容2.2、修改nagios命令调用文件commands.cfg# notify-host-by-email command definitiondefine command command_name notify-host-by-email command_line /usr/bin/printf %b * Nagios *nnNotificati

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论