nagios监控windows及linux从而实现飞信报警

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

nagios主要功能是实现报警

yum环境搭建:

[root@localhost~]#mount/dev/cdrom/mnt/cdrom/

mount:blockdevice/dev/cdromiswrite-protected,mountingread-only

[root@localhost~]#vim/etc/yum.repos.d/rhel-debuginfo.repo

[rhel-server]

name=RedHatEnterpriseLinuxserver

baseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

安装步骤

安装lamp环境

yuminstallmysqlmysql-develhttpdphpphp-gdphp-mbstring

测试lamp环境

创建一个组nagcmd

[root@localhostnagios-3.2.1]#groupaddnagcmd

创建一个账号nagios

[root@localhostnagios-3.2.1]#useradd-mnagios

加入组

[root@localhostnagios-3.2.1]#usermod-a-Gnagcmdnagios

将apache账号也添加进来

[root@localhostnagios-3.2.1]#usermod-a-Gnagcmdapache

解压缩

cdnagios-cn-3.2.3

配置

./configure--with-command-group=nagcmd--enable-event-broker

或者

./configure--with-command-group=nagcmd--prefix=/usr/local/nagios--sysconfdir=/etc/nagios--enable-event-broker

root@localhostnagios-3.2.1]#makeall

[root@localhostnagios-3.2.1]#makeinstall

(-Thisinstallstheinitscriptin/etc/rc.d/init.d)

makeinstall-commandmode

-Thisinstallsandconfigurespermissionsonthe

directoryforholdingtheexternalcommandfile

makeinstall-config

-Thisinstallssampleconfigfilesin/usr/local/nagios/etc

进入nagios目录

cd/usr/local/nagios/

在http服务器的配置目录(conf.d)下形成nagiosweb程序

cdnagios-cn-3.2.3

makeinstall-webconf

创建一个登陆nagiosweb程序的用户这个账号在以后通过web登陆nagios认证时使用

htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin

启动apache

servicehttpdstartchkconfighttpdon

安装nagios插件

./configure(perfix=/usr/local/nagios)--with-nagios-user=nagios--with-nagios-group=nagios

或者

./configure--with-nagios-user=nagios--with-nagios-group=nagios

make

makeinstall

将nagios服务加入chkconfig管理之类

chkconfig--addnagios

chkconfig--addnagios

检查nagios的配置文件的语法是否正确

/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

可以将/usr/local/nagios/bin加入命令搜索路径中

vim.bashrc

..bashrc重新读取环境文件

可以将/usr/local/nagios/etc/nagios.cfg设置为一个连接

ln-s/usr/local/nagios/etc/nagios.cfg/etc/nagios.cfg

检查语法

nagios-v/etc/nagios.cfg

启动nagios服务

启动httpd服务

编辑vim/usr/local/nagios/etc/nagios.cfg

注释36行#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

重启nagios会报错,原因,是无可监控

打开该文件中的其他主机比如windows

39cfg_file=/usr/local/nagios/etc/objects/windows.cfg

重启服务

windows检测客户端配置

Snmp161

Nsclienrt12489check_nt

Nrpe5666

naclient改变里面的ns.ini

然后从其windows上的ncclient

在nagios服务器上,更改object下的window。dfg定义

重启nagios服务

134231414.png

134231307.png

134232212.png

134232412.png

linux客户段安装

先创建账号nagios

[root@localhost~]#yuminstallmysqlmysql-serverhttpdmysql-devel

[root@localhost~]#useraddnagios

安装插件

./configure(perfix=/usr/local/nagios)--with-nagios-user=nagios--with-nagios-group=nagios

或者

./configure--with-nagios-user=nagios--with-nagios-group=nagios

make&&makeinstall

安装nrpe(客户端和服务端都需要)

#tar-zxvfnrpe-2.12.tar.gz

#cdnrpe-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

#makeall

#makeinstall-plugin

#makeinstall-daemon

#makeinstall-daemon-config

编辑客户端nrpe配置文件

vim/usr/local/nagios/etc/nrpe.cfg

(allowed_hosts=192.168.101.102(服务器地址))

以进程的方式启动nrpe

/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d

nrpe服务器段

1.#./configure--with-nrpe-user=nagios\

--with-nrpe-group=nagios\

--with-nagios-user=nagios\

--with-nagios-group=nagios\

--enable-command-args\

--enable-ssl

#makeall

#makeinstall-plugin

2.commands.cfg定义外部构件nrpe

vim/usr/local/nagios/etc/objects/commands.cfg

增加

definecommand{

command_namecheck_nrpe

command_line$USER1$/check_nrpe-H$HOSTADDRESS$-c$ARG1$

}

3.为了监控linux系统修改nagios.cfg

vim/usr/local/nagios/etc/nagios.cfg

添加一行

cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg

4.在/usr/local/nagios/etc/objects创建mylinux.cfg

