内容简介:(一)主机操作(1)路由信息
(一)主机操作
(1)路由信息
vmnet5 192.168.10.0
(2)主机信息
主机名称 | IP地址 | 操作系统版本 | 数据库版本 |
mgr-node1 | 192.168.10.11 | centos 7.4 ,64-bit | mysql社区版 5.7.24 |
mgr-node2 | 192.168.10.12 | centos 7.4 , 64-bit | mysql社区版 5.7.24 |
mgr-node3 | 192.168.10.13 | centos 7.4 ,64-bit | mysql社区版 5.7.24 |
配置所有主机的hosts文件:
[root@mgr-node1 data]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.10.11 mgr-node1 192.168.10.12 mgr-node2 192.168.10.13 mgr-node3
(3)关闭所有节点的防火墙和selinux
# 关闭防火墙# 查看防火墙状态,正在运行 [root@mgr-node1 ~]# firewall-cmd --state running# 关闭防火墙 [root@mgr-node1 ~]# service firewalld stop Redirecting to /bin/systemctl stop firewalld.service [root@mgr-node1 ~]# firewall-cmd --state not running# 永久关闭防火墙 [root@mgr-node1 ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. #禁用selinux [root@mgr-node1 ~]# vi /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted(二)安装 MySQL 数据库
这里在每个节点安装MySQL软件,过程见: https://www.cnblogs.com/lijiaman/p/10743102.html
参数文件:/etc/my.cnf
# 设置mysql的安装目录
basedir=/mysql
# 设置mysql数据库的数据的存放目录
datadir=/mysql/data
(三)配置组复制(Group Replication)--采用多主模式创建binlog日志存放路径,三个节点都要创建:
[root@mgr-node1 etc]# mkdir -p /mysql/binlog/ [root@mgr-node1 etc]# chown -R mysql:mysql /mysql/binlog
(1)节点1配置组复制
(1.1)在节点1上添加如下参数,重启实例
# 复制参数 server_id = 1 gtid_mode = on enforce_gtid_consistency = on master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_bin = /mysql/binlog/mgr-node1-bin log-slave-updates = 1 binlog_format = row sync-master-info = 1 sync_binlog = 1 skip_slave_start = 1 #group replication参数 transaction_write_set_extraction=XXHASH64 #以便在server收集写集合的同时将其记录到二进制日志。写集合基于每行的主键,并且是行更改后的唯一标识此标识将用于检测冲突。 loose-group_replication_group_name="dc04ba77-bcf2-11ea-85bf-000c295111ae" #组的名字可以随便起,但不能用主机的GTID! 所有节点的这个组名必须保持一致! loose-group_replication_start_on_boot=off #启动mysql时不自动启动组复制 loose-group_replication_local_address= "192.168.10.11:24901" #本机IP地址,24901用于接收来自其他组成员的传入连接 loose-group_replication_group_seeds= "192.168.10.11:24901,192.168.10.12:24901,192.168.10.13:24901" # 当前主机成员需要加入组时,Server先访问这些种子成员中的一个,然后它请求重新配置以允许它加入组, # 需要注意的是,此参数不需要列出所有组成员,只需列出当前节点加入组需要访问的节点即可。 loose-group_replication_bootstrap_group=off # 是否自动引导组。此选项只能在一个server实例上使用,通常是首次引导组时(或在整组成员关闭的情况下),如果多次引导,可能出现脑裂。 loose-group_replication_single_primary_mode=off #关闭单主模式的参数(本例测试时多主模式,所以关闭该项) loose-group_replication_enforce_update_everywhere_checks=on #开启多主模式的参数 loose-group_replication_ip_whitelist="192.168.10.0/24,127.0.0.1/8" # 允许加入组复制的客户机来源的ip白名单
(1.2)创建组复制的用户
组复制使用异步复制协议来实现分布式恢复,在将组成员加入组之前对其进行同步,分布式恢复过程依赖于group_replication_recovery通道,该通道用于组成员之间传输数据。因此,需要设置具有正确权限的复制用户,以便组复制可以建立成员到成员的数据恢复。
用于数据复制的用户需要有REPLICATION_SLAVE特权,用户的创建有2种方法:
方法一:第一个节点创建复制用户,二进制日志中捕获创建用户的过程,然后依靠分布式恢复来复制创建用户的语句。[注:奇怪的是,网上都不使用这种方法
方法二:禁用二进制日志,避免将创建用户传播到其它实例,然后在每一个节点创建复制用户。
这里演示第二种方法:
[root@mgr-node1 etc]# mysql -uroot -p123456 mysql> SET SQL_LOG_BIN=0; # 关闭binlog Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_slave@'%' IDENTIFIED BY '123456'; # 创建组复制的用户 Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.01 sec) mysql> SET SQL_LOG_BIN=1; # 开启binlog Query OK, 0 rows affected (0.00 sec)
(1.3)配置节点1上的组复制并安装组复制插件
mysql> CHANGE MASTER TO MASTER_USER='rpl_slave', MASTER_PASSWORD='123456' 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> SHOW PLUGINS; +----------------------------+----------+--------------------+----------------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+----------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | ... ... ... ... ... | | group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL | +----------------------------+----------+--------------------+----------------------+---------+ 45 rows in set (0.00 sec)
(1.4)开启节点1上的组复制
首次启动组的过程称为引导,使用group_replication_bootstrap_group系统变量来引导组,引导程序只能由一台服务器执行一次,且只能执行一次,这就是group_replication_bootstrap_group参数不保存在配置文件中的原因。假如将该参数保存在配置文件中,则在重启时,server会自动引导具有相同名称的第二个组,这将导致两个不同的组具有相同的名称。因此,为了安全的引导组,请连接到第一个节点执行:
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 (2.10 sec) mysql> SET GLOBAL group_replication_bootstrap_group=OFF; Query OK, 0 rows affected (0.00 sec)
在执行组引导及启动组复制后,组已经创建出来了,我们可以使用下面命令查看组信息
mysql> SELECT * FROM performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 533fe6ba-bcdf-11ea-9516-000c295111ae | mgr-node1 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 1 row in set (0.00 sec)
(2)节点2配置组复制
(2.1)在节点2上添加如下参数,重启实例
# 复制参数 server_id = 2 gtid_mode = on enforce_gtid_consistency = on master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_bin = /mysql/binlog/mgr-node2-bin log-slave-updates = 1 binlog_format = row sync-master-info = 1 sync_binlog = 1 skip_slave_start = 1 #group replication参数 transaction_write_set_extraction=XXHASH64 #以便在server收集写集合的同时将其记录到二进制日志。写集合基于每行的主键,并且是行更改后的唯一标识此标识将用于检测冲突。 loose-group_replication_group_name="dc04ba77-bcf2-11ea-85bf-000c295111ae" #组的名字可以随便起,但不能用主机的GTID! 所有节点的这个组名必须保持一致! loose-group_replication_start_on_boot=off #为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。 loose-group_replication_local_address= "192.168.10.12:24901" loose-group_replication_group_seeds= "192.168.10.11:24901,192.168.10.12:24901,192.168.10.13:24901" loose-group_replication_bootstrap_group=off loose-group_replication_single_primary_mode=off #关闭单主模式的参数(本例测试时多主模式,所以关闭该项) loose-group_replication_enforce_update_everywhere_checks=on #开启多主模式的参数 loose-group_replication_ip_whitelist="192.168.10.0/24,127.0.0.1/8" # 允许加入组复制的客户机来源的ip白名单
(2.2)创建组复制的用户
[root@mgr-node2 etc]# mysql -uroot -p123456 mysql> SET SQL_LOG_BIN=0; # 关闭binlog Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_slave@'%' IDENTIFIED BY '123456'; # 创建组复制的用户 Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.01 sec) mysql> SET SQL_LOG_BIN=1; # 开启binlog Query OK, 0 rows affected (0.00 sec)
(2.3)配置节点2上的组复制并安装组复制插件
mysql> CHANGE MASTER TO MASTER_USER='rpl_slave', MASTER_PASSWORD='123456' 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> SHOW PLUGINS; +----------------------------+----------+--------------------+----------------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+----------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | ... ... ... ... ... | | group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL | +----------------------------+----------+--------------------+----------------------+---------+ 45 rows in set (0.00 sec)
(2.4)开启节点2上的组复制
在第二个节点开启组复制的时候,不用再设置引导参数
mysql> START GROUP_REPLICATION; Query OK, 0 rows affected (2.10 sec)
查看组成员,此时有2个节点已经加入了组
mysql> SELECT * FROM performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 533fe6ba-bcdf-11ea-9516-000c295111ae | mgr-node1 | 3306 | ONLINE | | group_replication_applier | 5ca45641-bcdd-11ea-918e-000c29fa726d | mgr-node2 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 2 rows in set (0.00 sec)
(3)节点3配置组复制
(3.1)在节点3上添加如下参数,重启实例
# 复制参数 server_id = 3 gtid_mode = on enforce_gtid_consistency = on master_info_repository=TABLE relay_log_info_repository=TABLE binlog_checksum=NONE log_bin = /mysql/binlog/mgr-node3-bin log-slave-updates = 1 binlog_format = row sync-master-info = 1 sync_binlog = 1 skip_slave_start = 1 #group replication参数 transaction_write_set_extraction=XXHASH64 #以便在server收集写集合的同时将其记录到二进制日志。写集合基于每行的主键,并且是行更改后的唯一标识此标识将用于检测冲突。 loose-group_replication_group_name="dc04ba77-bcf2-11ea-85bf-000c295111ae" #组的名字可以随便起,但不能用主机的GTID! 所有节点的这个组名必须保持一致! loose-group_replication_start_on_boot=off #为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。 loose-group_replication_local_address= "192.168.10.13:24901" loose-group_replication_group_seeds= "192.168.10.11:24901,192.168.10.12:24901,192.168.10.13:24901" loose-group_replication_bootstrap_group=off loose-group_replication_single_primary_mode=off #关闭单主模式的参数(本例测试时多主模式,所以关闭该项) loose-group_replication_enforce_update_everywhere_checks=on #开启多主模式的参数 loose-group_replication_ip_whitelist="192.168.10.0/24,127.0.0.1/8" # 允许加入组复制的客户机来源的ip白名单
(3.2)创建组复制的用户
[root@mgr-node3 etc]# mysql -uroot -p123456 mysql> SET SQL_LOG_BIN=0; # 关闭binlog Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_slave@'%' IDENTIFIED BY '123456'; # 创建组复制的用户 Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> reset master; Query OK, 0 rows affected (0.01 sec) mysql> SET SQL_LOG_BIN=1; # 开启binlog Query OK, 0 rows affected (0.00 sec)
(3.3)配置节点3上的组复制并安装组复制插件
mysql> CHANGE MASTER TO MASTER_USER='rpl_slave', MASTER_PASSWORD='123456' 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> SHOW PLUGINS; +----------------------------+----------+--------------------+----------------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+----------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | ... ... ... ... ... | | group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL | +----------------------------+----------+--------------------+----------------------+---------+ 45 rows in set (0.00 sec)
(3.4)开启节点3上的组复制
mysql> START GROUP_REPLICATION; Query OK, 0 rows affected (2.10 sec)
查看组成员,此时所有成员已经加入到了组
mysql> SELECT * FROM performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 533fe6ba-bcdf-11ea-9516-000c295111ae | mgr-node1 | 3306 | ONLINE | | group_replication_applier | 5ca45641-bcdd-11ea-918e-000c29fa726d | mgr-node2 | 3306 | ONLINE | | group_replication_applier | 62ad32e3-bcdd-11ea-9bbb-000c2978d7f6 | mgr-node3 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 3 rows in set (0.00 sec)
【完】
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Docker搭建MySQL主从复制
- MySQL主从复制搭建及详解
- MySQL 主从复制搭建,基于日志(binlog)
- MySQL半同步复制的搭建和配置原理
- 基于Docker Compose搭建MySQL主从复制(1主2从)
- GlusterFS分布式存储搭建双机复制卷结合Keepalived实现存储高可用
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Out of Control
Kevin Kelly / Basic Books / 1995-4-14 / USD 22.95
Out of Control is a summary of what we know about self-sustaining systems, both living ones such as a tropical wetland, or an artificial one, such as a computer simulation of our planet. The last chap......一起来看看 《Out of Control》 这本书的介绍吧!