在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過程全記錄