在 centos7 上使用 monit 监控服务状态
最编程
2024-03-01 18:08:17
...
目录
- 1. 安装
- 2. 配置
- 3. 配置监控服务
- 4. 常用语法
- 5. 监控页面
1. 安装
yum -y install epel-release
yum -y install monit
2. 配置
vim /etc/monitrc
set daemon 30
set log syslog
set httpd port 2812 and
use address 172.20.10.11
allow 172.20.10.2
allow admin:monit
#with ssl { # enable SSL/TLS and set path to server certificate
# pemfile: /etc/ssl/certs/monit.pem
#}
include /etc/monit.d/*
3. 配置监控服务
a. 监控apache:vim /etc/monit.d/apache
check process apache with pidfile /etc/httpd/logs/httpd.pid
start program = "/usr/bin/systemctl start httpd"
stop program = "/usr/bin/systemctl stop httpd"
b. 监控mysql:vim /etc/monit.d/mysql
check process mysql with pidfile /usr/local/mysql/data/lee.pid
start program = "/usr/bin/systemctl start mysqld"
stop program = "/usr/bin/systemctl stop mysqld"
c. 监控ssh:vim /etc/monit.d/ssh
check process ssh with pidfile /run/sshd.pid
start program = "/usr/bin/systemctl start sshd"
stop program = "/usr/bin/systemctl stop sshd"
4. 常用语法
a. 检测配置文件语法:
monit -t
b. 启动服务:
systemctl start monit
c. 停止服务:
systemctl stop monit
d. 重启服务:
systemctl restart monit
e. 查看服务运行状态:
systemctl status monit -l
f. 查看错误日志:
tail /var/log/monit.log
5. 监控页面
http://172.20.10.11:2812
推荐阅读
-
在 Linux 上使用 Monit 在服务挂起时将其调出。
-
在 Linux 上使用 Monit 在服务挂起时将其调出。
-
在 centos7 上使用 monit 监控服务状态
-
玩转Java底层:JMX详解 - jconsole与自定义MBean监控工具的实际应用与区别" 在日常JVM调优中,我们熟知的jconsole工具通过JMX包装的bean以图形化形式展示管理数据,而像jstat和jmap这类内建监控工具则由JVM直接支持。本文将以jconsole为例,深入讲解其实质——基于JMX的MBean功能,包括可视化界面上的bean属性查看和操作调用。 MBeans在jconsole中的体现是那些可观察的组件属性和方法,如上图所示,通过名为"Verbose"的属性能看到其值为false,同时还能直接操作该bean的方法,例如"closeJerryMBean"。 尽管jconsole给我们提供了直观的可视化界面,但请注意,这里的MBean并非固定不变,开发者可根据JMX提供的接口将自己的自定义bean展示到jconsole。以下步骤展示了如何创建并注册一个名为"StudyJavaMBean"的自定义MBean: 1. 首先定义接口`StudyJavaMBean`,接口需遵循MBean规范,即后缀为"MBean"且包含getter方法代表属性,如`getApplicationName`,和无返回值的setter方法代表操作,如`closeJerryMBean`。 ```java public interface StudyJavaMBean { String getApplicationName(); void closeJerryMBean(); } ``` 2. 编写接口的实现类`StudyJavaMBeanImpl`,实现接口中的方法: ```java public class StudyJavaMBeanImpl implements StudyJavaMBean { @Override public String getApplicationName() { return "每天学Java"; } @Override public void closeJerryMBean() { System.out.println("关闭Jerry应用"); } } ``` 3. 在代码中注册自定义MBean,涉及的关键步骤包括: - 获取平台MBeanServer - 定义ObjectName,指定唯一的MBean标识符 - 注册MBean到服务器 - 启动RMI连接器服务,以便jconsole能够访问 ```java public void registerMBean() throws Exception { // ... 具体实现省略 ... } ``` 实际运行注册后的MBean,您将在jconsole中发现并查看自定义bean的属性和调用相关方法。然而,这种方式相较于传统的属性/日志查看和HTTP接口,实用性相对有限,可能存在潜在的安全风险。但不可否认的是,JMX及其MBean机制对于获取操作系统信息、内存状态等关键性能指标仍然具有重要价值。例如: 1. **获取操作系统信息**:通过JMX MBean,可以直接获取到诸如CPU使用率、操作系统版本等系统级信息,这对于资源管理和优化工作具有显著帮助。
-
使用Foxmail和Java代码在Linux CentOS7上设置邮件服务器并发送邮件(下)