文档章节

Centos7.2下安装mysql-group-replication数据库集群

日落北极
 日落北极
发布于 2018/06/14 16:59
字数 1146
阅读 35
收藏 2

系统版本:Centos7.2 x64

数据库版本:mysql5.7.17

1.首先安装环境:

yum -y install gcc gcc-c++ libaio-devel boost-devel autoconf automake zlib-devel libxml2-devel ncurses-devel libgcrypt-devel libtool-devel openssl-devel bison-devel unzip numactl-devel

2.关闭selinux和防火墙

setenforce 0
systemctl stop firewalld
systemctl disabled firewalld

3.下载mysql安装包

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar

解压:

tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar

tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

将解压后的文件夹移动到/user/local并且修改为mysql5.7

mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql5.7


配置环境变量
mysql-5.7.17-linux-glibc2.5-x86_64.tar

source /etc/profile

5.创建data目录和conf文件

进入mysql5.7

mkdir data/3306 data/3307 data/3308

mkdir conf

分别创建3306.cnf 3307.cnf 3308.cnf

6.实例化并且启动mysql

实例化:

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3306

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3307

/usr/local/mysql5.7/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql5.7 --datadir=/usr/local/mysql5.7/data/3308

会报一些警告信息:

2018-06-14T03:17:32.915314Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-14T03:17:33.980961Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-06-14T03:17:34.192176Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-06-14T03:17:34.256360Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7b29387c-6f81-11e8-abac-00163e06e59d.
2018-06-14T03:17:34.259013Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-06-14T03:17:34.259401Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

分别启动三个实例:

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3306.cnf &

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3307.cnf &

/usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3308.cnf &

查看mysql三个实例是否启动成功

[root@iZm5e7kkxs23uutsa9dbl5Z mysql5.7]# ps -ef | grep mysqld
root     22236  9200  1 11:18 pts/0    00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3306.cnf
root     22265  9200  2 11:18 pts/0    00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3307.cnf
root     22294  9200  3 11:18 pts/0    00:00:00 /usr/local/mysql5.7/bin/mysqld --defaults-file=/usr/local/mysql5.7/conf/3308.cnf
root     22326  9200  0 11:18 pts/0    00:00:00 grep --color=auto mysqld

说明启动成功

4.数据库相关配置

进入3306节点,作为主节点

执行以下操作:

mysql -S /usr/local/mysql5.7/data/3306/mysqld.sock

mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.01 sec)


mysql> set global group_replication_bootstrap_group=ON;
Query OK, 0 rows affected (0.00 sec)

mysql> START group_replication;
Query OK, 0 rows affected (1.07 sec)

mysql> set global group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;


进入3307节点

mysql -S /usr/local/mysql5.7/data/3307/mysqld.sock

mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.00 sec)

mysql> START group_replication;
Query OK, 0 rows affected (5.59 sec)

mysql> exit;


进入3308节点:

mysql -S /usr/local/mysql5.7/data/3308/mysqld.sock

mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave,replication client on *.* to 'repluser'@'%' identified by 'replpass';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_user='repluser',master_password='replpass' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.01 sec)

mysql> start group_replication;
Query OK, 0 rows affected (2.25 sec)

进入三个任意一个节点验证:

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST             | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------------------+-------------+--------------+
| group_replication_applier | 7b29387c-6f81-11e8-abac-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z |        3306 | ONLINE       |
| group_replication_applier | 8badfa8f-6f81-11e8-aec3-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z |        3307 | ONLINE       |
| group_replication_applier | 90f24e32-6f81-11e8-aef5-00163e06e59d | iZm5e7kkxs23uutsa9dbl5Z |        3308 | ONLINE       |
+---------------------------+--------------------------------------+-------------------------+-------------+--------------+
3 rows in set (0.00 sec)

5.数据同步测试

进入到3306节点

mysql> create table tb_stu(id int not null primary key auto_increment,name varchar(50));
Query OK, 0 rows affected (0.02 sec)

mysql> select * from tb_stu;
+----+------+
| id | name |
+----+------+
|  1 | tom  |
+----+------+
1 row in set (0.00 sec)

进入3307节点:

