文章目录
环境准备
节点名称 | ip地址 |
---|---|
node1 | 192.168.130.20 |
node2 | 192.168.130.19 |
node2 | 192.168.130.21 |
/etc/hosts(node1、node2、node3)
192.168.130.20 hello001
192.168.130.19 hello002
192.168.130.21 hello003
配置
创建数据目录(node1、node2、node3)
mkdir -p /root/mysql-cluster/data && chmod 777 /root/mysql-cluster/data
pxc节点默认监听端口:
3306:数据库对外服务的端口号
4444:请求SST,在新节点加入时起作用
4567:组成员之间沟通的端口
4568:传输IST,节点下线,重启加入时起作用
启动
node1
docker rm -f mysql-pxc-node1
docker run -d --network=host --name=mysql-pxc-node1 \
-e MYSQL_ROOT_PASSWORD=hello \
-e CLUSTER_NAME=helloPXC \
-e XTRABACKUP_PASSWORD=hello123456 \
-e TZ=Asia/Shanghai \
-v /root/mysql-cluster/data:/var/lib/mysql \
percona/percona-xtradb-cluster:5.7.31
node2
docker rm -f mysql-pxc-node2
docker run -d --network=host --name=mysql-pxc-node2 \
-e MYSQL_ROOT_PASSWORD=hello \
-e CLUSTER_NAME=helloPXC \
-e CLUSTER_JOIN=192.168.130.20 \
-e XTRABACKUP_PASSWORD=hello123456 \
-e TZ=Asia/Shanghai \
-v /root/mysql-cluster/data:/var/lib/mysql \
percona/percona-xtradb-cluster:5.7.31
node3
docker rm -f mysql-pxc-node3
docker run -d --network=host --name=mysql-pxc-node3 \
-e MYSQL_ROOT_PASSWORD=hello \
-e CLUSTER_NAME=helloPXC \
-e CLUSTER_JOIN=192.168.130.20 \
-e XTRABACKUP_PASSWORD=hello123456 \
-e TZ=Asia/Shanghai \
-v /root/mysql-cluster/data:/var/lib/mysql \
percona/percona-xtradb-cluster:5.7.31
查看集群状态
docker exec -it mysql-pxc-node1 /usr/bin/mysql -uroot -phello
mysql> show status like 'wsrep%';
....
wsrep_incoming_addresses
...
wsrep_incoming_addresses节点地址是否都已经加入