需要准备三个节点;
[root@master1 ~]# ntpdate s2c.time.edu.cn
[root@master2 ~]# ntpdate s2c.time.edu.cn
[root@master3 ~]# ntpdate s2c.time.edu.cn
配置yum源:
[root@master1 galera_cluster]# vim /etc/yum.repos.d/galera.repo
[galera]
name=Galera Cluster from MariaDB
baseurl=http://10.201.106.1:8080/galera_cluster/
enabled=1
gpgcheck=0
[root@master1 galera_cluster]# yum list | grep Gale
MariaDB-Galera-server.x86_64 5.5.46-1.el7.centos galera
MariaDB-Galera-test.x86_64 5.5.46-1.el7.centos galera
yum remove mariadb-server
yum remove mariadb
[root@master1 galera_cluster]# yum install MariaDB-Galera-server
[root@master2 galera_cluster]# yum install MariaDB-Galera-server
[root@master3 galera_cluster]# yum install MariaDB-Galera-server
[root@master1 ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so
[root@master1 ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so
[root@master1 ~]# vim /etc/my.cnf.d/server.cnf
[galera]
# Mandatory settings
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.201.106.131,10.201.106.132,10.201.106.133"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name=‘mycluster‘
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
[root@master1 ~]# scp /etc/my.cnf.d/server.cnf master2:/etc/my.cnf.d/
server.cnf 100% 1140 1.1KB/s 00:00
[root@master1 ~]# scp /etc/my.cnf.d/server.cnf master3:/etc/my.cnf.d/
server.cnf 100% 1140 1.1KB/s 00:00
[root@master1 ~]#
[root@master1 ~]# /etc/rc.d/init.d/mysql start --wsrep-new-cluster
Starting MySQL...... SUCCESS!
节点2,3启动
[root@master2 galera_cluster]# service mysql start
Starting MySQL.....SST in progress, setting sleep higher. SUCCESS!
[root@master2 galera_cluster]#
[root@master3 galera_cluster]# service mysql start
Starting MySQL.....SST in progress, setting sleep higher. SUCCESS!
[root@master3 galera_cluster]#
节点1
MariaDB [(none)]> CREATE DATABASE mydb;
节点3
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
节点2
MariaDB [mydb]> CREATE TABLE tb1(id int,name char(10));
节点1:
MariaDB [mydb]> DESC tb1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
节点1
MariaDB [mydb]> CREATE TABLE tb2(id int UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,name CHAR(30));
MariaDB [mydb]> INSERT INTO tb2 (name) VALUES(‘hi‘),(‘hello‘);
节点2
MariaDB [mydb]> SELECT * FROM tb2;
+----+-------+
| id | name |
+----+-------+
| 1 | hi |
| 4 | hello |
MariaDB [mydb]> INSERT INTO tb2(name) VALUES (‘to‘),(‘from‘);
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
MariaDB [mydb]> SELECT * FROM tb2;
+----+-------+
| id | name |
+----+-------+
| 1 | hi |
| 4 | hello |
| 5 | to |
| 8 | from |
+----+-------+
插入ID:找一个全局惟一ID生成器,可以专门找一台服务器生成ID,不做其他事情。
原文地址:http://blog.51cto.com/zhongle21/2089222