如何设置MONIT来监视MariadB复制?

发布于 2025-02-12 15:58:22 字数 1448 浏览 1 评论 0 原文

我使用 monit 5.27.2和 Mariadb 10.5.15在我的 debian 11个服务器。

我的服务器以 Multi-Source Mariadb Replication

有时,复制停止,我没有被通知。我还没有看到任何准备好的MONIT的配置来发送此类警报。

在以下查询中可见错误:

SHOW SLAVE STATUS;

这些值特别有趣:

”

”

我尚未找到任何使用MONIT直接监视A的结果的方法SQL语句。但是,似乎可以监视命令的返回代码带有版本的带有5.29.0之前的版本(以及命令的输出)。

我可能可以准备一个bash/shell脚本,该脚本将检查SQL语句的输出,然后是MONIT配置,该配置将在问题中向我发送警报。如果这样做,我将在此处发布它。我只是想知道是否已经有一个已知的解决方案。

我希望这可以与MySQL一起使用。

我打算使用这些SQL查询进行测试:

STOP SLAVE;
START SLAVE;

I use Monit 5.27.2 and MariaDB 10.5.15 on my Debian 11 servers.

My servers are set up in Multi-Source MariaDB Replication.

Sometimes, replication stops and I am not notified. I have not seen anywhere a prepared configuration for Monit to send such alerts.

The errors are visible with the following query:

SHOW SLAVE STATUS;

With those values particularly interesting:

slave_io_running and slave_sql_running values

last_error value

I have not found any way to use Monit to monitor directly the result of a SQL statement. However, it seems possible to monitor the return code of a command with versions before Monit 5.29.0 (and the output of a command after).

I can probably prepare a Bash/Shell script that will check the output of the SQL statement and then a Monit config that will send me an alert in case of issue. If I do, I will post this as an answer here. I was just wondering whether there was already a known solution to this.

I expect this to work with MySQL.

I intend to test this with those SQL queries:

STOP SLAVE;
START SLAVE;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风流物 2025-02-19 15:58:22

我按照我的期望工作。我在复制的所有服务器来源上都这样做。

在此处安装

是文件 monit_replication.sh

#!/bin/bash   
user="YOUR_USER"
password="YOUR_PASSWORD"

result=`echo "show slave status"|mysql -EsB --user="$user" --password="$password"`

contains_with_yes(){
        if echo "$1"|grep -i "$2"|grep -i "Yes" > /dev/null; then
                echo "$2 ok"
        else
                echo "$2 not ok"
                exit 1
        fi
}
 
contains_with_yes "$result" "Slave_IO_Running"
contains_with_yes "$result" "Slave_SQL_Running"
exit 0

使此可执行文件:

chmod 700 /YOUR_PATH_TO_THE_FILE/monit_replication.sh

添加到/etc/etc/monit/conf-enabled/mysql

 check program MySQL_replication with path "/YOUR_PATH_TO_THE_FILE/monit_replication.sh"
   every 120 cycles
   if status > 0 then alert
   group mysql 

testing

ran ran ran ran此sql:

STOP SLAVE;

重新启动monit:

/etc/init.d/monit restart

发现/var/log/monit.log

[2022-07-04T10:46:55+0000] error    : 'MySQL_replication' status failed (1) -- Slave_IO_Running not ok

接收到此电子邮件:

monit alert -- Status failed MySQL_replication

Status failed Service MySQL_replication

    Date:        Mon, 04 Jul 2022 10:46:55
    Action:      alert
    Host:        YOUR_HOST
    Description: status failed (1) -- Slave_IO_Running not ok

Your faithful employee,
Monit

这验证了测试。使用此SQL查询恢复复制:

START SLAVE;

其他解决方案

如果基于MONIT的任何简单解决方案可以提醒我Mariadb上的复制失败,我很乐意接受它作为问题的解决方案。

I got this to work as I expected. I did this on all servers sources of the replication.

Installing

Here is the file monit_replication.sh:

#!/bin/bash   
user="YOUR_USER"
password="YOUR_PASSWORD"

result=`echo "show slave status"|mysql -EsB --user="$user" --password="$password"`

contains_with_yes(){
        if echo "$1"|grep -i "$2"|grep -i "Yes" > /dev/null; then
                echo "$2 ok"
        else
                echo "$2 not ok"
                exit 1
        fi
}
 
contains_with_yes "$result" "Slave_IO_Running"
contains_with_yes "$result" "Slave_SQL_Running"
exit 0

Made this executable:

chmod 700 /YOUR_PATH_TO_THE_FILE/monit_replication.sh

Added to /etc/monit/conf-enabled/mysql:

 check program MySQL_replication with path "/YOUR_PATH_TO_THE_FILE/monit_replication.sh"
   every 120 cycles
   if status > 0 then alert
   group mysql 

Testing

Ran this SQL:

STOP SLAVE;

Restarted monit:

/etc/init.d/monit restart

Found in /var/log/monit.log:

[2022-07-04T10:46:55+0000] error    : 'MySQL_replication' status failed (1) -- Slave_IO_Running not ok

Received this email:

monit alert -- Status failed MySQL_replication

Status failed Service MySQL_replication

    Date:        Mon, 04 Jul 2022 10:46:55
    Action:      alert
    Host:        YOUR_HOST
    Description: status failed (1) -- Slave_IO_Running not ok

Your faithful employee,
Monit

This validates the test. Restoring replication with this SQL query:

START SLAVE;

Other solutions

If any simpler solution based on Monit can alert me of a replication failure on MariaDB, I would be happy to accept it as the solution to the question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文