• 在三台服务器上使用docker搭建集群


    集群环境搭建

    Minio集群

    参考-->minio
    所有节点配置主机名解析:

    cat >> /etc/hosts << EOF
    192.168.86.58 minio-1
    192.168.86.19 minio-2
    192.168.86.43 minio-3
    EOF
    

    使用docker run运行minio

    部署minio集群,3个节点每个节点挂载2个目录
    minio-1节点执行

    docker run -d --name minio \
      --restart=always --net=host \
      -e MINIO_ACCESS_KEY=minio \
      -e MINIO_SECRET_KEY=minio123 \
      -v minio-data1:/data1 \
      -v minio-data2:/data2 \
      minio/minio server \
      --address 192.168.86.58:9000 \
      http://minio-{1...3}/data{1...2}
    

    minio-2节点执行

    docker run -d --name minio \
      --restart=always --net=host \
      -e MINIO_ACCESS_KEY=minio \
      -e MINIO_SECRET_KEY=minio123 \
      -v minio-data1:/data1 \
      -v minio-data2:/data2 \
      minio/minio server \
      --address 192.168.86.19:9000 \
      http://minio-{1...3}/data{1...2}
    

    minio-3节点执行

    docker run -d --name minio \
      --restart=always --net=host \
      -e MINIO_ACCESS_KEY=minio \
      -e MINIO_SECRET_KEY=minio123 \
      -v minio-data1:/data1 \
      -v minio-data2:/data2 \
      minio/minio server \
      --address 192.168.92.12:9000 \
      http://minio-{1...3}/data{1...2}
    

    说明:docker部署集群模式时必须指定–net=host参数,使用主机网络,使用端口映射无法创建集群。

    使用docker-compose部署minio

    都要先更改/etc/hosts中的域名解析
    *在192.168.86.58上的docker-compose

    version: "3.2"
    services:
      minio3:
        container_name: minio
        image: minio/minio:RELEASE.2020-08-08T04-50-06Z
        restart: always
        volumes:
          - ./minio-data1:/data1
          - ./minio-data2:/data2
        ports:
          - "9000:9000"
        environment:
          MINIO_ACCESS_KEY: minio
          MINIO_SECRET_KEY: minio123
        command: server http://minio-{1...3}/data{1...2}
        healthcheck:
          test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
          interval: 30s
          timeout: 20s
          retries: 3
        network_mode: host
    

    其他两台的配置同上

    Nacos集群

    参考-->nacos

    主机 服务
    192.168.86.58 nacos01
    192.168.86.19 nacos02
    192.168.86.43 nacos03

    在主机为192.168.86.58上安装mysql(我安装的是mysql5.7.38)
    创建nacos数据库
    运行以下脚本:
    也可以在官方文档去找:
    https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql

    /*
     * Copyright 1999-2018 Alibaba Group Holding Ltd.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = config_info   */
    /******************************************/
    CREATE TABLE `config_info` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
      `data_id` varchar(255) NOT NULL COMMENT 'data_id',
      `group_id` varchar(255) DEFAULT NULL,
      `content` longtext NOT NULL COMMENT 'content',
      `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
      `src_user` text COMMENT 'source user',
      `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
      `app_name` varchar(128) DEFAULT NULL,
      `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
      `c_desc` varchar(256) DEFAULT NULL,
      `c_use` varchar(64) DEFAULT NULL,
      `effect` varchar(64) DEFAULT NULL,
      `type` varchar(64) DEFAULT NULL,
      `c_schema` text,
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = config_info_aggr   */
    /******************************************/
    CREATE TABLE `config_info_aggr` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
      `data_id` varchar(255) NOT NULL COMMENT 'data_id',
      `group_id` varchar(255) NOT NULL COMMENT 'group_id',
      `datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
      `content` longtext NOT NULL COMMENT '内容',
      `gmt_modified` datetime NOT NULL COMMENT '修改时间',
      `app_name` varchar(128) DEFAULT NULL,
      `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';
    
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = config_info_beta   */
    /******************************************/
    CREATE TABLE `config_info_beta` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
      `data_id` varchar(255) NOT NULL COMMENT 'data_id',
      `group_id` varchar(128) NOT NULL COMMENT 'group_id',
      `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
      `content` longtext NOT NULL COMMENT 'content',
      `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps',
      `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
      `src_user` text COMMENT 'source user',
      `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
      `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = config_info_tag   */
    /******************************************/
    CREATE TABLE `config_info_tag` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
      `data_id` varchar(255) NOT NULL COMMENT 'data_id',
      `group_id` varchar(128) NOT NULL COMMENT 'group_id',
      `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
      `tag_id` varchar(128) NOT NULL COMMENT 'tag_id',
      `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
      `content` longtext NOT NULL COMMENT 'content',
      `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
      `src_user` text COMMENT 'source user',
      `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = config_tags_relation   */
    /******************************************/
    CREATE TABLE `config_tags_relation` (
      `id` bigint(20) NOT NULL COMMENT 'id',
      `tag_name` varchar(128) NOT NULL COMMENT 'tag_name',
      `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',
      `data_id` varchar(255) NOT NULL COMMENT 'data_id',
      `group_id` varchar(128) NOT NULL COMMENT 'group_id',
      `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
      `nid` bigint(20) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`nid`),
      UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
      KEY `idx_tenant_id` (`tenant_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = group_capacity   */
    /******************************************/
    CREATE TABLE `group_capacity` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
      `group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
      `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
      `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
      `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
      `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
      `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
      `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_group_id` (`group_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = his_config_info   */
    /******************************************/
    CREATE TABLE `his_config_info` (
      `id` bigint(64) unsigned NOT NULL,
      `nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `data_id` varchar(255) NOT NULL,
      `group_id` varchar(128) NOT NULL,
      `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
      `content` longtext NOT NULL,
      `md5` varchar(32) DEFAULT NULL,
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `src_user` text,
      `src_ip` varchar(50) DEFAULT NULL,
      `op_type` char(10) DEFAULT NULL,
      `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
      PRIMARY KEY (`nid`),
      KEY `idx_gmt_create` (`gmt_create`),
      KEY `idx_gmt_modified` (`gmt_modified`),
      KEY `idx_did` (`data_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';
    
    
    /******************************************/
    /*   数据库全名 = nacos_config   */
    /*   表名称 = tenant_capacity   */
    /******************************************/
    CREATE TABLE `tenant_capacity` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
      `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',
      `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
      `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
      `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
      `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
      `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
      `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
      `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_tenant_id` (`tenant_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';
    
    
    CREATE TABLE `tenant_info` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
      `kp` varchar(128) NOT NULL COMMENT 'kp',
      `tenant_id` varchar(128) default '' COMMENT 'tenant_id',
      `tenant_name` varchar(128) default '' COMMENT 'tenant_name',
      `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',
      `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',
      `gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
      `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
      PRIMARY KEY (`id`),
      UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
      KEY `idx_tenant_id` (`tenant_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';
    
    CREATE TABLE `users` (
        `username` varchar(50) NOT NULL PRIMARY KEY,
        `password` varchar(500) NOT NULL,
        `enabled` boolean NOT NULL
    );
    
    CREATE TABLE `roles` (
        `username` varchar(50) NOT NULL,
        `role` varchar(50) NOT NULL,
        UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
    );
    
    CREATE TABLE `permissions` (
        `role` varchar(50) NOT NULL,
        `resource` varchar(255) NOT NULL,
        `action` varchar(8) NOT NULL,
        UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
    );
    
    INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
    
    INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
    

    在主机为192.168.86.58部署nacos01

    docker run -itd \
     -e PREFER_HOST_MODE=ip \
     -e MODE=cluster \
     -e NACOS_SERVERS="192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848" \
     -e SPRING_DATASOURCE_PLATFORM=mysql \
     -e MYSQL_SERVICE_HOST=192.168.86.58 \
     -e MYSQL_SERVICE_PORT=3306 \
     -e MYSQL_SERVICE_DB_NAME=nacos \
     -e MYSQL_SERVICE_USER=root \
     -e MYSQL_SERVICE_PASSWORD=root \
     -p 9901:8848 \
     --name nacos01 \
     --net host --ip 192.168.86.58 \
     --restart=always \
     nacos/nacos-server 
    

    在主机为192.168.86.19部署nacos02

    docker run -itd \
     -e PREFER_HOST_MODE=ip \
     -e MODE=cluster \
     -e NACOS_SERVERS="192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848" \
     -e SPRING_DATASOURCE_PLATFORM=mysql \
     -e MYSQL_SERVICE_HOST=192.168.86.58 \
     -e MYSQL_SERVICE_PORT=3306 \
     -e MYSQL_SERVICE_DB_NAME=nacos \
     -e MYSQL_SERVICE_USER=root \
     -e MYSQL_SERVICE_PASSWORD=root \
     -p 9901:8848 \
     --name nacos02 \
     --net host \
     --restart=always \
     nacos/nacos-server 
    

    在主机为192.168.86.43部署nacos03

    docker run -itd \
     -e PREFER_HOST_MODE=ip \
     -e MODE=cluster \
     -e NACOS_SERVERS="192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848" \
     -e SPRING_DATASOURCE_PLATFORM=mysql \
     -e MYSQL_SERVICE_HOST=192.168.86.58 \
     -e MYSQL_SERVICE_PORT=3306 \
     -e MYSQL_SERVICE_DB_NAME=nacos \
     -e MYSQL_SERVICE_USER=root \
     -e MYSQL_SERVICE_PASSWORD=root \
     -p 9901:8848 \
     --name nacos03 \
     --net host \
     --restart=always \
     nacos/nacos-server
    

    访问:http://ip:端口/nacos

    使用docker-compose部署nacos

    在192.168.86.58上的docker-compose

    version: "3"
    services:
      docker-nacos-3:
        image: nacos/nacos-server:latest
        container_name: nacos-server-3
        hostname: docker-nacos-3
        ports:
          - "8848:8848"
        restart: always
        volumes:
          - /app/nacos3/logs/:/home/nacos/logs
        environment:
          PREFER_HOST_MODE: ip #如果支 持主机名可以使用hostname,否则使用ip,默认也是ip
          NACOS_SERVERS: 192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848
          MYSQL_SERVICE_HOST: 192.168.86.58
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: root
          TIME_ZONE: Asia/Shanghai
        network_mode: host
    

    在192.168.86.19上的docker-compose

    version: "3"
    services:
      docker-nacos-3:
        image: nacos/nacos-server:latest
        container_name: nacos-server-3
        hostname: docker-nacos-3
        ports:
          - "8848:8848"
        restart: always
        volumes:
          - /app/nacos3/logs/:/home/nacos/logs
        environment:
          PREFER_HOST_MODE: ip #如果支 持主机名可以使用hostname,否则使用ip,默认也是ip
          NACOS_SERVERS: 192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848
          MYSQL_SERVICE_HOST: 192.168.86.58
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: root
          TIME_ZONE: Asia/Shanghai
        network_mode: host
    

    在192.168.86.43上的docker-compose

    version: "3"
    services:
      docker-nacos-3:
        image: nacos/nacos-server:latest
        container_name: nacos-server-3
        hostname: docker-nacos-3
        ports:
          - "8848:8848"
        restart: always
        volumes:
          - /app/nacos3/logs/:/home/nacos/logs
        environment:
          PREFER_HOST_MODE: ip #如果支 持主机名可以使用hostname,否则使用ip,默认也是ip
          NACOS_SERVERS: 192.168.86.58:8848 192.168.86.19:8848 192.168.86.43:8848
          MYSQL_SERVICE_HOST: 192.168.86.58
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: root
          TIME_ZONE: Asia/Shanghai
        network_mode: host
    

    Emqx集群

    参考-->emqx

    1. 拉取镜像
      docker pull emqx/emqx:v4.0.0
      在主机为192.168.86.58部署emqx01
    docker run -it --network host --name emqtt-master1-1 \
    -p 1883:1883 \
    -p 18083:18083 \
    -p 8083:8083 \
    -p 8883:8883 \
    -p 8080:8080 \
    -e EMQX_NAME="master1" \
    -e EMQX_HOST=192.168.86.58 \
    -e EMQX_LISTENER__TCP_EXTERNAL=1883 \
    -e EMQX_WAIT_TIME=30 \
    -e EMQX_CLUSTER__DISCOVERY="static" \
    -e EMQX_JOIN_CLUSTER="master1@192.168.86.58" \
    -e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
    emqx/emqx:v4.0.0
    

    在主机为192.168.86.19部署emqx02

    docker run -it --network host --name emqtt-master2-1 \
    -p 1883:1883 \
    -p 18083:18083 \
    -p 8083:8083 \
    -p 8883:8883 \
    -p 8080:8080 \
    -e EMQX_NAME="master2" \
    -e EMQX_HOST=192.168.86.19 \
    -e EMQX_LISTENER__TCP_EXTERNAL=1883 \
    -e EMQX_WAIT_TIME=30 \
    -e EMQX_CLUSTER__DISCOVERY="static" \
    -e EMQX_JOIN_CLUSTER="master2@192.168.86.19" \
    -e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
    emqx/emqx:v4.0.0
    

    在主机为192.168.86.43部署emqx03

    docker run -it --network host --name emqtt-master3-1 \
    -p 1883:1883 \
    -p 18083:18083 \
    -p 8083:8083 \
    -p 8883:8883 \
    -p 8080:8080 \
    -e EMQX_NAME="master2" \
    -e EMQX_HOST=192.168.86.43 \
    -e EMQX_LISTENER__TCP_EXTERNAL=1883 \
    -e EMQX_WAIT_TIME=30 \
    -e EMQX_CLUSTER__DISCOVERY="static" \
    -e EMQX_JOIN_CLUSTER="master3@192.168.86.43" \
    -e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
    emqx/emqx:v4.0.0
    

    使用docker-compose部署emqx

    在192.168.86.58上的docker-compose

    version: "3"
    services:
      emqx01:
        image: emqx/emqx:v4.0.0
        restart: always
        container_name: emqx01
        hostname: emqx01
        ports:
          - 8083:8083
          - 8080:8080
          - 8883:8883
          - 1883:1883
          - 18083:18083
        environment:
          - "EMQX_NAME=emqx01"
          - "EMQX_HOST=192.168.86.58"
          - "EMQX_LISTENER__TCP_EXTERNAL=1883"
          - "EMQX_WAIT_TIME=30"
          - "EMQX_CLUSTER__DISCOVERY=static"
          - "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
          - "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
        healthcheck:
          test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
          interval: 5s
          timeout: 25s
          retries: 5
        network_mode: host
    

    在192.168.86.19上的docker-compose

    version: "3"
    services:
      emqx01:
        image: emqx/emqx:v4.0.0
        restart: always
        container_name: emqx01
        hostname: emqx01
        ports:
          - 8083:8083
          - 8080:8080
          - 8883:8883
          - 1883:1883
          - 18083:18083
        environment:
          - "EMQX_NAME=emqx01"
          - "EMQX_HOST=192.168.86.19"
          - "EMQX_LISTENER__TCP_EXTERNAL=1883"
          - "EMQX_WAIT_TIME=30"
          - "EMQX_CLUSTER__DISCOVERY=static"
          - "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
          - "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
        healthcheck:
          test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
          interval: 5s
          timeout: 25s
          retries: 5
        network_mode: host
    

    在192.168.86.43上的docker-compose

    version: "3"
    services:
      emqx01:
        image: emqx/emqx:v4.0.0
        restart: always
        container_name: emqx01
        hostname: emqx01
        ports:
          - 8083:8083
          - 8080:8080
          - 8883:8883
          - 1883:1883
          - 18083:18083
        environment:
          - "EMQX_NAME=emqx01"
          - "EMQX_HOST=192.168.86.43"
          - "EMQX_LISTENER__TCP_EXTERNAL=1883"
          - "EMQX_WAIT_TIME=30"
          - "EMQX_CLUSTER__DISCOVERY=static"
          - "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
          - "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
        healthcheck:
          test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
          interval: 5s
          timeout: 25s
          retries: 5
        network_mode: host
    

    然后在网页打开ip:18083

    账号:admin
    密码:public

    Kafka集群

    参考-->kafka

    主机ip 服务
    192.168.86.58 Kafka1,zoo1
    192.168.86.19 Kafka2,zoo2
    192.168.86.43 Kafka,zoo3

    在主机为192.168.86.58部署kafka,zookeeper

    mkdir -p /data/deploy/kafkaCluster
    cd /data/deploy/kafkaCluster/
    vim docker-compose.yaml

    version: '3.1'
    services:
      zoo1:
        image: wurstmeister/zookeeper
        restart: always
        hostname: zoo1
        container_name: zoo1
        ports:
          - 2181:2181
          - 2888:2888
          - 3888:3888
        volumes:
          - /data/wangzunbin/volume/zkcluster/zoo1/data:/data:Z
          - /data/wangzunbin/volume/zkcluster/zoo1/datalog:/datalog:Z
        environment:
          ZOO_MY_ID: 1
          ZOO_SERVERS: server.1=192.168.86.58:2888:3888:2181 server.2=192.168.86.19:2888:3888:2181 server.3=192.168.86.43:2888:3888:2181
        network_mode: host
    
      kafka1:
        image: wurstmeister/kafka
        restart: always
        hostname: kafka1
        container_name: kafka1
        ports:
          - 9092:9092
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.86.58
          KAFKA_HOST_NAME: 192.168.86.58
          KAFKA_ADVERTISED_PORT: 9092
          KAFKA_BROKER_ID: 1
          KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.58:9092
          KAFKA_LISTENERS: PLAINTEXT://192.168.86.58:9092
        volumes:
          - /data/wangzunbin/volume/kfkluster/kafka1/logs:/kafka:Z
        network_mode: host
    

    启动: docker-compose up -d

    在主机IP为192.168.86.19服务器上部署zoo2、kafka2应用服务

    mkdir -p /data/deploy/kafkaCluster
    cd /data/deploy/kafkaCluster/
    vim docker-compose.yml

    version: '3.1'
    services:
      zoo2:
        image: wurstmeister/zookeeper
        restart: always
        hostname: zoo2
        container_name: zoo2
        ports:
          - 2181:2181
          - 2888:2888
          - 3888:3888
        volumes:
          - /data/wangzunbin/volume/zkcluster/zoo2/data:/data:Z
          - /data/wangzunbin/volume/zkcluster/zoo2/datalog:/datalog:Z
        environment:
          ZOO_MY_ID: 2
          ZOO_SERVERS: server.1=192.168.86.58:2888:3888;2181 server.2=192.168.86.19:2888:3888;2181 server.3=192.168.86.43:2888:3888;2181
        network_mode: host
    
      kafka2:
        image: wurstmeister/kafka
        restart: always
        hostname: kafka2
        container_name: kafka2
        ports:
          - 9092:9092
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.86.19
          KAFKA_HOST_NAME: 192.168.86.19
          KAFKA_ADVERTISED_PORT: 9092
          KAFKA_BROKER_ID: 2
          KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.19:9092
          KAFKA_LISTENERS: PLAINTEXT://192.168.86.19:9092
        volumes:
          - /data/wangzunbin/volume/kfkluster/kafka2/logs:/kafka:Z
        network_mode: host
    

    启动: docker-compose up -d

    在主机IP为192.168.86.43服务器上部署zoo3、kafka3应用服务

    mkdir -p /data/deploy/kafkaCluster
    cd /data/deploy/kafkaCluster/
    vim docker-compose.yml

    version: '3.1'
    services:
      zoo3:
        image: wurstmeister/zookeeper
        restart: always
        hostname: zoo3
        container_name: zoo3
        ports:
          - 2181:2181
          - 2888:2888
          - 3888:3888
        volumes:
          - /data/wangzunbin/volume/zkcluster/zoo3/data:/data:Z
          - /data/wangzunbin/volume/zkcluster/zoo3/datalog:/datalog:Z
        environment:
          ZOO_MY_ID: 3
          ZOO_SERVERS: server.1=192.168.86.58:2888:3888;2181 server.2=192.168.86.19:2888:3888;2181 server.3=192.168.86.43:2888:3888;2181
        network_mode: host
    
      kafka3:
        image: wurstmeister/kafka
        restart: always
        hostname: kafka3
        container_name: kafka3
        ports:
          - 9092:9092
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.86.43
          KAFKA_HOST_NAME: 192.168.86.43
          KAFKA_ADVERTISED_PORT: 9092
          KAFKA_BROKER_ID: 3
          KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.43:9092
          KAFKA_LISTENERS: PLAINTEXT://192.168.86.43:9092
        volumes:
          - /data/wangzunbin/volume/kfkluster/kafka3/logs:/kafka:Z
        network_mode: host
    

    启动: docker-compose up -d

    Redis集群

    参考-->redis

    分别在三台主机上创建如下文件和文件夹

    mkdir -p /usr/local/docker/redis
    cd /usr/local/docker/redis
    touch docker-compose.yaml
    vim docker-compose.yaml
    192.168.86.58的docker-compose.yaml

    version: '3'
    services:
      master:
        image: redis
        container_name: redis-master
        restart: always
        command: redis-server --port 6379 --requirepass test1234 --masterauth test1234 --appendonly yes
        ports:
          - 6379:6379
        privileged: true
        volumes:
          - /usr/local/docker/redis/data:/data
          - /usr/local/docker/redis/conf/:/usr/local/etc/redis/
    

    192.168.86.19的docker-compose.yaml

    version: '3'
    services:
      redis-slave1:
        image: redis
        container_name: redis-slave1
        restart: always
        command: redis-server --slaveof 192.168.86.58 6379 --port 6379 --requirepass test1234 --masterauth test1234 --appendonly yes
        ports:
          - 6379:6379
        privileged: true
        volumes:
          - /usr/local/docker/redis/data:/data
          - /usr/local/docker/redis/conf/:/usr/local/etc/redis/
    

    192.168.86.43的docker-compose.yaml

    version: '3'
    services:
      redis-slave2:
        image: redis
        container_name: redis-slave2
        restart: always
        command: redis-server --slaveof 192.168.86.58 6379 --port 6379 --requirepass test1234 --masterauth test1234 --appendonly yes
        ports:
          - 6379:6379
        privileged: true
        volumes:
          - /usr/local/docker/redis/data:/data
          - /usr/local/docker/redis/conf/:/usr/local/etc/redis/
    

    参数解释:
    privileged: true 权限
    requirepass test1234 访问本机需要的密码
    masterauth test1234 作为从机访问主机的密码
    appendonly yes 是否持久化

    docker-compose up -d 后台启动
    后面可以用docker ps查看容器是否正常启动
    docker-compose down 关闭

    进入docker exec -it redis-master bash
    输入redis-cli

    如果你更改了端口号,在进入集群的时候,要使用redis-cli -p 端口号(如果是6379就不用加-p)

    在输入info

    哨兵模式

    在/usr/local/docker/redis这个目录下创建新的文件夹sentinel
    mkdir sentinel
    cd sentinel
    touch sentinel.conf
    touch docker-compose.yml

    192.168.86.63的sentinel.conf编写:(其他两台服务器也可以使用26379,因为从属不同的服务器)

    # bind 127.0.0.1 192.168.1.1
    # protected-mode no
    port 26379
    #daemonize yes
    #pidfile /var/run/redis-sentinel.pid
    logfile "sentinel.log"
    sentinel monitor redis-master 192.168.86.58 6379 2
    sentinel auth-pass redis-master test1234
    sentinel down-after-milliseconds redis-master 10000
    
    sentinel announce-ip "192.168.86.58"
    sentinel announce-port 26379
    
    sentinel deny-scripts-reconfig yes
    

    其他两台的配置文件和上面的一样

    docker-compose.yaml文件
    192.168.86.58

    version: '3'
    services:
      redis-sentinel-1:
        image: redis
        container_name: redis-sentinel-1
        command: redis-sentinel /usr/local/etc/redis/sentinel.conf
        ports:
          - 26379:26379
    	privileged: true
        volumes:
          - /usr/local/docker/redis/sentinel:/usr/local/etc/redis/
    

    192.168.86.19

    version: '3'
    services:
      redis-sentinel-2:
        image: redis
        container_name: redis-sentinel-2
        command: redis-sentinel /usr/local/etc/redis/sentinel.conf
        ports:
          - 26379:26379
    	privileged: true
        volumes:
          - /usr/local/docker/redis/sentinel:/usr/local/etc/redis/
    

    192.168.86.43

    version: '3'
    services:
      redis-sentinel-3:
        image: redis
        container_name: redis-sentinel-3
        command: redis-sentinel /usr/local/etc/redis/sentinel.conf
        ports:
          - 26379:26379
    	privileged: true
        volumes:
          - /usr/local/docker/redis/sentinel:/usr/local/etc/redis/	
    

    启动哨兵:docker-compose up -d

    进入哨兵的容器中:
    docker exec -it 容器名称 bash
    进去集群: redis-cli -p 26379(你设置的端口,我设置的是26379)
    输入:info查看当前的配置信息

  • 相关阅读:
    [HTML] IE=edge,chrome=1的META标签详解
    [FFmpeg] ffmpeg 常用命令
    rsyncd 配置使用
    httpd配置
    ftp利用脚本添加本地用户
    zabbix监控概念
    搭建本地yum源并定时同步
    linux添加lvm磁盘大小,命令行创建swap
    500 OOPS: vsftpd: refusing to run with writable root inside chroot()
    利用saltstack批量安装clamav杀毒软件
  • 原文地址:https://www.cnblogs.com/linjiangplus/p/16415325.html
Copyright © 2020-2023  润新知