`

使用monit监控本机服务

 
阅读更多
【安装】
yum install monit

【配置告警】
修改/etc/monit.conf
set daemon 60

set httpd port 1966
#设置允许访问服务的账号密码
allow monitor:kaka2123
#允许访问的地址,下面是所有地址
allow 0.0.0.0/0.0.0.0

#设置告警邮件使用的服务器,下面用的是qq邮箱,采用的是ssl连接
set mailserver smtp.exmail.qq.com port 465 USERNAME "123456@qq.com"  PASSWORD "123456" using sslv3

#邮件格式,$Host如果没有设置默认是localhost
set mail-format {
  from: notifications@kakatool.com
  Subject: monit alert -- $Host $EVENT $SERVICE
  message: $EVENT Service $SERVICE
          Date:        $DATE
          Action:      $ACTION
          Host:        $HOST
          Description: $DESCRIPTION
  Your faithful employee,
  monit
}

#告警邮件的接收人
set alert somebody@abc.com 
set alert someone@abc.com

set eventqueue
basedir /var/monit

#默认会读取/etc/monit.d下的所有监控服务配置文件
# Include all files from /etc/monit.d/


【配置服务器】
在/etc/monit.d目录下新增以下文件
1、mysql.conf
check process mysqld with pidfile /var/run/mysqld/mysqld.pid 
  if failed port 3306 then alert
  ##下面的语句会在有问题时尝试重启服务,如果重启5次后仍然是不则会报警
  #start program = "/etc/init.d/mysqld start" with timeout 10 seconds
  #stop program  = "/etc/init.d/mysqld stop"
  #if failed port 3306 protocol mysql then alert
  #  with timeout 10 seconds 
  #  then restart
  #if 3 restarts within 5 cycles then alert 


2、nginx.conf
check process nginx with pidfile /var/run/nginx.pid 
  start program = "/etc/init.d/nginx start" with timeout 10 seconds
  stop program  = "/etc/init.d/nginx stop"
  if failed host heylinux.com port 80 protocol http
    with timeout 10 seconds
    then restart
  if 3 restarts within 5 cycles then timeout


3、php.conf
check process php-fpm with pidfile /opt/php/var/run/php-fpm.pid
  start program = "/etc/init.d/php56.fpm start" with timeout 10 seconds
  stop program  = "/etc/init.d/php56.fpm stop"
  if cpu > 60% for 5 cycles then restart
  if loadavg(5min) greater than 4 for 5 cycles then restart
  if 3 restarts within 5 cycles then timeout


4、redis.conf
check process redis with pidfile /var/run/redis/redis.pid 
  if failed port 6379 then alert


5、ssh.conf
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout


6、oss.conf
if loadavg (1min) > 10 then alert
if loadavg (5min) > 6 then alert
if memory usage > 50% for 5 cycles then alert
if cpu usage (user) > 50% then alert
if cpu usage (system) > 50% then alert
if cpu usage (wait) > 75% then alert

##下面是监控磁盘使用量,需根据实际路径修改
check device home with path /dev/mapper/vg_9quidc-lv_home
    if space usage > 70% for 1 times within 1 cycles then alert
check device root with path /dev/mapper/vg_9quidc-lv_root
    if space usage > 70% for 1 times within 1 cycles then alert
check device sda1 with path /dev/sda1
    if space usage > 70% for 1 times within 1 cycles then alert


【重启并查看服务】
> service monit restart
> monit status
分享到:
评论

相关推荐

    monit监控工具(客户端)

    Monit 可以监控多种服务,包括 SSH、MySQL、Nginx 等。例如,可以监控 SSH 服务的进程,检查 SSH 服务是否启动,如果不启动则自动启动。如果 SSH 服务 5 次重启失败,则超时。类似地,可以监控 MySQL 和 Nginx 服务...

    monit 服务端监控

    `monit status`命令将显示所有被监控项的状态,包括服务是否在线、资源使用情况等。 **Monit的报警机制** Monit支持多种报警方式,包括发送电子邮件、执行脚本或通过HTTP接口。在配置文件中,可以设置当监控条件...

    monit服务监控管理工具

    Monit 是一款强大的开源服务监控管理工具,专为Linux系统设计,它允许用户对系统中的进程、文件、目录、网络服务等进行实时监控,并在发现问题时自动修复或通知管理员。这款工具不仅提供了命令行接口,还包含了一个...

    monit使用说明.docx

    3. 远程主机监控:Monit 不仅能监控本地服务,还可以监控依赖远程主机的服务。 配置Monit需要编写控制文件`monitrc`,默认位于用户的`.monitrc`或`/etc/monitrc`。在启动Monit之前,使用`monit -t`命令检查配置文件...

    centos7安装monit

    最后,可以使用`monit status`命令查看当前的监控状态,或者使用`monit summary`查看简洁的概览。此外,Monit有一个内置的Web界面,通过访问`http://localhost:2812`可以查看和管理监控设置(默认用户名和密码是`...

    如何借助Monit搭建服务器监控系统-.docx

    Monit 提供了成熟的监控功能,包括进程状态监控、文件系统变化监控、电子邮件通知、针对核心服务的可定制操作等。 二、Monit 的优点 Monit 集安装简易、轻量级实现和功能强大于一身,是一款再理想不过的备用监控...

    monit-5.4.tar.gz

    在实际使用中,Monit 可以监控各种服务,如HTTP服务器、数据库服务、邮件服务等,通过HTTP接口提供可视化管理界面,方便远程监控和管理。同时,Monit支持发送警报邮件,及时通知用户系统异常情况。 总的来说,...

    monit-docker:Docker化监控

    在 conf.d 中添加要监视的服务/进程的配置比如可以在conf.d中添加nginx监控为 check process nginx with pidfile /var/run/nginx.pid start program = "/etc/init.d/nginx start" stop program = "/etc/init.d/...

    monit-4.9.tar

    Monit 是一款在 Unix-like 系统中广泛使用的开源监控工具,主要用于监控系统服务、文件、目录、程序以及网络资源的状态。"monit-4.9.tar" 是这个软件的一个特定版本,通常以 tar 归档文件的形式提供,用于在各种 ...

    monit-5.0.1.tar.gz_monit-5.0.1.tar.gz

    例如,你可以监控某个服务的状态,如果服务停止运行,Monit 可以自动重启它。 5. 初始化与启动:Monit 通常需要与系统的初始化系统集成,如Systemd或SysV init。这可能需要执行 `sudo systemctl enable monit` 或 `...

    monit-dashboard:Web仪表板,可一目了然地监控所有monit服务器

    监控面板 描述 一目了然的Python Web应用程序可获取一堆服务器的仪表板。 屏幕截图 每个Monit服务器未找到警报时的主视图: 一个Monit代理正在报告服务器上的错误: 展开服务器,上面有错误的问题: 它是如何...

    dogpack:Monit集群管理工具

    Monit 允许用户监控系统资源如 CPU 使用率、内存消耗、磁盘空间以及网络服务的状态,当检测到异常时,它可以自动采取修复措施或发送警告通知。`dogpack` 的目的是简化 Monit 在集群环境中的部署和管理。 ### Monit ...

    Ansible-ansible-role-monit.zip

    1. **tasks**: 这个目录包含了一系列的YAML文件,定义了具体的操作步骤,比如安装Monit、配置Monit的监控项、启动和启用Monit服务等。 2. **defaults**: 这里定义了角色的默认变量,如Monit的配置选项、服务监控...

    monit_bin-源码.rar

    6. **配置文件**:Monit 使用配置文件来定义需要监视的项目和相应的策略,这使得定制化监控变得简单。 接下来,解压 `monit_bin-源码.zip` 文件后,我们可以进行以下操作: 1. **学习源码**:通过阅读 C 语言编写...

    python-monit:与Monit对话的Python库

    1. **服务管理**:`python-monit` 允许通过Python代码启动、停止、重启Monit监控的服务,这对于自动化运维流程非常有帮助。 2. **状态查询**:可以获取服务的运行状态,如是否在线、是否有错误等,以便及时了解系统...

    统信UOS系统安装nmon监控教程

    本教程将指导你如何在统信UOS系统上安装并使用nmon监控工具。首先,我们需要准备nmon的安装包,这里提供的是nmon_16g+debian-3_arm64.deb,这是一款针对64位架构的Debian兼容版本的nmon。在统信UOS上,由于其底层也...

    monit:ASYD 的 Monit 分叉

    AsydSolutions/monit 这是来自官方的分支,包括一些小的更改,用于... 您可能需要更多 RAM,具体取决于 Monit 应监控的服务数量。 ANSI-C 编译器和构建系统。 您需要安装 ANSI-C99 编译器来构建 Monit。 推荐使用自由

    基于Ubuntu Nginx Mongrel Mysql部署rails monit-5.0

    最后,配置Monit来监控所有关键服务,确保它们始终处于运行状态。 总结来说,这个部署方案利用了Ubuntu的稳定基础,Nginx的高性能,Rails的开发效率,Mongrel的执行效率,MySQL的数据库支持,以及Monit的监控保障,...

    docker-monit:用于monit的Docker映像

    监控的基本图像docker-monit是一个映像,已配置为可直接使用或用作监控守护程序更多自定义应用程序的基础。 docker-monit可用于从提取该图像包括监控版本5.13概述此映像将monit安装到以下位置: / opt / monit Monit...

    ansible-monit:Monit的Ansible角色

    在不安装和使用自定义服务的情况下配置monit: - role : monit monit_setup : configure monit_custom_services : consul : {group: monitoring, pid: /var/run/consul/consul.pid, checks: [ {type: host, ...

Global site tag (gtag.js) - Google Analytics