主机名 | IP地址 | 角色 |
---|---|---|
node2.com | 172.16.8.101 | primary |
node3.com | 172.16.8.53 | seconde |
node3.com | 172.16.8.68 | seconde |
操作系统:CentOS Linux release 7.2.1511
MySQL版本:mysql-5.7.26-linux-glibc2.12-x86_64
MySQL Router版本:mysql-router-8.0.17-linux-glibc2.12-x86_64
MySQL Shell版本:mysql-shell-8.0.17-linux-glibc2.12-x86-64bit
注意: 以下需要在三台机器上分别安装
本次安装为一主两从模式
# systemctl stop firewalld
# systemctl disable firewalld
# setenforce 0
# cat /etc/sysconfig/selinux
## 如果上一步查的SELINUX=disabled则下一步用sed替换不用执行
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# getenforce
# cd /software/
# tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz mysql
# mkdir -p /data/mysql/data/3306
# useradd mysql
# chown -R mysql:mysql /data/mysql/data/3306
# chown -R mysql:mysql /usr/local/mysql*
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data/3306
port=3306
socket=/tmp/mysql.sock
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.16.8.101:33060"
loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
loose-group_replication_bootstrap_group=off
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data/3306
port=3306
socket=/tmp/mysql.sock
server_id=2
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.16.8.53:33060"
loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
loose-group_replication_bootstrap_group=off
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data/3306
port=3306
socket=/tmp/mysql.sock
server_id=3
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.16.8.68:33060"
loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
loose-group_replication_bootstrap_group=off
说明: 上面的三个配置文件省略了所有不必要的配置项,但是看起来还是有点多,这些都是mgr环境要求的。
# cd /usr/local/mysql/
# ./bin/mysqld --defaults-file=/etc/my.cnf --datadir=/data/mysql/data/3306/ --user=mysql --initialize-insecure
--initialize-insecure:无密码初始化MySQL
说明: CentOS7.x下与服务启动相关的脚本不在是7以下的/etc/init.d/目录的下脚本,而是/usr/lib/systemd/system/目录
配置systemd相关的配置文件/usr/lib/systemd/system/mysql.service
vim /usr/lib/systemd/system/mysql.service
输入如下内容
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
#LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
# systemctl enable mysql
# systemctl start mysql
# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
# source /etc/profile
# echo "172.16.8.101 node2.com" >> /etc/hosts
# echo "172.16.8.53 node3.com" >> /etc/hosts
# echo "172.16.8.68 node4.com" >> /etc/hosts
# mysql -uroot -p
mgr中所有的结点都属于一个逻辑上的组、这个组就像是QQ群一样,是由群主建起来的,有了这个上组之后,其它的结点就可以加入到这个组中来了。onode2.com来建群,以下步骤在node2.com主机上的mysql中执行
mysql> set sql_log_bin=0;
mysql> create user mgruser@'%' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'%';
mysql> create user mgruser@'127.0.0.1' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1';
mysql> create user mgruser@'localhost' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'localhost';
mysql> set sql_log_bin=1;
mysql> change master to
-> master_user='mgruser',
-> master_password='123456'
-> for channel 'group_replication_recovery';
mysql> install plugin group_replication soname 'group_replication.so';
mysql> set global group_replication_bootstrap_group=on;
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=off;
说明:
第二个结点和第一个结点唯一的不同在于它不在要自己去建一个群了,它只要加入第一个结点建的群就可以了,以下步骤在node3.com主机上的mysql中执行
mysql> set sql_log_bin=0;
mysql> create user mgruser@'%' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'%';
mysql> create user mgruser@'127.0.0.1' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1';
mysql> create user mgruser@'localhost' identified by '123456';
mysql> grant replication slave,replication client on *.* to mgruser@'localhost';
mysql> set sql_log_bin=1;
mysql> change master to
-> master_user='mgruser',
-> master_password='123456'
-> for channel 'group_replication_recovery';
mysql> install plugin group_replication soname 'group_replication.so';
mysql> start group_replication;
逻辑上第二个结点与第三、第四、第五...等等结点有着一样的逻辑角色,就也是说它们都不是群主,所以它们的配置方式和第二个结点是一样的,所以不在详细列举每一步的配置
原文:https://www.cnblogs.com/williamzheng/p/11365235.html