severalnines / galera-docker-mariadb

96 stars 88 forks source link

文档请求/Document request:Creat a healthy etcd cluster #20

Open zctmdc opened 1 year ago

zctmdc commented 1 year ago

For use etcd

etcd

docker 中创建 etcd,需要使用以下环境变量:environment --env -e ETCD_ENABLE_V2=true

docker compose file:

version: "3.0"

networks:
    net:
        # 网络
        driver: bridge # 桥接模式

volumes:
    data: # 挂载到本地的数据卷名
    data-324:

services:
    etcd-cluster:
        image: bitnami/etcd:3.5 # 镜像
        container_name: etcd-cluster # 容器名 --name
        restart: always # 总是重启
        networks:
            - net # 使用的网络 --network
        ports:
            # 端口映射 -p
            - ${your_private_ip}:2379:2379 # e.g.  - 2379:2379
            - ${your_private_ip}:2380:2380 # e.g.  - 2380:2380
        environment:
            # 环境变量 --env
            - ALLOW_NONE_AUTHENTICATION=yes # 允许不用密码登录
            - ETCD_ENABLE_V2=true # 这个参数是成功的关键 / This parameter is the key to success.
            - ETCD_NAME=etcd-node1 # etcd 的名字
            - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://${node1_domain_or_ip}:2380 # 列出这个成员的伙伴 URL 以便通告给集群的其他成员
            - ETCD_LISTEN_PEER_URLS=http://${your_private_ip}:2380 # 用于监听伙伴通讯的URL列表 e.g. http://0.0.0.0:2380
            - ETCD_LISTEN_CLIENT_URLS=http://${your_private_ip}:2379 # 用于监听客户端通讯的URL列表 e.g. http://0.0.0.0:2379
            - ETCD_ADVERTISE_CLIENT_URLS=http://${node1_domain_or_ip}:2379 # 列出这个成员的客户端URL,通告给集群中的其他成员
            - ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster # 在启动期间用于 etcd 集群的初始化集群记号
            - ETCD_INITIAL_CLUSTER=etcd-node1=http://${node1_domain_or_ip}:2380,etcd-node2=http://${node2_domain_or_ip}:2380 # 为启动初始化集群配置
            - ETCD_INITIAL_CLUSTER_STATE=existing # 初始化集群状态
        volumes:
            - data:/bitnami/etcd # 挂载的数据卷

mariadb-galera

在多网卡环境中需要指定 hostname extra_hosts multi-interface docker compose file:

version: "3.8"

# networks:
#     net:

volumes:
    data:

services:

    mariadb-galera:
        image: severalnines/mariadb
        container_name: mariadb-galera
        extra_hosts:
            - node1.example.org:${galera_node1_IP}
        hostname: node1.example.org
        environment:
            - CLUSTER_NAME=mariadb-galera
            - MYSQL_ROOT_PASSWORD=your_PASS
            - XTRABACKUP_PASSWORD=mypassword
            - MYSQL_USER=drone
            - MYSQL_USER_PASSWORD=your_PASS_2
            - MYSQL_USER_DATABASE=drone
            - DISCOVERY_SERVICE=${etcd_node1_IP}:2379,${etcd_node2_IP}:2379
        volumes:
            - data:/var/lib/mysql
        network_mode: host
        # networks:
        #     net:
        # ports:
        #     - ${galera_node1_IP}:3306:3306
        #     - ${galera_node1_IP}:4567:4567
        #     - ${galera_node1_IP}.59:4568:4568
        restart: unless-stopped