Nagios短信配置
nagios安装与配置√

一、Nagios简介Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows、Linux和Unix 的主机状态,交换机路由器等网络设置,打印机等。
在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。
NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。
Nagios被开发在Linux下使用,但在Unix下也工作得非常好。
主要功能∙网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)∙主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)∙可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)∙可以通过配置Nagios远程执行插件远程执行脚本∙远程监控支持SSH或SSL加通道方式进行监控∙简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)∙包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios 等)∙可并行服务检查∙能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查∙当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知∙能够自定义事件处理机制重新激活出问题的服务或主机∙自动日志循环∙支持冗余监控∙包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等二、Nagios工作原理Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。
Nagios调用短信接口

Nagios调用短信接口公司之前一直使用的飞信的免费接口来发送Nagios短信报警,但由于1.23飞信内部系统升级,导致发信不能发送,飞信机器人也公布近期不会去破解,so,免费的飞信时代被终结。
公司正好有自己的短信接口平台,接下来带大家一起配置nagios调用第三方短信接口。
1:首先我们要写一个调用短信接口的脚本,网上的脚本大都是python写的,我这个是shell写的,比较好理解。
vi /root/duanxin.sh# 脚本的日志文件LOGFILE="/data1/sms_log/sms_send_.log" #定义发送短信的日志信息文件:>>"$LOGFILE"exec 1>>"$LOGFILE"exec 2>&1Uid="test" #接口的用户名,这个使用接口时对方会提供,我这里的test是随意写的Key="123456" #密码与用户名对应,也是接口方提供MOBILE_NUMBER=$1 # 接受短信的手机号码QIANMING="%e3%80%90%e9%a9%ac%e5%8f%af%e6%b3 %a2%e7%bd%97%e7%bd%91%e3%80%91" #这里重点说一下,签名有的接口需要,有的不需要,因为我们公司的接口需要,所以需要添加上,我这里的签名内容是经过编码的,不加编码会导致发送失败,具体工作中需不需要编码还得看接口哪边有没有要求。
XXD="/usr/bin/xxd"CURL="/usr/bin/curl"TIMEOUT=5MESSAGE_ENCODE=$(echo $(/usr/local/bin/php -r "echo urlencode(\"$2\");"; ) ) #这里的$2是nagios发送短信的第二个变量URL="http://192.168.100.100:8888/services/msgsend.asmx/ SendMsg?userCode=${$Uid}&userPass=${Key}&DesNo=${MOB ILE_NUMBER}&Msg=${MESSAGE_ENCODE}${QIANMING}&Chan nel=0"#我这里的URL是胡乱写的,我不可能暴漏自己公司的接口哈,但是格式大体是这样的,到时候接口方会提供URL的格式的# Send itset -x${CURL} -s --connect-timeout ${TIMEOUT} "${URL}"2 :测试脚本bash /root/duanxin.sh "手机号" “内容”如果脚本报错,可以根据报错信息检查脚本,如果脚本没有问题,但是短信发不出去,可以看看sms_send_log里面的报错信息3:nagios 调用脚本,不要忘记脚本要给执行权限,一般脚本放在root目录下,nagios在调用脚本时是不能访问root目录的,所以你还要看你/root目录的权限define command {command_name host-notify-by-smscommand_line /root/duanxin.sh $CONTACTPAGER$ "$HOSTNAME$ $HOSTSTATE$ $SHORTDATE TIME$"}define command {command_name service-notify-by-smscommand_line /root/duanxin.sh$CONTACTPAGER$ "$SERVICESTATE$ $SERVICEOUTPUT$ $HOS TALIAS$/$SERVICEDESC$ $SHORTDATETIME$"}4:看到这里大家可能对上面脚本的$1和 $2概念比较模糊,其实刚开始我也迷糊,nagios怎么知道我要发送的号码呢,后来研究发现,$CONTACTPAGER$这个变量就是nagios内部联系人的变量,也就是他会调用我们在contacts.cfg里面定义的手机号,而我们脚本里面定义的$1就对应$CONTACTPAGER$,$2就对应"$HOSTNAME$ $HOSTSTATE$ $SHORTDATETIME$"。
Nagios安装配置手册

