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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

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,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
运维 监控 中间件
Linux运维笔记 - 如何使用WGCLOUD监控交换机的流量
WGCLOUD是一款开源免费的通用主机监控工具,安装使用都非常简单,它可以监控主机、服务器的cpu、内存、磁盘、流量等数据,也可以监控数据库、中间件、网络设备
|
7月前
|
Prometheus 监控 Cloud Native
Prometheus+Grafana监控Linux主机
通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
563 7
|
7月前
|
Prometheus 运维 监控
Prometheus+Grafana+NodeExporter:构建出色的Linux监控解决方案,让你的运维更轻松
本文介绍如何使用 Prometheus + Grafana + Node Exporter 搭建 Linux 主机监控系统。Prometheus 负责收集和存储指标数据,Grafana 用于可视化展示,Node Exporter 则采集主机的性能数据。通过 Docker 容器化部署,简化安装配置过程。完成安装后,配置 Prometheus 抓取节点数据,并在 Grafana 中添加数据源及导入仪表盘模板,实现对 Linux 主机的全面监控。整个过程简单易行,帮助运维人员轻松掌握系统状态。
905 3
|
9月前
|
监控 安全 Linux
使用NRPE和Nagios监控Linux系统资源的方法
通过遵循以上步骤,可以有效地使用NRPE和Nagios监控Linux系统资源,确保系统运行稳定,并及时响应任何潜在的问题。这种方法提供了高度的可定制性和灵活性,适用于从小型环境到大型分布式系统的各种监控需求。
156 2
|
10月前
|
存储 监控 Linux
监控Linux服务器
详细介绍了如何监控Linux服务器,包括监控CPU、内存、磁盘存储和带宽的使用情况,以及使用各种系统监控工具如vmstat、iostat、sar、top和dstat来分析系统性能,并推荐了一些开源监控系统。
162 0
监控Linux服务器
|
11月前
|
监控 安全 Linux
在Linux中,zabbix如何监控脑裂?
在Linux中,zabbix如何监控脑裂?
|
17天前
|
Linux 虚拟化 iOS开发
Windows Server 2022 OVF (2025 年 6 月更新) - VMware 虚拟机模板
Windows Server 2022 OVF (2025 年 6 月更新) - VMware 虚拟机模板
72 6
Windows Server 2022 OVF (2025 年 6 月更新) - VMware 虚拟机模板
|
2月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 5 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 5 月更新)
136 2
|
2月前
|
Ubuntu 虚拟化 Windows
无影云电脑选择哪个操作系统Windows server 2019还是Ubuntu?
在选择阿里云无影云电脑的操作系统时,Windows Server 2019 和 Ubuntu 各有优势。Windows适合依赖微软生态的企业级应用,提供图形化界面和高安全性;Ubuntu则轻量、经济,适合开源工具链和容器化部署。根据应用场景、资源占用、安全性、开发效率及成本考量,选择最适合的系统。条件允许下,可采用混合方案满足多样化需求。
|
3月前
|
Linux 虚拟化 iOS开发
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板
122 29
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板