基于Docker搭建Mysql的PXC集群

基于Docker搭建Mysql的PXC集群

镜像信息

镜像名称:percona/percona-xtradb-cluster
点击跳转镜像地址

下载镜像

docker pull percona/percona-xtradb-cluster

修改本地的镜像名称为mysql-pxc

docker tag percona/percona-xtradb-cluster mysql-pxc

查看现在的镜像列表

给PXC集群实例创建Docker内部网络

docker network create --subnet 172.18.1.1/24 mysql-net

通过inspect命令查看网络详情

docker network inspect mysql-net

[
    {
        "Name": "mysql-net",
        "Id": "271ed67c250c65e72dcae9d5559209d1921f4ad9d0b5aec097272fcaeaa9f86f",
        "Created": "2019-12-29T15:18:01.807655262+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.1.1/24"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

设置PXC集群各个节点的存储卷

docker volume create mysql-v1
docker volume create mysql-v2
docker volume create mysql-v3

启动容器

启动Node1
docker run -d -p 3306:3306 \
-v mysql-v1:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e CLUSTER_NAME=PXC \
-e XTRABACKUP_PASSWORD=123456 \
--privileged --name=node1 --net=mysql-net --ip 172.18.1.2 \
mysql-pxc
启动Node2
docker run -d -p 3307:3306 \
-v mysql-v2:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e CLUSTER_NAME=PXC \
-e CLUSTER_JOIN=node1 \
-e XTRABACKUP_PASSWORD=123456 \
--privileged --name=node2 --net=mysql-net --ip 172.18.1.3 \
mysql-pxc
启动Node3
docker run -d -p 3308:3306 \
-v mysql-v3:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e CLUSTER_NAME=PXC \
-e CLUSTER_JOIN=node1 \
-e XTRABACKUP_PASSWORD=123456 \
--privileged --name=node3 --net=mysql-net --ip 172.18.1.4 \
mysql-pxc

搭建成功

你可能感兴趣的:(mysql,docker)