第1步:安装Monit Package

要安装Monit,只需在Ubuntu服务器上运行下面的命令。

sudo apt update
sudo apt install monit

安装Monit后,下面的命令可用于停止,启动和启用Monit服务。

sudo systemctl stop monit.service
sudo systemctl start monit.service
sudo systemctl enable monit.service
在Ubuntu 上安装Monit系统监控

Monit 是一个用于管理和监控Linux系统的开源实用程序 。
它可以自动化,维护和修复Linux服务,包括还原和重新启动它们。

第3步:访问Monit Web 主页

使用浏览器打开Monit Web页面

http://localhost:2812

用户名和密码是admin,password,在上面的配置文件中定义。

默认情况下,Monit监控的服务不多。
我们可以通过在/etc/monit/conf.d/目录中创建来添加要监视的自定义服务。

例如,要监视Apache2服务,请在/etc/monit/conf.d/目录中创建名为apache2.conf的自定义配置文件。

sudo nano /etc/monit/conf.d/apache2.conf

然后添加以下行:

# Apache configuration
check process apache2 with pidfile /run/apache2/apache2.pid
    start program = "/bin/systemctl start apache2" with timeout 60 seconds
    stop program  = "/bin/systemctl stop apache2"
    restart program = "/bin/systemctl restart apache2" with timeout 120 seconds

保存文件并运行以下命令以监视Apache2.

sudo monit check -t
sudo monit reload
sudo monit start all

第2步:配置Monit服务

Monit配置文件位于/etc/monit /目录下。
主要配置文件是/etc/monit/monitrc,并其中配置了基本设置。
我们需要进行一些更改以满足环境。

默认情况下,当服务启动时,Monit读取位于/etc/conf.d/和/etc/monit/conf-enabled/的所有文件。
将所有监视配置文件放入/etc/monit/conf.d/目录中。

打开Monit 主配置文件

sudo nano /etc/monit/monitrc

允许通过HTTP访问Monit Web界面:

## Monit has an embedded HTTP interface which can be used to view status of
## services monitored and manage services from a web interface. The HTTP
## interface is also required if you want to issue Monit commands from the
## command line, such as 'monit status' or 'monit restart service' The reason
## for this is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wiki if you want to
## enable SSL for the HTTP interface.
#
 set httpd port 2812 and
     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'
#     #with ssl {            # enable SSL/TLS and set path to server certificate
#     #    pemfile: /etc/ssl/certs/monit.pem
#     #}

设置后,我们能够通过LocalHost Name或者IP和Username登录Monit服务器:Admin,密码:Monit

运行以下命令重新启动Monit服务:

sudo systemctl restart monit.service
日期:2020-07-07 20:57:27 来源:oir作者:oir