mysql> select * from tb_stu;
+----+------+
| id | name |
+----+------+
|  1 | tom  |
+----+------+
1 row in set (0.00 sec)

同样进入3308节点验证:

mysql> select * from tb_stu;
+----+------+
| id | name |
+----+------+
|  1 | tom  |
+----+------+
1 row in set (0.00 sec)

说明三个节点能够进行数据同步。

加入我们在3307或者3308节点插入数据:

mysql>  insert tb_stu(id,name) values (1,'tom');
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

报错原因是:3306是主节点,3307和3308是从节点,单主模式下只能在主节点写入,从节点只能查询数据。

下面我们在进行多主节点修改和增加节点。

© 著作权归作者所有

共有 人打赏支持
日落北极
粉丝 7
博文 35
码字总数 24505
作品 0
海淀
程序员
私信 提问
mysql8.0初探:(二)MySQL Group Replication-MGR集群简介

简介 MySQL Group Replication(简称MGR)字面意思是mysql组复制的意思,但其实他是一个高可用的集群架构,暂时只支持mysql5.7和mysql8.0版本. 是MySQL官方于2016年12月推出的一个全新的高可用...

arthur376
2018/05/08
0
0
数据库Mysql5.7 MGR集群的搭建

最近看了一下mysql5.7的MGR集群挺不错的,有单主和多主模式,于是乎搭建测试了一下效果还不错,我指的不错是搭建和维护方面都比较简单。网上绝大多数都是单主模式,当然我这里也是,为了加深...

English0523
2017/09/04
0
0
MySQL · 引擎特性 · Group Replication内核解析

背景 为了创建高可用数据库系统,传统的实现方式是创建一个或多个备用的数据库实例,原有的数据库实例通常称为主库master,其它备用的数据库实例称为备库或从库slave。当master故障无法正常工...

阿里云RDS-数据库内核组
2017/08/02
0
0
mysql5.7 MGR集群搭建

微信公共号 mysql5.7 MGR集群搭建部署 此文章由队员(谆谆)拟写 此文章来自 乌龟运维 官网 wuguiyunwei.com QQ群 602183872 最近看了一下mysql5.7的MGR集群挺不错的,有单主和多主模式,于是...

乌龟运维
2017/06/08
0
0
MySQL高可用性分析

版权声明:本文由易固武原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/203 来源:腾云阁 https://www.qcloud.com/community MySQL数据库是目前开源应用...

偶素浅小浅
2016/11/11
4
0

没有更多内容

加载失败,请刷新页面

加载更多

告别2018

今天中午从喵喵家回来之后,倒头就睡到下午4点了。可能是之前透支的身体,在我放松下来后,开始觉得疲惫了,所以最近估计会进入嗜睡期。醒来之后,拿了包花生,开了瓶低糖菊花茶,听着网易云...

七木网络科技
23分钟前
1
0
MySql数据库分表分区实践

1. 背景 —— 公司物联网项目 海量设备通过物联网服务接入云端,设备每30s上报一次自身数据(以下称为动态数据)。 物联网服务将设备上报的数据转发给数据处理网关,由数据入库网关执行批量入...

吴伟祥
35分钟前
1
0
大表关联走hash优化

大表关联走hash? 案例: ---- 反正我执行过1个多小时,没有跑完 SELECT a.id AS order_id ,b.s_id AS bill_id, d.id AS sub_order_id, d.deal_oper_id FROM EM_ORDER PARTITION(EM_ORDER_20......

hnairdb
48分钟前
1
0
MySQL查询执行

当我们希望MySQL能够以更高的性能运行查询时,最好的办法就是弄清楚MySQL是如何优化和执行查询的。一旦理解了这一点,很多查询优化工作实际上就是遵循一些原则让优化器能够按照预想的合理方式...

问题终结者
今天
1
0
CDH5动静态资源池配置与回滚

关于动态 静态资源池的配置以前都有提过,可以从以下几篇了解: YARN动态资源池配置案例 https://yq.aliyun.com/ziliao/346856# Hadoop YARN配置参数剖析(4)—Fair Scheduler相关参数 Hadoop...

hblt-j
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部