美文网首页我爱编程
2018-08-09 mariadb galera cluste

2018-08-09 mariadb galera cluste

作者: tomatostranger | 来源:发表于2018-08-09 17:48 被阅读0次

    mariadb install

    利用 respository tool 获取需要的 mariadb 版本对应的仓库,并完成安装

    https://downloads.mariadb.org/mariadb/repositories/

    sudo apt-get install software-properties-common 
    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
    sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.1/ubuntu trusty main'
    
    sudo apt-get update
    sudo apt-get install mariadb-server
    

    galera cluster setup

    创建单点 cluster

    可以通过以下命令新创建一个 galera cluster 集群

    mysqld --wsrep-new-cluster

    通过 mysql 命令来查看当前集群的状态:

    show status like 'wsrep_%';

    显示集群的 wsrep_cluster_size = 0, wsrep_cluster_status = DISCONNECTED,表明node并未加入到 cluster 中。这是因为,需要在修改 mariadb 配置,来开启 wsrep

    [galera]
    # Mandatory settings
    wsrep_on=ON
    wsrep_provider=/usr/lib/galera/libgalera_smm.so
    wsrep_cluster_address="gcomm://10.240.140.2,10.240.140.3"
    binlog_format=row
    #default_storage_engine=InnoDB
    #innodb_autoinc_lock_mode=2
    

    修改后重启,查看状态

    MariaDB [(none)]> show status like 'wsrep_%';
    +------------------------------+--------------------------------------+
    | Variable_name                | Value                                |
    +------------------------------+--------------------------------------+
    | wsrep_apply_oooe             | 0.000000                             |
    | wsrep_apply_oool             | 0.000000                             |
    | wsrep_apply_window           | 0.000000                             |
    | wsrep_causal_reads           | 0                                    |
    | wsrep_cert_deps_distance     | 0.000000                             |
    | wsrep_cert_index_size        | 0                                    |
    | wsrep_cert_interval          | 0.000000                             |
    | wsrep_cluster_conf_id        | 5                                    |
    | wsrep_cluster_size           | 1                                    |
    | wsrep_cluster_state_uuid     | 11204c5f-9ba9-11e8-a8dc-2acc1cebe53a |
    | wsrep_cluster_status         | Primary                              |
    | wsrep_commit_oooe            | 0.000000                             |
    | wsrep_commit_oool            | 0.000000                             |
    | wsrep_commit_window          | 0.000000                             |
    | wsrep_connected              | ON                                   |
    | wsrep_desync_count           | 0                                    |
    ...
    

    添加 node

    和上述类似,需要修改 mariadb 配置

    [galera]
    # Mandatory settings
    wsrep_on=ON
    wsrep_provider=/usr/lib/galera/libgalera_smm.so
    wsrep_cluster_address="gcomm://10.240.140.2,10.240.140.3"
    binlog_format=row
    #default_storage_engine=InnoDB
    #innodb_autoinc_lock_mode=2
    

    再将该新节点加入到现有的 cluster 中

    mysqld --wsrep_cluster_address=gcomm://10.240.140.2

    重启 node,添加成功后,输入命令查看:

    MariaDB [(none)]> show status like 'wsrep_%';
    +------------------------------+---------------------------------------+
    | Variable_name                | Value                                 |
    +------------------------------+---------------------------------------+
    | wsrep_apply_oooe             | 0.000000                              |
    | wsrep_apply_oool             | 0.000000                              |
    | wsrep_apply_window           | 0.000000                              |
    | wsrep_causal_reads           | 0                                     |
    | wsrep_cert_deps_distance     | 0.000000                              |
    | wsrep_cert_index_size        | 0                                     |
    | wsrep_cert_interval          | 0.000000                              |
    | wsrep_cluster_conf_id        | 2                                     |
    | wsrep_cluster_size           | 2                                     |
    | wsrep_cluster_state_uuid     | 846ec2c8-9bb5-11e8-95c5-12bbe81db3ef  |
    | wsrep_cluster_status         | Primary                               |
    | wsrep_commit_oooe            | 0.000000                              |
    | wsrep_commit_oool            | 0.000000                              |
    | wsrep_commit_window          | 0.000000                              |
    | wsrep_connected              | ON                                    |
    | wsrep_desync_count           | 0                                     |
    ...
    

    注意到 wsrep_cluster_size = 2 表明该 cluster 中当前有 2 个节点。可以通过相同的方式添加新节点保证 2n+1(n=1, 2, 3...) 个节点

    测试

    通过在任一 node 上进行数据库操作,观察其他 node 的同步情况。如果同步成功,表明创建mariadb galera cluster 成功。

    参考链接:

    1. https://mariadb.com/kb/en/library/getting-started-with-mariadb-galera-cluster/
    2. https://serverfault.com/questions/744040/unable-to-run-a-mariadb-10-1-galera-cluster
    3. http://galeracluster.com/documentation-webpages/monitoringthecluster.html

    相关文章

      网友评论

        本文标题:2018-08-09 mariadb galera cluste

        本文链接:https://www.haomeiwen.com/subject/tzzqbftx.html