在雨润2年,在老大临走之际才知道我们的MySQL不是简单的主从结构,而是MGR集群。哈哈,看了老大留下来的文档,于是尝试着在自己的VM上搭建一下,练习练习
环境准备
- 192.168.2.3 centos01
- 192.168.2.4 centos02
- 192.168.2.5 centos03
tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql/
mkdir -p /home/mysql/data
mkdir -p /home/mysql/log
chmod -R 777 /home/mysql/data/
chmod -R 777 /home/mysql/log/
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin
/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/home/mysql/data
chkconfig --add mysql
chkconfig --list
[mysqld]
character_set_server=utf8mb4
datadir=/home/mysql/data
socket=/tmp/mysql.sock
user=root
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#优化
max_connections = 3000
max_connect_errors = 10000
max_allowed_packet = 1024M
slow_query_log = 1
long_query_time = 5
slow_query_log_file = /home/mysql/log/mysql-slow.log
innodb_page_cleaners = 4
lower_case_table_names = 1
#Group Replication
server_id = 1
#服务ID
gtid_mode = ON
#全局事物
enforce_gtid_consistency = ON
#强制GTID的⼀致性
binlog_gtid_simple_recovery = 1
master_info_repository = TABLE
#将master.info元数据保存在系统表中
relay_log_info_repository = TABLE
#将relay.info元数据保存在系统表中
relay_log=/home/mysql/log/relay-log
binlog_checksum = NONE
#禁⽤⼆进制⽇志事件校验
log_slave_updates = ON
#级联复制
log_bin = /home/mysql/data/binlog
#开启⼆进制⽇志记录
binlog_format= ROW
#以⾏的格式记录
log-error=/home/mysql/log/error.log
pid-file=/home/mysql/data/mysqld.pid
##优化
loose-group_replication_compression_threshold = 15000
loose-group_replication_transaction_size_limit = 1073741824
loose-group_replication_unreachable_majority_timeout = 5
transaction_write_set_extraction = XXHASH64
#使⽤哈希算法将其编码为散列
loose-group_replication_group_name = 'ce9be252-2b72-11e6-b8f4-00212844f856'
#加⼊的组名,随便写
loose-group_replication_start_on_boot = off
#不启⽤⾃动复制集群功能
loose-group_replication_member_weigth = 30
# ⾮必需,mysql 5.7.20才开始⽀持该选项
loose-group_replication_local_address = 'centos01:33061'
#以本机3306端⼝接收来⾃组成员的传⼊连接
loose-group_replication_group_seeds='centos01:33061,centos02:33061,centos03:33061'
#组中成员访问列表
loose-group_replication_bootstrap_group = off
#不启⽤引导组
loose-group_replication_single_primary_mode = ON
##loose-group_replication_enforce_update_everywhere_checks=ON
# =multi-primary
Master
mysql> set SQL_LOG_BIN=0; #停掉⽇志记录
mysql> grant replication slave on *.* to mgr@'%' identified by
'123456';
mysql> flush privileges;
mysql> set SQL_LOG_BIN=1; #开启⽇志记录
mysql> change master to master_user='mgr',master_password='123456' for
channel 'group_replication_recovery';
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
mysql> show plugins;
# 单主模式
刧洇MGR敯䒳
⪭☽僜ⱷ⹇拨┕鳮鿥糌server_id⽰IP嫱䙬⟤䷊
# 设置group_replication_bootstrap_group为ON是为了标示以后加⼊集群的服务器以这
台服务器为基准,以后加⼊的就不需要设置
mysql> set global group_replication_bootstrap_group=ON;
# 作为⾸个节点启动MGR集群
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=OFF;
Slave
mysql> change master to master_user='mgr',master_password='123456' for
channel 'group_replication_recovery';
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
mysql> show plugins;
# 其他节点
mysql> set global
group_replication_allow_local_disjoint_gtids_join=ON;
mysql> start group_replication;