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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 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,如需转载请自行联系原作者
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3天前
|
Linux 数据安全/隐私保护 Windows
Linux共享Windows目录
Linux共享Windows目录
|
7天前
|
缓存 NoSQL Linux
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据
|
3天前
|
Unix Linux Ruby
在windows和linux上高效快捷地发布Dash应用
在windows和linux上高效快捷地发布Dash应用
|
3天前
|
Linux iOS开发 开发者
跨平台开发不再难:.NET Core如何让你的应用在Windows、Linux、macOS上自如游走?
【8月更文挑战第28天】本文提供了一份详尽的.NET跨平台开发指南,涵盖.NET Core简介、环境配置、项目结构、代码编写、依赖管理、构建与测试、部署及容器化等多个方面,帮助开发者掌握关键技术与最佳实践,充分利用.NET Core实现高效、便捷的跨平台应用开发与部署。
30 3
|
3天前
|
Ubuntu Linux 虚拟化
安装Windows Linux 子系统的方法:适用于windows 11 版本
本文提供了在Windows 11系统上安装Linux子系统(WSL)的详细步骤,包括启用子系统和虚拟化功能、从Microsoft Store安装Linux发行版、设置WSL默认版本、安装WSL2补丁,以及完成Ubuntu的首次安装设置。
16 2
|
2天前
|
Linux Windows Python
最新 Windows\Linux 后台运行程序注解
本文介绍了在Windows和Linux系统后台运行程序的方法,包括Linux系统中使用nohup命令和ps命令查看进程,以及Windows系统中通过编写bat文件和使用PowerShell启动隐藏窗口的程序,确保即使退出命令行界面程序也继续在后台运行。
|
监控 Linux 开发工具
下一篇
云函数