12.配置和启动 nagios cd /usr/local/nagios/etc 里面如果有 cfg-sample,就把目录里的.cfg-sample 文件全部拷贝成.cfg 例如: cp nagios.cfg-sample nagios.cfg 没有的话就直接修改:
修改 vi cgi.cfg, use_authentication=1 改成 use_authentication=0, 即不用验证.不然有一些页面不会显示。
情况二: 如果还不行,从这个网站: 下载一下 Mudule 包,tar.gz 格式的! - Crypt::DES - Digest::MD5 - Digest::SHA1 - Digest::HMACcd - Net::SNMP 按以下操作顺序安装这些 Module: tar zxf <module>.tar.gz cd <module> perl Makefile.PL make test make install 完了以后 cd nagios_plugins ./install.sh (路径选默认,y/n 选 Y!)
6.安装 nagios nagios 之前的准备,特别需要安装 gd-devel, 另外安装 nagios 时需要加--with-gd-lib=/usr/lib --with-gd-inc=/usr/include 不然不能生成 statusmap.cgi 也就不能看状态图了!
groupadd nagios useradd -g nagios nagios passwd nagios mkdir /usr/local/nagios chown -R nagios:nagios /usr/local/nagios chmod 755 /usr/local/nagios/ usermod -G nagios apache usermod -G nagios nagios grep ^User /etc/httpd/conf/httpd.conf User apache 查看运行 apache 的用户
Nagios安装与配置详解

Nagios学习笔记之(一)最初搭建2012-07-17 13:05:08标签:linux监控nagios cacti声明:原创作品,如需,请与作者联系。
否则将追究法律责任。
Nagios学习笔记之一最初搭建一、简介:Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。
在系统或服务状态异常时发出或短信报警第一时间通知运维人员,在状态恢复后发出正常的或短信通知。
二、搭建过程:OS:CentOS 5.5 x86_64(最小化即可)Nagios主程序:nagios-cn-3.4.1Nagios插件:nagios-plugins-1.4.15.tar.gz2.1安装前:2.1.1安装依赖包,下载源程序包1.#cd/etc/yum.repos.d/2.#rm-fr./*3.#wget wget mirrors.163./.help/CentOS-Base-163.repo4.#yum makecache#删除系统自带的yum源,下载网易的网络源并更新缓存1.#yum-y install gcc glibc glibc-common gd gd-devel httpd#安装必须的依赖包1.#wget /sourceforge/nagios/nagios-3.4.1.tar.gz2.#wget /sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz#下载nagios主程序以及插件程序2.1.2正式安装:1.#groupadd nagcmd2.#useradd-G nagcmd nagios3.#usermod-G nagcmd apache#创建一个用户组名为nagcmd用于从Web接口执行外部命令。
将nagios用户和apache用户都加到这个组中。
1.#tar zxf nagios-3.4.1.tar.gz2.#cd nagios3.#./configure--prefix=/usr/local/nagios --with-command-group=nagcmd4.#解压程序包,并进行预编译前的配置(默认用户就是nagios,所以只需指定组)5.#make all#编译Nagios程序包源码6.#make install#安装二进制运行程序7.#make install-init#初始化脚本8.#make install-config#配置文件样本9.#make install-commandmode#设置运行目录权限10.#make install-webconf#安装Nagios的WEB配置文件到Apache的conf.d目录下#htpasswd -c /usr/local/nagios/etc/ers nagiosadmin#创建一个nagiosadmin的用户用于登录Nagios的web界面。
nagios基本安装配置文档

