软件版本:
操作系统:CentOS 7.6
数据库:MySQL 8.0.19
虚拟机:VM Workstation 15 Pro
IP地址分配:
DB1 192.168.5.130:3306
DB2 192.168.5.130:3307
DB3 192.168.5.130:3308
1、安装MySQL
#依赖包
yum -y install libaio*
#解压软件
xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar -C /usr/local
ln -s /usr/local/mysql-8.0.19-linux-glibc2.12-x86_64/ /usr/local/mysql
#创建用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
#创建数据目录
mkdir -p /mysql_data/data/s{1..3}
chown mysql:mysql -R /mysql_data/data
chmod 750 -R /mysql_data/data
#初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/mysql_data/data/s1 --user=mysql /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/mysql_data/data/s2 --user=mysql /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/mysql_data/data/s3 --user=mysql
#my3306.cnf
#几乎默认参数,方便你们安装 [client] #user = root #password = xxxxx [mysqld] # basic settings # user = mysql port = 3306 socket = mysql.sock basedir = /usr/local/mysql datadir = /mysql_data/data/s1 bind-address = 0.0.0.0 max_connections = 500 max_connect_errors = 1000 log_error = error.log pid-file = mysql.pid server-id = 3306130 log_bin = binlog binlog_format = row sync_binlog = 1 log_timestamps=SYSTEM interactive_timeout = 28800 wait_timeout = 28800 default_authentication_plugin=mysql_native_password transaction_isolation = READ-COMMITTED binlog_rows_query_log_events = 1 # group repl settings # gtid_mode=ON enforce_gtid_consistency=ON binlog_checksum=NONE plugin_load_add='group_replication.so' group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" group_replication_start_on_boot=off group_replication_local_address= "192.168.5.130:33061" group_replication_group_seeds= "192.168.5.130:33061,192.168.5.130:33062,192.168.5.130:33063" group_replication_bootstrap_group=off group_replication_unreachable_majority_timeout=60 group_replication_single_primary_mode = 1 #group_replication_enforce_update_everywhere_checks = 1 # innodb settings # innodb_buffer_pool_size = 128M innodb_buffer_pool_instances = 2 innodb_flush_log_at_trx_commit = 1
#启动MySQL
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3306.cnf --user=mysql & /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --user=mysql & /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3308.cnf --user=mysql &
2、MGR配置
#记住哦 my3306.cnf,my3307.cnf、my3308.cnf的端口与server id差异哦,
group_replication_local_address 这里要改的
plugin_load_add='group_replication.so' group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" group_replication_start_on_boot=off group_replication_local_address= "192.168.5.130:33061" group_replication_group_seeds= "192.168.5.130:33061,192.168.5.130:33062,192.168.5.130:33063" group_replication_bootstrap_group=off group_replication_unreachable_majority_timeout=60 group_replication_single_primary_mode = 1
3、主库执行(首次启动组的过程称为引导,只需要在其中一台服务器上执行一次,此库即为主库)
CREATE USER repl@'%' IDENTIFIED BY 'mysqldb@1025';
GRANT REPLICATION SLAVE ON *.* TO repl@'%';
FLUSH PRIVILEGES;
CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='mysqldb@1025' FOR CHANNEL 'group_replication_recovery';
INSTALL PLUGIN group_replication SONAME 'group_replication.so';
首次启动组的过程称为引导,只需要在一台服务器上执行一次,此库即为主库:
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;
#查询集群状态
SELECT * FROM performance_schema.replication_group_members;
4、从库执行:
CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='mysqldb@1025' FOR CHANNEL 'group_replication_recovery';
START GROUP_REPLICATION;
#查询集群状态
SELECT * FROM performance_schema.replication_group_members;