在CentOS7上配置MariaDB-Galera-Cluster过程全记录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CentOS7上配置MariaDB-Galera-Cluster过程全记录相关的知识,希望对你有一定的参考价值。

在CentOS7上配置MariaDB-Galera-Cluster过程全记录

mysql or MariaDB Replication之Galera Cluster

Galera Cluster:
另一种多主模型机制,不再通过mysql协议通过读取二进制文件实现,而是通过wresp协议在全局实现底层数据片复制,任何一节点都可读写。
percona-cluster:
MariaDB-Cluster:

优点:网络状态可用情况下,节点间基本实时数据同步,完胜MHA的日志可能不同步;

特点:分担读操作,前端没必要读写分离、只需做负载均衡即可。

条件:1、至少要三个节点;2、不能安装mariadb-server。

配置文件参数解释:
# cat /etc/my.cnf.d/server.cnf
[galera]
# Mandatory settings
#wsrep_provider= "/usr/lib64/galera/libgalera_smm.so" #插件;
#wsrep_cluster_address="gcomm://node_ip_address1,node_ip_address2,node_ip_address3"
#wsrep_cluster_name=galera_cluster
#wsrep_node_address= #节点地址,可省略;
#wsrep_node_name= #节点名,可省略;
#binlog_format=row #二进制日志格式;
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2 #锁格式;
#bind-address=0.0.0.0 #工作时监听的地址;

首次启动时,需要初始化集群,在其中任意节点上执行如下命令:
/etc/init.d/mysql start --wsrep-new-cluster [--wsrep_cluster_name=galera_cluster]

而后正常启动其他节点:
/etc/init.d/mysql start


配置过程:
OS:
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

Galera:
# rpm -qa MariaDB-Galera-server
MariaDB-Galera-server-5.5.57-1.el7.centos.x86_64

IP:
Node1 IP:192.168.1.77
Node2 IP:192.168.1.78
Node3 IP:192.168.1.79

Node1:
# vim /etc/yum.repos.d/galera.repo
[galera]
name=galera
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-5.5.57/yum/centos7-amd64/
gpgcheck=0
# scp /etc/yum.repos.d/galera.repo 192.168.1.78:/etc/yum.repos.d/
# scp /etc/yum.repos.d/galera.repo 192.168.1.79:/etc/yum.repos.d/

Node1-3:
# yum isntall MariaDB-Galera-server -y

Node1:
# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so
# vim /etc/my.cnf.d/server.cnf
[galera]
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.1.77,192.168.1.78,192.168.1.79"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="galera_cluster"
# scp /etc/my.cnf.d/server.cnf 192.168.1.78:/etc/my.cnf.d/server.cnf
# scp /etc/my.cnf.d/server.cnf 192.168.1.79:/etc/my.cnf.d/server.cnf
# /etc/init.d/mysql start --wsrep-new-cluster

Node2-3:
# /etc/init.d/mysql start

Node1:
# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.57-MariaDB-wsrep MariaDB Server, wsrep_25.21.r9949137
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [galeradb]> show status like ‘wsrep_%‘;
MariaDB [(none)]>create database galeradb;
Query OK, 1 row affected (0.63 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| galeradb |
| hellodb |
| masterdb |
| mysql |
| performance_schema |
| test |
+--------------------+
MariaDB [(none)]> use galeradb;
MariaDB [galeradb]> create table tb1 (id int unsigned auto_increment not null primary key,name char(30));
MariaDB [galeradb]> insert into tb1 (name) values (‘Guo Jing‘),(‘Huang Rong‘);
MariaDB [galeradb]> select * from tb1;
+----+------------+
| id | name |
+----+------------+
| 4 | Guo Jing |
| 7 | Huang Rong |
+----+------------+

Node2:
# mysql
MariaDB [(none)]> show databases;
MariaDB [(none)]> use galeradb;
MariaDB [galeradb]> insert into tb1 (name) values (‘Yang Kang‘),(‘Mu Niangci‘);
MariaDB [galeradb]> select * from tb1;
+----+------------+
| id | name |
+----+------------+
| 4 | Guo Jing |
| 7 | Huang Rong |
| 11 | Yang Kang |
| 14 | Mu Niangci |
+----+------------+
//解决方案:对于ID不连续问题的解决,可在编程时调用工具生成器。































































































以上是关于在CentOS7上配置MariaDB-Galera-Cluster过程全记录的主要内容,如果未能解决你的问题,请参考以下文章

实战mariadb-galera集群架构

如何在centos7上配置hadoop

在CentOS7上配置iSCSI

在Centos7.6上配置mysql主从

在Centos7.6上配置mysql主从

CentOS7上安装并配置KVM,以及通过KVM安装CentOS系统