From bb3b511ef55424b492a042a6bfc5e9252adc14e6 Mon Sep 17 00:00:00 2001 From: ghb <3779166520@qq.com> Date: Tue, 23 Jul 2024 09:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 16 ++++++++++++++++ cluster.service | 14 ++++++++++++++ example.conf | 10 ++++++---- notify.py | 3 ++- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 Readme.md create mode 100644 cluster.service diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..df16260 --- /dev/null +++ b/Readme.md @@ -0,0 +1,16 @@ +## Galera Cluster 数据库集群监控服务 + +#### ClusterMonitory.py + 该脚本主要功能是监控本地数据库集群状态 + 在集群模式下监控集群状态,当本机离线后切换数据库为单机模式 + 切换为单机模式后尝试连接集群其它设备,网络恢复后重新切换为集群模式 + 恢复为集群模式后过滤slow_query.log,重新执行增删改操作恢复单机模式下的数据 + 模式切换成功会发送请求到rms后台接口,提示前端已完成切换 + + 该脚本需要部署成服务,保证自启动(cluster.service) + 数据库连接信息修改需同步修改脚本内的信息 + +#### notify.py + 该脚本用于接受集群状态变更的信息,转发给rms后台接口 + 建议部署路径:/var/lib/mysql/notify.py + 需修改该脚本权限 \ No newline at end of file diff --git a/cluster.service b/cluster.service new file mode 100644 index 0000000..5f47215 --- /dev/null +++ b/cluster.service @@ -0,0 +1,14 @@ +[Unit] +Description=Mysql Cluster Montior Service +After=network.target + +[Service] +Type=simple +WorkingDirectory=/home/yanei/cluster +ExecStart=/home/yanei/miniconda3/bin/python ClusterMonitor.py +User=root +Group=root +PermissionsStartOnly=true + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/example.conf b/example.conf index 8aae679..38b86b1 100644 --- a/example.conf +++ b/example.conf @@ -32,7 +32,7 @@ pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log - +log_bin = on bind-address = 0.0.0.0 port = 3344 @@ -44,9 +44,11 @@ innodb_autoinc_lock_mode=2 wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so -wsrep_cluster_name="YaneiGaleraCluster" -wsrep_cluster_address="gcomm://192.168.100.129,129.168.100.128" -wsrep_node_name="node_130" +wsrep_cluster_name="cluster" +wsrep_cluster_address="gcomm://192.168.100.129,192.168.100.128" +wsrep_node_name="node_192_168_100_130" wsrep_node_address="192.168.100.130" wsrep_sst_method=rsync wsrep_sst_auth=root:yanei!23 +wsrep_notify_cmd="/var/lib/mysql/notify.py" + diff --git a/notify.py b/notify.py index e1c5392..2862afa 100644 --- a/notify.py +++ b/notify.py @@ -1,8 +1,9 @@ +#!/usr/bin/python3 import sys from urllib.parse import urlencode import urllib.request -API_URL = "http://127.0.0.1:8000/api/rms/sync/db_status" +API_URL = "http://127.0.0.1:8000/api/rms/cab/sync/db_status" def main():