1. 程式人生 > >mysql5.7 MRG文件及叢集部署學習

mysql5.7 MRG文件及叢集部署學習

文章目錄


有關複製組的相關原理介紹: http://note.youdao.com/noteshare?id=9eb41d6de1af00e41314297282a43bc1
環境:

ip hostname
192…168.8.80 node-01
192…168.8.81 node-02
192…168.8.83 node-03
1、安裝mysql
[[email protected]]# yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
[[email protected]]# yum -y install Percona-Server-server-57
[
[email protected]
]# cat /var/log/mysqld.log |grep "[email protected]" 2018-11-02T05:41:32.373113Z 1 [Note] A temporary password is generated for [email protected]: m-3SAGso6w43 [[email protected]]# mysql -uroot -pm-3SAGso6w43 mysql> show variables like '%vali%'; mysql> set global validate_password_length=4; mysql> alter user 'root'@'localhost' identified by 'root123';
2、修改配置檔案:

my.cnf配置檔案裡修改引數: server-id、loose-group_replication_local_address

[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server-id = 101
log-bin = master-bin
log-bin-index = master-bin.index
binlog_format = row
gtid-mode = ON
enforce-gtid-consistency = ON
log-bin=mysql-bin
log-slave-updates
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE

## group replication 配置 
#如果server啟動時尚未載入複製外掛,group_replicaton 變數使用loose-字首將指示server繼續啟動。
transaction_write_set_extraction=XXHASH64 #表示server必須為每個事物收集寫集合,並使用XXHASH64 雜湊演算法將其編碼為雜湊。
loose_group_replication_start_on_boot=OFF
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="192..168.8.80:33061"
loose-group_replication_group_seeds="192..168.8.80:33061,192..168.8.81:33061,192..168.8.83:33061"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=FALSE
loose-group_replication_enforce_update_everywhere_checks= TRUE
loose-group_replication_ip_whitelist="192..168.8.80,192..168.8.81,192..168.8.83"

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

3、安裝group_replicatin外掛,啟動group_replication
[[email protected]]# mysql -uroot -proot123
mysql> set sql_log_bin=0;
mysql> grant replication slave on *.* to  'rep'@'%' identified by 'rep123';
mysql> flush privileges;
mysql> set sql_log_bin=1;
mysql> change master to master_user='rep',master_password='rep123' for channel 'group_replication_recovery';
mysql> install plugin group_replication soname 'group_replication.so';
mysql> show plugins;
+-----------------------------+----------+--------------------+----------------------+---------+
| Name                        | Status   | Type               | Library              | License |
+-----------------------------+----------+--------------------+----------------------+---------+
| group_replication           | ACTIVE   | GROUP REPLICATION  | group_replication.so | GPL     |
+-----------------------------+----------+--------------------+----------------------+---------+
mysql> set global group_replication_bootstrap_group=ON;
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=OFF;
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+---------------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST         | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+
| group_replication_applier | f38e5798-de61-11e8-91e6-fa163e180951 | node-01			 |        3306 | ONLINE       |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+
4、新增節點node-02 node-03:

安裝mysql、my.cnf 同上
安裝group_replicatin外掛,啟動group_replication

mysql> set sql_log_bin=0;
mysql> grant replication slave on *.* to  'rep'@'%' identified by 'rep123';
mysql> flush privileges;
mysql> set sql_log_bin=1;
mysql> change master to master_user='rep',master_password='rep123' for channel 'group_replication_recovery';
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
mysql> start group_replication;
mysql> select * from  performance_schema.replication_group_members;
+---------------------------+--------------------------------------+---------------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST         | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+
| group_replication_applier | 433cc62e-dd00-11e8-a653-fa163e4f3761 | node-03			 |        3306 | ONLINE       |
| group_replication_applier | af4e8b5d-bc99-11e8-9ad1-fa163e230ff6 | node-02			 |        3306 | ONLINE       |
| group_replication_applier | f38e5798-de61-11e8-91e6-fa163e180951 | node-01			 |        3306 | ONLINE       |
+---------------------------+--------------------------------------+---------------------+-------------+--------------+