我使用3 Galera cluster
设置了docker containers
3个节点。需要在数据从donor
节点同步到其他节点时,根据同步节点上的wsrep_notify_cmd
触发器或wsrep_sst_method
触发器,还需要填充数据该节点上相应的Redis队列。
问题是这两个触发器仅在我启动集群时调用。有一个日志说当一个节点加入集群时调用了这两个触发器。但是当我尝试修改架构或在一个节点中执行CUD操作时,触发器不会在其他节点上触发。
我不知道我是否错误地进行了配置,或者这不是这些触发器的工作方式。
以下是我用来使群集正常工作的文件
搬运工-compose.yml
version: '3'
services:
node1:
build: ./galera/
image: galera_mariadb:latest
container_name: "galera_cluster_node1"
hostname: node1
ports:
- 13306:3306
networks:
- galera_cluster
volumes:
- ./galera/conf.d/galera.cnf:/etc/mysql/conf.d/galera.cnf
- /var/data/galera/mysql/node1:/var/lib/mysql/
# ./galera/scripts contains the bash script which is executed by wsrep_notify_cmd trigger
- ./galera/scripts/:/etc/mysql/scripts/
environment:
- MYSQL_ROOT_PASSWORD=123
- REPLICATION_PASSWORD=123
- MYSQL_DATABASE=test_db
- MYSQL_USER=maria
- MYSQL_PASSWORD=123
- GALERA=On
- NODE_NAME=node1
- CLUSTER_NAME=maria_cluster
- CLUSTER_ADDRESS=gcomm://
command: --wsrep-new-cluster
node2:
image: galera_mariadb:latest
container_name: "galera_cluster_node2"
hostname: node2
links:
- node1
ports:
- 23306:3306
networks:
- galera_cluster
volumes:
- ./galera/conf.d/galera.cnf:/etc/mysql/conf.d/galera.cnf
- /var/data/galera/mysql/node2:/var/lib/mysql/
- ./galera/scripts/:/etc/mysql/scripts/
environment:
- REPLICATION_PASSWORD=123
- GALERA=On
- NODE_NAME=node2
- CLUSTER_NAME=maria_cluster
- CLUSTER_ADDRESS=gcomm://node1
node3:
image: galera_mariadb:latest
container_name: "galera_cluster_node3"
hostname: node3
links:
- node1
ports:
- 33306:3306
networks:
- galera_cluster
volumes:
- ./galera/conf.d/galera.cnf:/etc/mysql/conf.d/galera.cnf
- /var/data/galera/mysql/node3:/var/lib/mysql/
- ./galera/scripts/:/etc/mysql/scripts/
environment:
- REPLICATION_PASSWORD=123
- GALERA=On
- NODE_NAME=node3
- CLUSTER_NAME=maria_cluster
- CLUSTER_ADDRESS=gcomm://node1
networks:
galera_cluster:
driver: bridge
用于构建3个galera集群节点的Dockerfile
# Galera Cluster Dockerfile
FROM hauptmedia/mariadb:10.1
RUN apt-get update \
&& apt-get -y install \
vim \
python \
redis-tools
# remove the default galera.cnf in the original image
RUN rm -rf /etc/mysql/conf.d/galera.cnf
# add the custom galera.cnf
COPY ./conf.d/galera.cnf /etc/mysql/conf.d/galera.cnf
# grant access and execution right
RUN chmod 755 /etc/mysql/conf.d/galera.cnf
galera.cnf档案
[galera]
wsrep_on=ON
# wsrep only supports binlog_format='ROW' and storage-engine=innodb
binlog_format=row
default_storage_engine=InnoDB
# to avoid issues with 'bulk mode inserts' using autoinc
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# relax flushing logs when running in galera mode
innodb_flush_log_at_trx_commit=0
sync_binlog=0
# Query Cache is supported since version 10.0.14 with wsrep
query_cache_size=8000000
query_cache_type=1
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# use the built-in method to manage State Snapshot Transfers
# we can customize this script to perform a specific logic
wsrep_sst_method=xtrabackup-v2
# This bash is volumed from the host which is used to populate synchronized data to the Redis queue
wsrep_notify_cmd=/etc/mysql/scripts/wsrep_notify.sh
# force transaction level to be read commited
#transaction-isolation = READ-COMMITTED
wsrep_notify.sh
#!/bin/sh -eu
wsrep_log()
{
# echo everything to stderr so that it gets into common error log
# deliberately made to look different from the rest of the log
local readonly tst="$(date +%Y%m%d\ %H:%M:%S.%N | cut -b -21)"
echo "WSREP_SST: $* ($tst)" >&2
}
wsrep_log_info()
{
wsrep_log "[INFO] $*"
}
STATUS=""
CLUSTER_UUID=""
PRIMARY=""
MEMBERS=""
INDEX=""
while [ $# -gt 0 ]
do
case $1 in
--status)
STATUS=$2
shift
;;
--uuid)
CLUSTER_UUID=$2
shift
;;
--primary)
PRIMARY=$2
shift
;;
--index)
INDEX=$2
shift
;;
--members)
MEMBERS=$2
shift
;;
esac
shift
done
wsrep_log_info "--status $STATUS --uuid $CLUSTER_UUID --primary $PRIMARY --members $MEMBERS --index $INDEX"
以下是3个节点的日志文件
node1:
https://drive.google.com/file/d/0B2q2F62RQxVjbkRaQlFrV2NyYnc/view?usp=sharing
node2:
https://drive.google.com/file/d/0B2q2F62RQxVjX3hYZHBpQ2FRV0U/view?usp=sharing
node3:
https://drive.google.com/file/d/0B2q2F62RQxVjelZHQTN3ZDRNZ0k/view?usp=sharing
我一直在谷歌搜索这个问题,但没有运气。我希望任何有Galera Cluster设置经验的人都可以帮我解决这个问题。或者有另一种方法来解决要求请告诉我。非常感谢
答案 0 :(得分:1)
wsrep_notify_cmd
定义节点在集群成员资格或运行时运行的命令 节点状态发生变化。
因此,如果脚本将其在下面列表中描述的状态更改为任何其他状态,则将在节点上启动脚本:
可能的状态是:
未定义节点刚启动且未连接到任何主要组件。
Joiner 节点已连接到主要组件,现在正在接收状态快照。
Donor 节点已连接到主要组件,现在正在发送状态快照。
已加入该节点已处于完整状态,现在正在赶上群集。
已同步节点已与群集同步。
错误(如果可用>)节点处于错误状态。
您会看到脚本在节点启动时发出通知并更改其状态。当数据仅在galera集群节点之间同步时,它不会通知。