definehost{

uselinux-server;Inheritdefaultvaluesfromatemplate

host_namemylinux;Thenamewe'regivingtothishost

aliasmylinux;Alongernameassociatedwiththehost

address192.168.101.110;IPaddressofthehost

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck-swap

check_commandcheck_nrpe!check_swap

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_load

check_commandcheck_nrpe!check_load

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck-disk

check_commandcheck_nrpe!check_had1

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_user

check_commandcheck_nrpe!check_users

}

defineservice{

usegeneric-service

host_namemylinux

service_descriptioncheck_procs

check_commandcheck_nrpe!check_total_procs

}

改变数组

chownnagios.nagiosmylinux.cfg

5实现飞信报警

脚本(附件下载)

a、将飞信的文档传入linux系统,将库文件放入/usr/lib目录

chmoda+xfetion

b、使用下列命令测试./fetion--mobile=15136848083--pwd=lsx885--to15136848083--msg-type=0--msg-utf8$HOSTNAME

c.编辑vim/usr/local/nagios/etc/objects/contacts.cfg(这个文件可以不修改)

vim/usr/local/nagios/etc/objects/templates.cfg

34service_notification_commandsnotify-service-by-fetion;sendservicenotificationsviaemail

35host_notification_commandsnotify-service-by-fetion;sendhostnotificationsviaemail

d。定义命令

vim/usr/local/nagios/etc/objects/commands.cfg

definecommand{

command_namenotify-service-by-fetion

command_line/usr/bin/fetion--mobile=15136848083--pwd=lsx885--to15136848083--msg-type=0--msg-utf8$HOSTNAME

}

check_nrpe语法:

check_nrpe...-c<command>[-a<argument><argument><argument>]

check_nrpe的内置命令:

·CheckAlwaysCRITICAL(check)

·CheckAlwaysOK(check)

·CheckAlwaysWARNING(check)

·CheckCPU(check)

·CheckCRITICAL(check)

·CheckCounter(check)

·CheckEventLog/CheckEventLog(check)

·CheckFile(check)

·CheckFileSize(check)

·CheckMem(check)

·CheckMultiple(check)

·CheckOK(check)

·CheckProcState(check)

·CheckServiceState(check)

·CheckTaskSched/CheckTaskSched(check)

·CheckUpTime(check)

·CheckVersion(check)

·CheckWARNING(check)

·CheckWMI/CheckWMI(check)

·CheckWMIValue(check)

用法如:

#check_nrpe...-cCheckCPU-awarn=80crit=90time=20mtime=10stime=4










本文转自 only223wym 51CTO博客,原文链接:http://blog.51cto.com/ymchaofeng/1318968,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
28天前
|
监控 网络协议 Shell
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
33 0
|
4天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF
27 0
|
14天前
|
安全 Ubuntu Linux
Linux远程访问Windows实现步骤
在Windows上启用远程桌面连接并获取IP地址后,Linux用户需安装SSH客户端( Debian系:`sudo apt-get update; sudo apt-get install openssh-client`,RPM系:`sudo yum install openssh-clients`)。然后使用命令`ssh 用户名@Windows_IP地址`连接,其中`用户名`和`Windows_IP地址`按实际情况填写。
14 4
|
27天前
|
监控 Shell Linux
【Shell 命令集合 系统设置 】Linux 管理和监控电源管理 apmd命令 使用指南
【Shell 命令集合 系统设置 】Linux 管理和监控电源管理 apmd命令 使用指南
28 0
|
29天前
|
Linux 数据安全/隐私保护 Docker
linux和windows中安装emqx消息服务器
linux和windows中安装emqx消息服务器
27 0
|
1月前
|
缓存 监控 Linux
linux 内存监控
linux 内存监控
14 1
|
2月前
|
弹性计算 运维 安全
阿里云服务器linux和windows镜像有啥区别?
阿里云服务器linux和windows镜像有啥区别?阿里云服务器镜像Windows和Linux操作系统有什么区别?性能有差异吗?有,同配置下Linux性能要优于Windows,但这与阿里云无关,仅仅是linux和windows之间的区别。另外,阿里云提供的windows和linux操作系统均为正版授权,用户不需要额外支付许可费用,如何选择?看用户自己的应用程序情况
|
2月前
|
弹性计算 运维 安全
阿里云服务器镜像怎么选?Linux和Windows有啥区别?
阿里云服务器镜像怎么选?Linux和Windows有啥区别?阿里云服务器镜像Windows和Linux操作系统有什么区别?性能有差异吗?有,同配置下Linux性能要优于Windows,但这与阿里云无关,仅仅是linux和windows之间的区别。另外,阿里云提供的windows和linux操作系统均为正版授权,用户不需要额外支付许可费用,如何选择?看用户自己的应用程序情况
66 0
|
4月前
|
编解码 安全 Linux
Linux vs windows 他们之间的区别
Linux vs windows 他们之间的区别
46 0