当前位置:网站首页>MariaDB的Galera集群-双主双活安装设置
MariaDB的Galera集群-双主双活安装设置
2022-07-04 22:44:00 【左明水】
MariaDB的Galera集群-双主双活安装设置
一、Galera原理
1、简介
Galera Cluster for MySQL是一套基于同步复制的多主MySQL集群解决方案,使用简单,没有单点故障,可用性高,能很好保证业务不断增长时数据的安全和随时的扩展。
2、Galera多主模型的主要特点
基于同步复制
多主服务器的拓扑结构`
可以在任意节点上进行读写
自动剔除故障节点
自动加入新节点
真正行级别的并发复制
客户端连接跟操作单台MySQL数据库的体验一致
3、安装Galera的时候的注意事项
Galera集群是基于wsrep协议进行的,所以不需要提前配置MySQL异步复制。
不能同时安装MariaDB-Server和Galera-Server。
使用Galera多主模型至少需要至少三个节点。
(因为安装Galera-server的时候会替换掉mariadb-server;三个节点是为了要使用投票功能仲裁出master)
4、工作原理
Mariadb 可以看做是常见的数据库,负责连接应用(web, API 等);单纯的 mariadb 无法实现多个主服务器数据同步;多台数据库中数据同步由 wsrep 接口实现;最终目标,实现多个 MySQL 同时读写。
wsrep API
wsrep API 是一种数据库插件接口,比较类似一种应用程序,主要针对写复制
该程序主要用于定义应用程序如何调用复制库实现回写
wsrep API 由支持改库的应用程序动态装载
全局事务ID(GTID)
wsrep API 描述下面复制模型,一个应用程序,如数据库当前的一个对象,当前被客户端修改,对象改变导致事务产生一系列的原子性改变, 在集群中所有的节点都具备相同的对象,并由同步复制应用都各自节点,按照相同的顺序产生相同变化从而实现数据同步
到最后,wsrep API 将会分配一个全局事务ID 该 ID 具有下面功能
标识对象的改变
标识对象自身 ID 最后状态(正常情况下,ID 是连续不中断的)
GTID 包含
一个 UUID 作为对象标识及经历改变的序号,序号会发生连续的改变。
GTID 允许比较应用程序状态,建立对象改变的顺序,决定对象的变化是否需要更新 GTID
通常 GTID 会被记录成下面格式
45eec521-2f34-11e0-0800-2a36050b826b:94530586304
二、搭建yum源,配置yum配置文件
0、操作环境
本文使用的系统版本为CentOS7.3
注意:本文关闭了selinux,以及iptables。
1、使用外网Yum 源如下:若是没有恰好的版本yum安装时会出现对已经安装的数据库相关软件进行相应的小版本升级.
vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=0
2、若是不能连接外网,需根据数据库本身版本在网站上下载与之匹配的软件包,搭建本地yum源
a、对应地址:
http://yum.mariadb.org/
b、开启http服务,创建对应的目录:
mkdir -v /var/www/html/mariadb/
mkdir -v /var/www/html/mariadb/repodata
mkdir -v /var/www/html/mariadb/rpms
ll /var/www/html/mariadb/
c、需要下载的内容与Internet上的对应:
d、rpm软件的对比
三、安装Galera软件
yum --enablerepo=mariadb -y install MariaDB-Galera-server
yum -y install rsync
1、yum安装时会根据软件的版本寻找对应的依赖软件版本
例如:
Install 3 Packages (+3 Dependent packages)
MariaDB-5.5.61-centos73-x86_64-client.rpm
MariaDB-5.5.61-centos73-x86_64-common.rpm
MariaDB-5.5.61-centos73-x86_64-shared.rpm
galera-25.3.23-1.rhel7.el7.centos.x86_64.rpm
MariaDB-Galera-server-5.5.61-centos73-x86_64-server.rpm
2、可能导致的结果是会对数据库的相关软件有一定的小版本升级
四、Mariadb 主配置文件
1、编辑配合文件:
a、修改配置文件时,先对配置文件进行备份
cp /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.bak
b、 原始配置文件部分内容截图如下
c、 编辑配置以下内容
vim /etc/my.cnf.d/server.cnf
:set nu
19行:指定数据库间数据同步由谁来完成数据的复制
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
20行:指定集群中所有数据库节点,使用gcomm协议
wsrep_cluster_address=“gcomm:// 192.168.244.163, 192.168.244.169”
21行:指的是联机重做日志,直接解注释即可
binlog_format=row
22 行:指定所使用的数据库引擎
default_storage_engine=InnoDB
23 行:
innodb_autoinc_lock_mode=2
24 行:本台机器所有网卡
bind-address=0.0.0.0
以下3个配置是新添加的内容!!
指定集群名称:
wsrep_cluster_name=“test_cluster”
wsrep_node_address=“192.168.244.163” (指定 wsrep 节点地址,这里指当前节点)
wsrep_sst_method=rsync(复制方式为rsync,要确保安装了rsync)
d、 然后复制到其他节点
把对应真实节点的wsrep_node_address地址改为自身IP地址
cp /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.bak
scp 192.168.244.163:/etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf
e、最终配置文件的配置项
14 #
15 # * Galera-related settings
16 #
17 [galera]
18 # Mandatory settings
19 wsrep_provider=/usr/lib64/galera/libgalera_smm.so
20 wsrep_cluster_address=“gcomm://192.168.244.163,192.168.244.169”
21 binlog_format=row
22 default_storage_engine=InnoDB
23 innodb_autoinc_lock_mode=2
24 bind-address=0.0.0.0
25 #
26 # Optional setting
27 #wsrep_slave_threads=1
28 #innodb_flush_log_at_trx_commit=0
29
30 # this is only for embedded server
31
32 #added the parts
33 wsrep_cluster_name=“test_cluster”
34 wsrep_node_address=“192.168.244.163”
35 wsrep_sst_method=rsync
f、最终配置文件的配置项截图
五、在各个节点启动(集群)
/etc/rc.d/init.d/mysql bootstrap
启动效果如下图所示:
/etc/rc.d/init.d/mysql status bootstrap
查看启动状态如下图:
或查看端口:
netstat -ntl
六、配置MySQL的基本设置即MySQL初始化
若是初次安装需要在每一个数据库节点上进行初始化操作;
若是已经由数据库在使用中了,此数据库节点无需此操作。
mysql_secure_installation
设置root用户的密码,这里自己指定,密码一定要记住,后期要使用,这里设置成root
七、节点上,启动MySQL
systemctl start mysql
systemctl status mysql
八、验证数据库集群是否搭建成功
1、登录数据库
mysql -u root –p
2、在数据库中查询关于数据库集群节点的信息
show status like ‘wsrep_%’;
正常的集群显示结果:
wsrep_connected = on 链接已开启
wsrep_cluster_size =2 集群中节点的数量
wsrep_incoming_addresses=ip1,1p2
若是没有,就重启各个节点的集群服务和MySQL
直接停止集群:
/etc/rc.d/init.d/mysql stop bootstrap
然后查看数据状态:
systemctl status mysql.service
再分别在各自节点上启动集群,待集群启动成功后,再次再各自的节点上启动数据库
进入数据库查看集群详情,若是没有加入集群中,再次restart数据库,再次查看。
在此处,直接重启数据库:(本次解决方式)
systemctl restart mysql.service
再次查看数据库集群结果:
3、测试数据库集群的双主双活功能
a.创建数据库并在里面建立一个新表。
create database wsrep_test;
use wsrep_test;
create table wsrep_test (id int auto_increment not null primary key,name varchar(30) not null);
desc wsrep_test;
创建一个叫wsrep_test的表,里面有两个字段,一个是id,一个是name。其中id字段设置为自动增长。
b.插入数据
insert into wsrep_test.wsrep_test (name) values (‘node1’);
insert into wsrep_test.wsrep_test (name) values (‘node2’);
insert into wsrep_test.wsrep_test (name) values (‘node3’);
insert into wsrep_test.wsrep_test (name) values (‘node4’);
insert into wsrep_test.wsrep_test (name) values (‘node5’);
select * from wsrep_test.wsrep_test;
操作效果图:
插入数据之前,所有数据库节点的表数据:
如上图显示的过程,则表示mariadb的galera集群双主双活安装设置成功!
最终效果是在任何一个节点上面插入的数据,最后在每一个节点中都可以查询得到。而且多主模型中,通过设置id自动增长的步长,避免多个节点中自动增长的id号冲突。
注意事项:
启动时先把节点的所有集群全部启动,之后再启动MySQL数据.
集群软件启动后,检查状态,成功后就可可以了.
若是没有集群节点,MySQL数据库服务需要重新启动
详情请见,公众号
边栏推荐
- Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
- Redis入门完整教程:键管理
- 实战模拟│JWT 登录认证
- Summary of wechat applet display style knowledge points
- 【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
- A complete tutorial for getting started with redis: getting to know redis for the first time
- Excel 快捷键-随时补充
- Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
- The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
- Mongodb aggregation operation summary
猜你喜欢

Hit the core in the advanced area of misc in the attack and defense world

Redis入门完整教程:Bitmaps

Attack and defense world misc advanced area Hong

Three stage operations in the attack and defense drill of the blue team

A complete tutorial for getting started with redis: hyperloglog

Redis入门完整教程:GEO

Qt加法计算器(简单案例)

【机器学习】手写数字识别

D3.js+Three. JS data visualization 3D Earth JS special effect

colResizable. JS auto adjust table width plug-in
随机推荐
小程序vant tab组件解决文字过多显示不全的问题
金融市场,资产管理与投资基金
MySQL Architecture - user rights and management
SPH中的粒子初始排列问题(两张图解决)
Async await used in map
Redis: redis configuration file related configuration and redis persistence
UML图记忆技巧
Redis入门完整教程:Redis使用场景
One of the commonly used technical indicators, reading boll Bollinger line indicators
The overview and definition of clusters can be seen at a glance
Redis getting started complete tutorial: Geo
Redis入门完整教程:API的理解和使用
Pagoda 7.9.2 pagoda control panel bypasses mobile phone binding authentication bypasses official authentication
Notepad++ -- editing skills
Attack and defense world misc advanced area can_ has_ stdio?
On-off and on-off of quality system construction
Redis getting started complete tutorial: publish and subscribe
【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
Redis入门完整教程:有序集合详解
Serial port data frame