gpt4 book ai didi

mysql - Galera集群节点不触发wsrep_notify_cmd和wsrep_sst_method

转载 作者:行者123 更新时间:2023-11-29 05:59:02 33 4
gpt4 key购买 nike

我确实使用 3 个 docker 容器 设置了具有 3 个节点的 Galera 集群。有一个要求,当数据从donor节点同步到其他节点时,基于同步时的wsrep_notify_cmd触发器或wsrep_sst_method触发器节点的数据也需要填充到该节点对应的Redis队列中。问题是这 2 个触发器仅在我启动集群时调用。有日志说当一个节点加入集群时调用了这 2 个触发器。但是,当我尝试在一个节点中修改架构或执行 CUD 操作时,触发器不会在其他节点上触发。我不知道是我配置不正确,还是这些触发器的工作方式不对。

下面是我用来使集群正常工作的文件

  • docker-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个节点的日志文件

节点 1:

https://drive.google.com/file/d/0B2q2F62RQxVjbkRaQlFrV2NyYnc/view?usp=sharing

节点2:

https://drive.google.com/file/d/0B2q2F62RQxVjX3hYZHBpQ2FRV0U/view?usp=sharing

节点 3:

https://drive.google.com/file/d/0B2q2F62RQxVjelZHQTN3ZDRNZ0k/view?usp=sharing

我一直在用谷歌搜索这个问题,但没有成功。我希望任何有 Galera Cluster 设置经验的人都可以帮助我解决这个问题。或者有另一种方法来解决需求请告诉我。非常感谢

最佳答案

wsrep_notify_cmd

Defines the command the node runs whenever cluster membership or the state of the node changes.

因此,如果节点将下面列表中描述的状态更改为任何其他状态,脚本将在节点上启动:

The possible statuses are:

Undefined The node has just started up and is not connected to any Primary Component.

Joiner The node is connected to a primary component and now is receiving state snapshot.

Donor The node is connected to primary component and now is sending state snapshot.

Joined The node has a complete state and now is catching up with the cluster.

Synced The node has synchronized itself with the cluster.

Error( if available>) The node is in an error state.

您会看到脚本在节点启动和更改其状态时发出通知。当数据刚刚在 galera 集群节点之间同步时,它不会通知。

关于mysql - Galera集群节点不触发wsrep_notify_cmd和wsrep_sst_method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46611987/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com