简单介绍nagiosnagios是一款开源的监控软件,能够对网络内的主机和硬件设备进行状态监控。
功能:1. 状态监控2. 预警报告3. 集中,规模化管理4. web可视化显示方式5. 自定义shell脚本或插件实现更多的功能nagios的实现方式:nagios采用分布-集中的管理模式。
在nagios服务器上安装nagios主程序,在被监控主机上安装nagios代理程序。
通过nagios主程序和nagios代理程序之间的通讯,监视主机状态。
主程序和代理程序之间有两种工作方式,一种是主程序-->Active-->代理程序;另一种是主程序-->passive-->代理程序;顾名思义,是以一方向另一方主动提出通讯需求来划分的。
所需软件:系统:Redhat AS 4nagios-3.1.0.tar.gzwget /sourceforge/nagios/nagios-3.1.0.tar.gznagios-plugins-1.4.13.tar.gzwget /sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz官方下载:wget/sourceforge/nagios/nagios-3.1.0.tar.gz wget/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz实现要求:在一台机器上面监控多台运行主机状态,所以安装步骤为首先安装监控机器,再配置监控机器,最后安装被监控端软件。
一.安装监控中心(server端)一.nagios 安装[code]tar zxf nagios-3.1.0.tar.gzuseradd nagioscd nagios-3.1.0./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/includemake all && make installmake install-init && make install-commandmode && make install-configchown -R nagios.nagios /usr/local/nagios2.安装nagios-pluginstar zxf nagios-plugins-1.4.13.tar.gzcd nagios-plugins-1.4.13./configure --prefix=/usr/local/nagios --enable-redhat-pthread-workaroundmake all && make install(在redhat系统上面安装可能出现configure时,到这里checking for redhat spopenproblem...就不动了,所以需要在configure时再加上这个--enable-redhat-pthread-workaround 3安装imagepak-base.tar.gzwget /distfiles/imagepak-base.tar.gztar zxf imagepak-base.tar.gz解压以后是base目录cp -r base /usr/local/nagios/share/images/logos/4监控的机器上需要安装nrpewget /project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz tar xzf nrpe-2.12.tar.gzcd nrpe-2.12./configure --enable-ssl --enable-command-argsmake allmake install-pluginmake install-daemonmake install-daemon-config二 .配置apache在httpd.conf中追加ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/<Directory "/usr/local/nagios/sbin/">AllowOverride AuthConfigOptions ExecCGIOrder allow,denyAllow from all</Directory>Alias /nagios/ /usr/local/nagios/share/<Directory "/usr/local/nagios/share">Options NoneAllowOverride AuthConfigOrder allow,denyAllow from all</Directory>2.配置nagios检查配置文件是否出错/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg出现Total Warnings: 0Total Errors: 0vi /usr/local/nagios/etc/cgi.cfguse_authentication=1改为use_authentication=0,即不用验证.启动后台进程把nagios作为守护进程:/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg/etc/init.d/nagios start此时我们就可以访问nagios监控界面了,访问的方法是http://ip/nagios/安装远程端一.安装nrpeuseradd nagiostar xzf nrpe-2.12.tar.gzcd nrpe-2.12./configure --enable-ssl --enable-command-argsmake all && make install-plugin && make install-daemon && make install-daemon-config2 安装nagios-pluginstar zxf nagios-plugins.tar.gzcd nagios-plugins./configure --prefix=/usr/local/nagios --enable-redhat-pthread-workaroundmake all && make installok,安装好了,可以到/usr/local/nagios/下面检查一下,应该生成了4个目录:bin、etc、libexec、share。
nagios部署+短信和邮件报警

nagios部署+短信和邮件报警操作系统 CentOS6.6服务端:10.0.0.20客户端:10.0.0.50⼀.nagios的服务端安装部署1.nagios安装[root@manager src]# rzrz waiting to receive.Starting zmodem transfer. Press Ctrl+C to cancel.Transferring nagios-cn-3.2.3.tar.bz2...100% 9412 KB 9412 KB/sec 00:00:01 0 Errorstar xf nagios-cn-3.2.3.tar.bz2cd nagios-cn-3.2.3useradd -m -s /bin/bash nagiosgroupadd nagcmdmake install; make install-init;make install-commandmode;make install-config;make install-webconfll /usr/local/nagios/ #出现以下⽂件代表成功drwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 bindrwxrwxr-x 3 nagios nagios 4096 Mar 12 08:08 etcdrwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 libexecdrwxrwxr-x 2 nagios nagios 4096 Mar 12 08:08 sbindrwxrwxr-x 9 nagios nagios 4096 Mar 12 08:08 sharedrwxrwxr-x 6 nagios nagios 4096 Mar 12 08:08 varchmod o+rwx /usr/local/nagios/var/rw2.nagios plugin 插件安装[root@manager src]# rzrz waiting to receive.Starting zmodem transfer. Press Ctrl+C to cancel.Transferring nagios-plugins-1.4.13.tar.gz...100% 2226 KB 2226 KB/sec 00:00:010 Errors[root@manager src]# tar xf nagios-plugins-1.4.13.tar.gz[root@manager src]# cd nagios-plugins-1.4.13#安装依赖yum install make apr* autoconf automake curl curl-devel gcc gcc-c++ zlib-devel \openssl openssl-devel pcre-devel gd gd-devel kernel keyutils patch perl perl-devel \kernel keyutils kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl \cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel \krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch -y./configure --prefix=/usr/local/nagios --with-mysql=/usr/local/mysql/makemake installfile /usr/lib64/libxcb-reply.so.1.0.0 from install of compat-xcb-util-0.4.0-2.2.el6.x86_64 conflicts with file from package xcb-util-0.3.6-5.el6.x86_64有冲突卸载掉这个有冲突的yum remove -y xcb-util-0.3.6-5.el6.x86_643.nrpe安装[root@manager src]# rzrz waiting to receive.Starting zmodem transfer. Press Ctrl+C to cancel.Transferring nrpe-2.12.tar.gz...100% 396 KB 396 KB/sec 00:00:010 Errorstar xf nrpe-2.12.tar.gzcd nrpe-2.12./configuremake./configuremake allmake install-pluginmake install-daemonmake install-daemon-config\cp src/check_nrpe /usr/local/nagios/libexec//usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -decho'/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local要重启nrpe进⾏就先杀掉进⾏,然后重启kill `ps aux |grep nrpe |grep -v grep |awk'{print $2}'`/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d本机测试下:/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users加⼊系统服务加⼊系统服务并设为开机⾃动chkconfig --add nagioschkconfig nagios onchown nagios.nagios /usr/local/nagios/var/rw# 测试配置⽂件是否正确/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg添加别名命令,⽅便测试配置⽂件vi ~/.bashrc在⾥⾯⽤alias 来⾃定义⼀个命令来代替,这⾥我⽤checkalias check='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'source ~/.bashrc此时可以⽤check命令来检测配置⽂件了安装 nginx 的FCGI模块cd /usr/local/src/rztar xf FCGI-0.74.tar.gzcd FCGI-0.74perl Makefile.PLmake && make install安装IO 和IO-ALL模块[root@manager src]# tar xf IO-1.25.tar.gz[root@manager src]# cd IO-1.25[root@manager IO-1.25]# perl Makefile.PL[root@manager IO-1.25]# make && make install[root@manager src]# tar xf IO-All-0.81.tar.gz[root@manager src]# cd IO-All-0.81[root@manager IO-All-0.81]# perl Makefile.PL[root@manager IO-All-0.81]# make && make install上传fastcgi 的启动脚本。
监控系统配置使用(Nagios)

监控系统配置使用—Nagios
讲师:吴云鹏
税友软件集团股份有限公司
课程目标
nagios体系结构认识 • 帮助运维人员对nagios体系结构有更清晰的认识
如何配置监控项 • 帮助运维人员更有效的使用和配置nagios的监控项
理解监控项含义 • 帮助运维人员更好理解现有监控项的含义
2
课程大纲
3
系统介绍 原理、结构 部署、配置 监控项简介
问题交流
Nagios介绍
Nagios介绍: Nagios是一款用于系统和网络监控的应用程序,可在设定的条件下对主机和服务
进行监控,在状态变差和变好的时候给出告警信息。 Nagios 的特征包括: 1) 监控网络服务(SMTP、POP3、HTTP、NNTP、PING 等); 2) 监控主机资源(处理器负荷、磁盘利用率等); 3) 简单地插件设计使得用户可以方便地扩展服务的检测方法; 4) 当服务或主机问题产生与解决时将告警发送给联系人(Email)、页面声音报警 Centreon介绍: centreon作为nagios的分布式监控管理平台,它的底层使用nagios监控软件,通过 centreon页面可以简单方便地管理和配置nagios;
个性类监 控
监控项
Weblogic 类监控
Oracle类 监控
15
监控插件
插件作用
• 什么是插件?插件和命令的关系?
插件存放位置
• 存放在监控机位置?存放在被监控机位置?
现有插件
• 现有哪些插件?获取插件网站
16
回顾
通用监控
主机监控项 Weblogic监控项
Oracle监控项
17
个性监控
Godengate监控项 业务监控项 接口监控项
Linux命令高级技巧之系统监控与告警配置与管理

