码迷,mamicode.com
首页 > 数据库 > 详细

Mariadb-Galera集群杂记

时间:2018-03-21 00:10:28      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:Mariadb Galera 集群 杂记

Galera Cluster

Galera Cluster

1、需要专门下载支持Galera-Cluster支持的mariadb分支

1.1

需要准备三个节点;

1.2 配置时间同步

[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 

2、清除之前的mariadb

yum remove mariadb-server
yum remove mariadb

3、安装

3.1 安装Galera

[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

3.2 查看安装生成文件

[root@master1 ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so

4、配置Galera-server

4.0

[root@master1 ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so

4.1 配置

[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

4.2 复制文件到节点2,3

[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 ~]# 

5、启动

5.1 初始化启动服务

[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]# 

5.2 测试创建

节点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    |       |
+-------+----------+------+-----+---------+-------+

6、演示同时插入数据

6.1

节点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,不做其他事情。

Mariadb-Galera集群杂记

标签:Mariadb Galera 集群 杂记

原文地址:http://blog.51cto.com/zhongle21/2089222

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!