在CentOS7上配置MariaDB-Galera-Cluster過程全記錄前端
MySQL or MariaDB Replication之Galera Clusternode
Galera Cluster:
另外一種多主模型機制,再也不經過mysql協議經過讀取二進制文件實現,而是經過wresp協議在全局實現底層數據片複製,任何一節點均可讀寫。
percona-cluster:
MariaDB-Cluster:mysql
優勢:網絡狀態可用狀況下,節點間基本實時數據同步,完勝MHA的日誌可能不一樣步;sql
特色:分擔讀操做,前端不必讀寫分離、只需作負載均衡便可。編程
條件:一、至少要三個節點;二、不能安裝mariadb-server。vim
配置文件參數解釋:
# 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 #工做時監聽的地址;centos
首次啓動時,須要初始化集羣,在其中任意節點上執行以下命令:
/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)ide
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:# mysqlMariaDB [(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不連續問題的解決,可在編程時調用工具生成器。