2017-10-06 251 views
0

我確實使用3 docker containers設置了帶有3個節點的Galera cluster。要求當數據從donor節點同步到其他節點時,基於同步節點上的觸發器wsrep_notify_cmdwsrep_sst_method,還需要將數據填充到該節點上相應的Redis隊列。 問題是隻有在啓動集羣時纔會調用這2個觸發器。有日誌說,當一個節點加入羣集時,這兩個觸發器被調用。但是,當我試圖修改模式或在一個節點上執行CUD操作時,觸發器未在其他節點上觸發。 我不知道如果我做錯了配置,或者它不是這些觸發器的工作方式。Galera羣集節點不會觸發wsrep_notify_cmd和wsrep_sst_method

下面是我使用,使集羣工作文件

  • 泊塢窗,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 
    
  • 的Dockerfile用於建立3加萊拉羣集節點

    # 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集羣設置人員都能幫助我解決問題。或者有另一種方法來解決這個需求請給我看看。非常感謝

回答

0

wsrep_notify_cmd

定義命令的節點運行每當集羣成員或節點的變化 狀態。

所以,腳本會在節點啓動,如果它改變其狀態在下面的列表中所描述的任何其他狀態:

可能的狀態是:

未定義的節點剛啓動並沒有連接到任何主要組件。

細木工節點連接到主要組件,現在正在接收狀態快照。

捐助者節點連接到主要組件,現在正在發送狀態快照。

加入該節點具有完整狀態,現在正在趕上集羣。

同步節點已與羣集同步。

錯誤(如果可用>)節點處於錯誤狀態。

您會看到腳本通知節點何時啓動並更改其狀態。它不會通知數據何時在加萊拉羣集節點之間進行同步。

+0

在這種情況下,我們應該使用哪個狀態變量來檢查數據是否在一個節點上同步?我想知道如果我使用https://mariadb.com/kb/en/library/galera-cluster-status-variables/#wsrep_local_commits是正確的。 – tilonthuduc

+0

我也考慮觸發器,我將爲那些將數據填充到Redis的表創建Insert/Update/Delete觸發器。這是一個好方法,是否有任何性能問題需要注意? – tilonthuduc