写在前面:之前一直用mariadb 版本,mariadb 集成了galera插件,实现pxc部署较为简单。官方在5.7推出了MySQL Group Replication,之前因为时间原因,一直没有时间搭建,今天也是抱着学习对比的态度,进行一个MySQL Group Replication 搭建和了解。
一、 测试环境
1)centos 6.5 3台 :
192.168.1.212 hadoop1
192.168.1.223 hadoop 2
192.168.1.222 hadoop 3
修改/etc/hosts 将对应的ip 主机名加入, 关闭防火墙,关闭selinux
2)mysql版本:5.7.18(二进制包) :mysql-5.7.18-linux-glibc2.5-x86_64.tar
二、 详细步骤
1)mysql部署
添加对应的basedir ,datadir目录,mysql用户
mkdir /data
mkdir /data/mysql_data
useradd mysql
将对应的MySQL版本 mysql-5.7.18-linux-glibc2.5-x86_64.tar ,配置文件my.cnf 上传到对应目录,我的上传目录为/usr/local/src/下
解压:
cd /usr/local/src
tar xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar
tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
修改文件名字,将mysql文件移动到basedir下,也可以使用软链接
mv mysql-5.7.18-linux-glibc2.5-x86_64 /data/mysql
cp my.cnf /etc/my.cnf 这里我写了个简单的mysql配置文件
修改文件属组:
chown mysql.mysql -R /data/
初始化安装mysql:
/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize
拷贝启动服务脚本:
cp /data/mysql/support-files/mysql.server /etc/init.d/mysql
添加环境变量:
export PATH=$PATH:/data/mysql/bin
添加开机启动mysql
chkconfig --add mysql
启动mysql
service mysql start
在错误日志中过滤出原始root密码
[root@haboop1 ~]# cat /data/mysql_data/error.log |grep password
2017-10-20T11:20:26.061066Z 1 [Note] A temporary password is generated for root@localhost: &Z2va(hNqKat
进入mysql 修改密码
set password=password('123456')
至此 mysql 基本部署完成 (按照同样的方法部署其他两台机器)
2)组复制配置 (第一个节点hadoop1)
首先修改mysql配置文件my.cnf 添加如下配置:
启用group repliacation的前提:
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
安装组复制插件
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
组复制参数配置(动态配置后,最好加入配置文件my.cnf)
set global transaction_write_set_extraction = XXHASH64
set global group_replication_start_on_boot = OFF
set global group_replication_bootstrap_group = OFF
set global group_replication_group_name = b6ddfda0-d8bc-4272-a58f-4ea75acbbc79
set global group_replication_local_address = '192.168.1.212:23306'
set global group_replication_group_seeds = '192.168.1.212:23306,192.168.1.222:23306,192.168.1.223:23306'
开启多主模式的参数:
set global group_replication_single_primary_mode=FALSE
set global group_replication_enforce_update_everywhere_checks=TRUE
创建复制账户
SET SQL_LOG_BIN=0;
CREATE USER repl@'%';
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='repl',MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
启动组复制
SET GLOBAL group_replication_bootstrap_group=ON;
注:group_replication_bootstrap_group参数设置为ON,是为了标示以后加入集群的服务器都已这台服务器为基准,只在某一个节点上使用。本例是以第一个节点为准。
START GROUP_REPLICATION;
如果启动报错,查看错误日志具体报错信息!
启动正常后,检查组复制状态:
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 931dccbe-b58b-11e7-9ab3-000c29d7bafc | hadoop1 | 3306 | ONLINE
这样第一个节点的配置就完成了!注意查看错误日志中的信息,
3)配置第二个节点(hadoop2)
启用group repliacation的前提:
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
安装组复制插件
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
组复制参数配置(动态配置后,最好加入配置文件my.cnf)
set global transaction_write_set_extraction = XXHASH64
set global group_replication_start_on_boot = OFF
set global group_replication_bootstrap_group = OFF
set global group_replication_group_name = b6ddfda0-d8bc-4272-a58f-4ea75acbbc79
set global group_replication_local_address = '192.168.1.223:23306'
set global group_replication_group_seeds = '192.168.1.212:23306,192.168.1.222:23306,192.168.1.223:23306'
开启多主模式的参数:
set global group_replication_single_primary_mode=FALSE
set global group_replication_enforce_update_everywhere_checks=TRUE
创建复制账户
SET SQL_LOG_BIN=0;
CREATE USER repl@'%';
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='repl',MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
启动组复制
START GROUP_REPLICATION;
启动正常后检查组复制状态
SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 931dccbe-b58b-11e7-9ab3-000c29d7bafc | hadoop1 | 3306 | ONLINE |
| group_replication_applier | ab8c3ec3-b588-11e7-a769-000c29c57be6 | haboop2 | 3306 | ONLINE
4)配置第三个节点(hadoop3)
启用group repliacation的前提:
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
安装组复制插件
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
组复制参数配置(动态配置后,最好加入配置文件my.cnf)
set global transaction_write_set_extraction = XXHASH64
set global group_replication_start_on_boot = OFF
set global group_replication_bootstrap_group = OFF
set global group_replication_group_name = b6ddfda0-d8bc-4272-a58f-4ea75acbbc79
set global group_replication_local_address = '192.168.1.222:23306'
set global group_replication_group_seeds = '192.168.1.212:23306,192.168.1.222:23306,192.168.1.223:23306'
开启多主模式的参数:
set global group_replication_single_primary_mode=FALSE
set global group_replication_enforce_update_everywhere_checks=TRUE
创建复制账户
SET SQL_LOG_BIN=0;
CREATE USER repl@'%';
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='repl',MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
启动组复制
START GROUP_REPLICATION;
启动正常后检查组复制状态
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 931dccbe-b58b-11e7-9ab3-000c29d7bafc | hadoop1 | 3306 | ONLINE |
| group_replication_applier | ab8c3ec3-b588-11e7-a769-000c29c57be6 | haboop2 | 3306 | ONLINE |
| group_replication_applier | d24c1c76-b4ef-11e7-969a-000c29a75f68 | hadoop3 | 3306 | ONLINE
5)验证,在各节点创建,插入删除数据
这样 三个节点的组复制基本配置完成了!
以上步骤参考微博:http://blog.chinaunix.net/xmlrpc.phpr=blog/article&uid=31396856&id=5758012
在配置过程中也会遇到报错,遇到报错过程可以查看错误日志 参考:
http://blog.itpub.net/27067062/viewspace-2142098
http://blog.csdn.net/zdy0_2004/article/details/69568988