Linux命令高级技巧之系统监控与告警配置与管理Linux是一种开源的操作系统,广泛应用于服务器、嵌入式设备以及个人电脑等领域。
在使用Linux系统时,系统监控与告警配置与管理是非常重要的环节,可以帮助我们实时了解系统的运行状态,及时发现问题并采取相应的措施。
本文将介绍一些常用的Linux命令和技巧,以及如何进行系统监控与告警的配置与管理。
一、系统监控1. 查看系统负载系统负载是指系统当前的工作量,通常通过查看负载平均值来判断系统是否超负荷运行。
可以使用命令"uptime"来查看系统的负载情况。
2. 监控CPU使用率CPU使用率是监控系统性能的重要指标之一。
可以使用命令"top"来实时监控CPU的使用情况。
在top命令界面中,可以看到各个进程的CPU占用率以及总体的CPU使用率。
3. 监控内存使用情况内存使用情况是系统性能监控中的另一个关键指标。
可以使用命令"free"来查看系统的内存使用情况,包括已用内存、可用内存、缓存和交换空间等信息。
4. 监控磁盘空间磁盘空间是系统资源的重要组成部分,监控磁盘空间可以及时发现磁盘使用过高的情况。
可以使用命令"df"来查看磁盘的使用情况,包括各个分区的使用情况以及剩余空间。
5. 监控网络连接网络连接是系统运行中不可或缺的一部分,通过监控网络连接可以了解当前系统的网络活动情况。
可以使用命令"netstat"来查看当前的网络连接状态,包括已建立的连接、监听中的连接以及没有建立连接的端口。
二、告警配置与管理1. 设置性能告警在Linux系统中,我们可以通过一些工具和命令来设置性能告警,当系统达到一定的阈值时,自动触发告警。
其中,一个常用的工具是Nagios,它可以监控服务器和应用程序,并在发生故障时发送警报。
2. 配置邮件告警通过配置邮件告警,可以在系统出现问题时及时通知管理员,并且提供相应的解决方案。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
nagios3.20版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处、作者信息和本声明。
否则将追究法律责任。
h tt p://zh jc z r.b lo g.51c to.c o m/205837/213369nagios3.20安装配置笔记(带飞信短信报警,mssql和mysql监控)nagios 官方主页nagios /1,下载软件包nagios-3.2.0.tar.gz wget /sourcefor ge/nagios/nagios-3.2.0.tar.gznagios-plugins-1.4.14.tar.gz wget /source forge/nagiosplug/nagios-plugins-1.4.14.tar.gznrpe-2.12.tar.gz wget /sourcefor ge/nagios/nrpe-2.12.tar.gzNSClient++-Win32-0.3.6.msi wget /project/n scplus/nscplus/NSClient%2B%2B%200.3.6/NSClient%2B%2B-0.3.6-Win32.msi2,实验环境主机名操作系统IP 作用nagios-server AS5.0 192.168.0.216 监控机(nagios主程序)192.168.0.19 Cent5.0 192.168.0.19 被监控机192.168.0.113 AS4.5 192.168.0.113 被监控机192.168.0.80 Windows2k3 192.168.0.80 被监控机192.168.0.229 Windows2k3 192.168.0.229 被监控机3,监控目标nagios-server 机器是否存活ssh是否开启磁盘负载系统负载状况站点是否正常192.168.0.19 机器是否存活m ysql是否存活ssh是否开启磁盘负载系统负载状况192.168.0.113 机器是否存活m ysql是否存活ssh是否开启磁盘负载系统负载状况192.168.0.80 机器是否存活 cpu使用率m emory使用情况c盘情况e盘情况f盘情况Explorer是否正常NSClient++是否正常系统时间是否正常ftp是否正常192.168.0.229 机器是否存活 cpu使用率m emory使用情况c盘情况d盘情况m s sql2000是否正常NSClient++是否正常系统时间是否正常w3svc是否正常4,配套需要的服务的安装与配置apache安装#tar zxvf httpd-2.2.6.tar.gz#cd httpd-2.2.6#./configure--prefix=/usr/local/apache--enable-so--enable-ssl--with-ssl=/usr/local/ssl--enable-track-vars--enable-rewrite--with-zlib--enable-modules=all--enable-mods-shared=all--with-suexec-caller=daemon#make#make install飞信机器人安装下载wget /fetion/downng/fetion20090406003-linux.tar.gz wget /fetion/downng/#解压主程序tar zxvf fetion20090406003-linux.tar.gzmv install /usr/local/fetionmkdir /usr/local/fetion/libmv library_linux.tar.gz /usr/local/fetion/lib/tar zxvf library_linux.tar.gz#解压后应该有一下4个文件libACE.so.5.6.8libACE_SSL.so.5.6.8libcrypto.so.0.9.8libssl.so.0.9.8全部copy到/usr/lib下cd /usr/local/fetion/lib/cp libACE.so.5.6.8 libACE_SSL.so.5.6.8 libcrypto.so.0.9.8 libssl.so.0.9.8 /usr/l ib/设定lib库配置文件#vi /etc/ld.so.conf#增加一条/usr/lib/#保存退出后,执行#ldconfig测试是否发送成功/usr/local/fetion/fetion --m obile=15801****** --pwd=bai******** --to=136 61****** --m sg-utf8=ddd创建发送联系人的手机号的文件# zhjczr1 mobile13661******# zhjczr2 mobile13693******编辑发送脚本vi /usr/local/fetion/sendsms.sh#!/bin/shfetionDir=/usr/local/fetioncd $fetionDirDIR=`pwd`# 设置发短信的号码和飞信登录密码user=15801******pwd=bai********for phone in `cat $DIR/phonelist.txt`doecho "$phone" | sed '/^[ \t]*$/d' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | grep '^1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'if (($? == 0 ));thenif [[ -f $DIR/msg.txt ]];thencat /dev/null >msg.txtfiphone=`echo "$phone" | sed 's/^[ \t]*//' | sed 's/[ \t]*$//'`echo "sms $phone $1" >> $DIR/msg.txtecho "quit" >> $DIR/msg.txt$fetionDir/fetion --m obile=$user --pwd=$pwd --to=$phone --m sg-utf8 =$1elsecontinuefidone5,安装与配置nagios/usr/sbin/useradd -m nagios进入下载目录tar zxvf nagios-3.2.0.tar.gzcd nagios-3.2.0./configure --prefix=/usr/local/nagiosmake all# 使用make install来安装主程序,CGI和HTML文件make install# 使用make install-init在/etc/rc.d/init.d安装启动脚本make install-init# 使用make install-cofig来安装示例配置文件,安装的路径是/usr/local/nagios/etc. make install-config# 使用make install-commandmode来配置目录权限make install-commandmodenagios目录功能的简要说明:bin Nagios执行程序所在目录,nagios文件即为主程序etc Nagios配置文件位置sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录Share Nagios网页文件所在的目录var Nagios日志文件、spid 等文件所在的目录var/archives 日志归档目录var/rw 用来存放外部命令文件配置apacheScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin<Directory "/usr/local/nagios/sbin"> #Cgi文件所在目录AuthType BasicOptions ExecCGIAllowOverride NoneOrder allow,denyAllow from allAuthNam e "Nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswd #验证文件路径Require valid-user</Directory>Alias /nagios /usr/local/nagios/share<Directory "/usr/local/nagios/share"> #nagios页面文件目录AuthType BasicOptions NoneAllowOverride NoneOrder allow,denyAllow from allAuthNam e "nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswd #验证文件路径Require valid-user</Directory>#创建apache目录验证文件/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd testNew password: (输入密码)Re-type new password: (再输入一次密码)#重启apache:/usr/local/apache/bin/apachectl -k restart以后在添加文件不需要加-c的参数,-c是建立passwdfile文件。
如果passwdfile已经存在,则它被重写并截断,所以要添加新用户就直接/usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd test2这里我们提前建立好一个以后发送短信的用户/usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd sendm sg New password: (输入密码)Re-type new password: (再输入一次密码)启动Nagios#配置机器启动时自动启动Nagioschkconfig --add nagioschkconfig nagios on安装Nagios插件tar xzf nagios-plugins-1.4.14.tar.gzcd nagios-plugins-1.4.14./configuremakemake install安装nrpe插件,用来监控Linux机器tar xzvf nrpe-2.12.tar.gzcd nrpe-2.12./configuremake all#在Nagios服务器端只要安装nrpe监控插件就行make install-plugin接下来修改nagios的主配置文件nagios.cfgvi /usr/local/nagios/etc/nagios.cfg#添加或修改下面的配置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/contactgroups.cfg #联系组配置文件路径cfg_file=/usr/local/nagios/etc/objects/tim eperiods.cfg #监视时段配置文件路径cfg_file=/usr/local/nagios/etc/objects/tem plates.cfg #模板的配置文件路径cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg #主机组配置文件路径cfg_file=/usr/local/nagios/etc/objects/hosts.cfg #主机配置文件路径cfg_file=/usr/local/nagios/etc/objects/services.cfg #服务配置文件路径#把关于windows的配置选项前面的#号去掉cfg_file=/usr/local/nagios/etc/objects/windows.cfg#把server目录配置前面的#去掉,记得手动创建目录cfg_dir=/usr/local/nagios/etc/servers#如果需要查看日志就把下面的配置加上,记得自己手动创建目录log_file=/usr/local/nagios/var/nagios.logdebug_file=/usr/local/nagios/var/nagios.debugdebug_level=32#修改CGI脚本控制文件cgi.cfgvi /usr/local/nagios/etc/cgi.cfg#是否开启验证,1是开启0是关闭use_authentication=1#修改默认用户default_user_name=test#多个用户之间用逗号隔开authorized_for_system_information=nagiosadmin,testauthorized_for_configuration_information=nagiosadmin,testauthorized_for_system_commands=testauthorized_for_all_services=nagiosadmin,testauthorized_for_all_hosts=nagiosadmin,testauthorized_for_all_service_commands=nagiosadmin,testauthorized_for_all_host_commands=nagiosadmin,test定义监控时间段,配置文件timeperiods.cfgvi /usr/local/nagios/etc/objects/tim eperiods.cfg#以下的配置只能用tab键来相隔,不能用空格#默认是有以下配置的#定义了一个监控时间段,它的名称是24x7,监控的时间是每天全天24小时define timeperiod{tim eperiod_name 24x7alias 24 Hours A Day, 7 Days A Weeksunday 00:00-24:00monday 00:00-24:00tuesday 00:00-24:00wednesday 00:00-24:00thursday 00:00-24:00friday 00:00-24:00saturday 00:00-24:00}定义联系人,配置文件contacts.cfgvi /usr/local/nagios/etc/objects/contacts.cfg#以下的配置只能用tab键来相隔,不能用空格#添加下面的配置define contact{contact_nam e testalias Sys Admin ; Full name of usercontactgroups sagroupservice_notification_period 24x7 ; 服务出了状况通知的时间段,这个时间段就是上面在tim eperiods.cfg中定义的.host_notification_period 24x7 ; 主机出了状况通知的时间段, 这个时间段就是上面在timeperiods.cfg中定义的service_notification_options w,u,c,r ; 当服务出现w—报警(warning),u—未知(unkown),c—严重(critical),或者r—从异常情况恢复正常,在这四种情况下通知联系人.host_notification_options d,u,r ; 当主机出现d—当机(do wn),u—返回不可达(unreachable),r—从异常情况恢复正常,在这3种情况下通知联系人service_notification_commands notify-service-by-em ail ; 服务出问题通知采用的命令notify-service-by-em ail,这个命令是在commands.cfg中定义的,作用是给联系人发邮件.host_notification_commands notify-host-by-em ail ; 主机出问题时采用的也是发邮件的方式通知联系人em ail zhaojc@ ; 联系的人em ail地址}define contact{contact_nam e sendm sgalias Sys Admin ; Full name of usercontactgroups sendm sggroupservice_notification_period 24x7host_notification_period 24x7service_notification_options w,u,c,rhost_notification_options d,u,rservice_notification_commands notify-service-by-sendm sg ; 服务出问题通知采用的命令notify-service-by-sendm sg,这个命令是在commands.cfg中定义的,作用是给联系人发短信.host_notification_commands notify-host-by-sendm sg ; 主机出问题时采用的也是发邮件的方式通知联系人em ail zhaojc@}将多个联系人组成一个联系人组,创建文件contactgroups.cfgvi /usr/local/nagios/etc/objects/contactgroups.cfg#以下的配置只能用tab键来相隔,不能用空格#要添加多个用户到sagroup组只需要在m embers后面继续增加用户名即可,需要用逗号(,)相隔define contactgroup{contactgroup_name sagroupalias Novell Administratorsm embers test}define contactgroup{contactgroup_name sendm sggroupalias Sendm sg Administratorsm embers sendm sg}定义被监控主机,创建文件hosts.cfgvi /usr/local/nagios/etc/objects/hosts.cfg#以下的配置只能用tab键来相隔,不能用空格define host{host_nam e nagios-server #定义主机名字alias wd-linux-216 #定义别名address 192.168.0.216 #真是ip地址check_command check-host-alive #监控的命令check-h ost-alive,这个命令来自commands.cfg,用来监控主机是否存活m ax_check_attem pts 5 #检查失败后重试的次数 check_period 24x7 #检查的时间段24x7,同样来自于我们之前在timeperiods.cfg中定义的contact_groups sagroup #联系人组,上面在contact groups.cfg中定义的sagroupnotification_interval 10 #提醒的间隔,每隔10秒提醒一次notification_period 24x7 #提醒的周期, 24x7,同样来自于我们之前在timeperiods.cfg中定义的notification_options d,u,r #指定什么情况下提醒,具体含义见之前contacts.cfg部分的介绍}与联系人可以组成联系人组一样,多个主机也可以组成主机组.创建文件hostgrops.cfgvi /usr/local/nagios/etc/objects/hostgroups.cfg#以下的配置只能用tab键来相隔,不能用空格#同样,多台主机名需要用逗号(,)相隔#事先加好其他的主机名到组里,稍候再讲其他主机名的配置define hostgroup{hostgroup_name linux-serversalias Linux Serversm embers nagios-server,192.168.0.19,192.168.0.113}define hostgroup{hostgroup_name windows-serversalias Windows Serversm embers 192.168.0.80,192.168.0.229}定义监控的项目服务,创建services.cfgvi /usr/local/nagios/etc/objects/services.cfg#以下的配置只能用tab键来相隔,不能用空格define service{host_nam e nagios-server #被监控的主机,hosts.cfg中定义的service_description check-host-alive #这个监控项目的描述(也可以说是这个项目的名称),可以空格,我们这里定义的是监控这个主机是不是存活check_command check-host-alive #所用的命令,是commands.cf g中定义的m ax_check_attempts 5norm al_check_interval 3retry_check_interval 2check_period 24x7 #监控的时间段,是timeperiods.cfg中定义的notification_interval 10notification_period 24x7 #通知的时间段, ,是timeperiods.c fg中定义的notification_options w,u,c,rcontact_groups sagroup #联系人组,是contactgroups.cfg 中定义的}define service{host_nam e nagios-serverservice_description check-sshcheck_command check_tcp!22 #所用的命令,是comman ds.cfg中定义的m ax_check_attempts 5norm al_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e nagios-serverservice_description check_local_diskcheck_command check_local_disk!10%!5%!/ #所用的命令,是co mmands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e nagios-serverservice_description check-loadcheck_command check_nrpe!check_load #所用的命令,是com mands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e nagios-serverservice_description m -Javacheck_command check_http_uri!8080!http://lily_gsm.local/sm sse nd/index.ht ml #所用的命令,是commands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups +sendmsggroup #联系人组,是contactgro ups.cfg中定义的,这里的+代表不替换原有的sagroup组而是增加了sendmsggroup组}建立servers文件夹mkdir /usr/local/nagios/etc/servers/创建被监控机的配置文件vi /usr/local/nagios/etc/servers/192.168.0.19_l.cfg#以下的配置只能用tab键来相隔,不能用空格define host{host_nam e 192.168.0.19alias wd-linux-19address 192.168.0.19check_command check-host-alive #所用的命令,是commands. cfg中定义的m ax_check_attempts 5check_period 24x7contact_groups sagroupnotification_interval 10notification_period 24x7notification_options d,u,r}define service{host_nam e 192.168.0.19service_description check-host-alivecheck_command check-host-alive #所用的命令,是comma nds.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e 192.168.0.19service_description check-ssh #监控ssh端口是否存活的名称,在nagios中显示的check_command check_tcp!22 #所用的命令,是comm ands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e 192.168.0.19service_description check_local_diskcheck_command check_local_disk!10%!5%!/ #所用的命令,是c ommands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e 192.168.0.19service_description check-loadcheck_command check_nrpe!check_load #所用的命令,是com mands.cfg中定义的m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups sagroup}define service{host_nam e 192.168.0.19service_description MySQLcheck_command check_m ysql!slave1!123456!3306 #所用的命令,是commands.cfg中定义的,slave1是mysql的用户名,123456是密码,3306是端口,!是相隔标志m ax_check_attem pts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,u,c,rcontact_groups +sendmsggroup #联系人组,是contact groups.cfg中定义的,这里的+代表不替换原有的sagroup组而是增加了sendmsggroup 组}#在这里说明下,host_name是主机名称需要在host中有定义,本例在192.168.0.19_l. cfg这个配置文件中先配置了host,然后在配置了server,这样做的好处是便于管理,如果以后监控的机器非常多都写在hosts.cfg和services.cfg文件中,那样查看起来比较麻烦,所以这样分机器些配置文件是便于以后的管理,现在把其他的被监控的机器也分别配置好就可以,这里可以以192.168.0.19_l.cfg为例,来copy成其他需要被监控的文件,在修改下主机名就可以了,这样以后再加新的机器就简单多了。