美文网首页
mysql 5.7 安装及MGR的设置

mysql 5.7 安装及MGR的设置

作者: ittony | 来源:发表于2018-08-23 13:51 被阅读0次

安装mysql 5.7.23

打开 http://repo.mysql.com/ 找到最新的,如mysql57-community-release-el7-11.noarch.rpm

wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

ll /etc/yum.repos.d/

安装后新增2个源

如想加速,执行 wget -O  /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-7.repo

yum install mysql-server

设置,

1.开启慢查询

long-query-time=3

slow-query-log=1

slow-query-log-file=/var/log/mysql/log-slow-queries.log

2.获取临时密码

grep "temporary" /var/log/mysqld.log 或 grep "password" /var/log/mysqld.log

3.改密码,不修改无法进行其他操作

SET PASSWORD = PASSWORD('your new password');

ALTER USER 'root'@'localhost'  PASSWORD EXPIRE NEVER;

FLUSH  PRIVILEGES;

———————————至此安装已完成,下面是MGR的设置———————————

MGR的设置

编辑/etc/my.cnf

1.设置MGR复制框架 , 开启binlog

server_id=3   (id自填)

gtid_mode=ON

enforce_gtid_consistency=ON

master_info_repository=TABLE

relay_log_info_repository=TABLE

log_slave_updates=ON

log_bin=binlog    (默认值log_bin即为binlog,可以不加=binlog)

binlog_format=ROW

binlog_checksum=NONE

2.设置MGR

transaction_write_set_extraction=XXHASH64    (server必须为每个事务收集写集合,并使用XXHASH64哈希算法将其编码为散列)

loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"   (告知插件加入或创建组名,必须是UUID,可用工具创建)

loose-group_replication_start_on_boot=off           (server启动时不自启组复制)

loose-group_replication_local_address="n0:13306"   (告诉插件使用主机名或IP,自定义端口13306用于接收组中其他成员转入连接,端口可改 )

loose-group_replication_group_seeds="n0:13306,n1:13306,n2:13306"  (启动组server,种子server,加入组应该连接这些主机和端口;其他server要加入组得由组成员同意)

loose-group_replication_ip_whitelist='n0,n1,n2'     (可以忽略不写)

loose-group_replication_bootstrap_group=off   (表示是否启动MySQL分组,在一个分组中,只应当允许一个成员启动MySQL分组)

loose-group_replication_single_primary_mode=off       ( 多主模式须为off ,单主模式为on)

loose-group_replication_enforce_update_everywhere_checks=true       ( 多主模式须为true,单主模式为false)

以下操作均是登录mysql后进行

3.创建MGR的复制账号,并授权

#下面操纵不写入二进制日志,避免修改传递给其他服务器,先关闭完成后再开启;

set sql_log_bin=0;

create user rpl_user@'%' identified by 'rpl_pass';     #创建拥有replication slave权限mysql用户,用户名可自行替换

grant replication slave on *.* to rpl_user@'%' ;

flush privileges;

set sql_log_bin=1;

4 设置group_replication_recovery

#change master to命令将server配置为在下次需要从其他成员恢复状态时,使用group_replication_recovery复制通道的给定账号密码

change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';

5.安装组复制插件

install plugin group_replication soname 'group_replication.so';

show plugins

6.启动

6-9操作均是登录mysql后进行

# 第1台服务器启动组复制,复制组只须启动一次,第1台服务器和其他服务器在此次之后都无需再做以下操作

set global group_replication_bootstrap_group=ON;

start group_replication;

set global group_replication_bootstrap_group=OFF;

7 其他服务器设置

重复1-5的步骤

8.其他服务器启动及加入集群

set global group_replication_allow_local_disjoint_gtids_join=ON;    非必须如提示错误则运行

start group_replication;

9. 检测组是否创建并已加入新成员

select * from performance_schema.replication_group_members;

----------------------------------排错----------------------------------------------------------------

[ERROR] Plugin group_replication reported: 'For details please check performance_schema.replication_connection_status table and error log messages of Slave I/O for channel group_replication_recovery.'

select * from performance_schema.replication_group_members; 查出主机名

修改/etc/hosts 把主机名添加进去,也可用IP代替主机名但不一定有效

2018-08-29T03:07:33.494884Z 0 [ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: ecd4c59e-3bdc-11e8-9582-525400373379:1-4 > Group transactions: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-46'

2018-08-29T03:07:33.494916Z 0 [ERROR] Plugin group_replication reported: 'The member contains transactions not present in the group. The member will now exit the group.'

2018-08-29T03:07:33.494919Z 0 [Note] Plugin group_replication reported: 'To force this member into the group you can use the group_replication_allow_local_disjoint_gtids_join option'

解决:set global group_replication_allow_local_disjoint_gtids_join=ON;  

出错重启,先STOP GROUP_REPLICATION;  再START GROUP_REPLICATION;

注意:开启防火墙和SELinux会导致失败

---------------------------------其他指令----------------------------------------------------------

show global status like '%group_replication_primary%';   仅适用于单主模式

show variables where Variable_name like '%hostname%';   显示主机IP

参考:https://www.cnblogs.com/jorzy/p/8455519.html

https://dev.mysql.com/doc/refman/5.7/en/group-replication-configuring-instances.html

https://www.cnblogs.com/shengdimaya/p/8436112.html

http://axiaoxin.com/article/237/

相关文章

网友评论

      本文标题:mysql 5.7 安装及MGR的设置

      本文链接:https://www.haomeiwen.com/subject/vfrxbftx.html