galera mysql 机制_MySQL高可用架构之Galera Cluster

Galera Replication简介

Galera Repplication

Galera复制发生在事务提交时, 通过广播事务写集群应用

客户端直接连接到 Galera Cluster DMBS就和连接到原生的DBMS一样

wsrep API, 定义了Galera和DBMS之间的接口

Galera Cluster的特点

Galera是为MySQL提供的一个真正意义上的多主(M/M)集群, Galera Cluster是一个易于使用的高可用解决方案, 可提高系统的平均无故障时间, 并且提供数据的可靠性和集群的可扩展性

Galera Cluster的强大功能

同步复制

多主模型

可以在任意节点读写

自动控制各个节点的升级和降级

行级的并行控制

规模较小的客户端延迟

Galera-Cluster在网络拓扑所处的位置

1461850533386384.png

MariaDB-Galera-Server

好吧、这里和标题不符合, 因为我目前只有MariaDB-Galera的包, 所以有使用MariaDB-5.5来做实验了, 其实配置过程和MySQL-5.5并无区别

还有要注意的一点: Galera集群不需要提前配置MySQL复制, 并且也不需要基于MySQL复制

安装MariaDB-Galear-Server前, 不能安装MariaDB, 其实MariaDB-Gelera算是MariaDB的一个分支

环境部署

实验前准备:

1、HA环境首要条件:时间同步

三个节点添加对时脚本

[root@localhost ~]# crontab -l

*/5 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org

2、三个几点均配置MariaDB-Galera的本地yum仓库,我尝试使用mariadb官方提供的yum仓库,天朝的网会气死你

[root@localhost ~]# cat /etc/yum.repos.d/galera.repo

[galera]

name=galera

baseurl=file:///root/galera_cluster

gpgcheck=0

enable=1

3、yum安装,仅需安装MariaDB-Galera-server,其余的均会依赖安装

yum -y install Mariadb-Galera-server

1、查看galera所需调用的库的位置

rpm -ql galera | grep -i smm.so

/usr/lib64/galera/libgalera_smm.so

2、修改配置文件,三节点同步修改

729ee18bb9e4385786d0a50939dbd5db.png

启动服务

首先我们要在一个节点初始化集群

[root@node1 ~]# service mysql start --wsrep-new-cluster   #注意:这里是mysql不是mysqld

Starting MySQL....                                         [  OK  ]

依次在其他节点启动

[root@node2 ~]# service mysql start    #可能有点慢, 耐心等待

Starting MySQL............................SST in progress, setting sleep higher.

[root@node3 ~]# service mysql start    #可能有点慢, 耐心等待

Starting MySQL......SST in progress, setting sleep higher.

3、功能验证

1、节点1创建数据库,节点2 3均可正常查看

节点1:[root@localhost ~]# mysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.46-MariaDB-wsrep MariaDB Server, wsrep_25.12.r4f81026

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE mydb;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mydb |

| mysql |

| performance_schema |

| test |

+--------------------+

节点2 3:

[root@localhost ~]# mysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.46-MariaDB-wsrep MariaDB Server, wsrep_25.12.r4f81026

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mydb |

| mysql |

| performance_schema |

| test |

+--------------------+

5 rows in set (0.01 sec)

2、节点2数据库中创建表,节点1 2均可正常查看

节点2:

MariaDB [(none)]> use mydb;

Database changed

MariaDB [mydb]> CREATE TABLE tb1 (id int,name char(10));

Query OK, 0 rows affected (0.01 sec)

节点1 3:

MariaDB [(none)]> use mydb

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mydb]> SHOW TABLES

-> ;

+----------------+

| Tables_in_mydb |

+----------------+

| tb1 |

+----------------+

1 row in set (0.00 sec)

MariaDB [mydb]> DESC tb1;

+-------+----------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+----------+------+-----+---------+-------+

| id | int(11) | YES | | NULL | |

| name | char(10) | YES | | NULL | |

+-------+----------+------+-----+---------+-------+

2 rows in set (0.02 sec)

3、自增栏位的测试,每个几点会跳着进行自增,同时插入时例如1节点1 4 7;2节点2 5 8;三节点3 6 9。

节点1:

MariaDB [mydb]> CREATE TABLE tb2(id int UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,name char(30)

uery OK, 0 rows affected (0.01 sec)

MariaDB [mydb]> INSERT INTO tb2 (name) VALUES ('void'),('yao');

Query OK, 2 rows affected (0.01 sec)

Records: 2 Duplicates: 0 Warnings: 0

节点2:

MariaDB [mydb]> select * from tb2;

+----+------+

| id | name |

+----+------+

| 1 | void |

| 4 | yao |

+----+------+

2 rows in set (0.01 sec)

MariaDB [mydb]> INSERT INTO tb2 (name) VALUES ('amy'),('apple');

Query OK, 2 rows affected (0.00 sec)

Records: 2 Duplicates: 0 Warnings: 0

MariaDB [mydb]> select * from tb2;

+----+-------+

| id | name |

+----+-------+

| 1 | void |

| 4 | yao |

| 5 | amy |

| 8 | apple |

+----+-------+

4 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值