Docker-Compose配置zookeeper+KaFka+CMAK简单集群

1. 本地DNS解析管理

# 编辑hosts文件
sudo nano /etc/hosts
# 添加以下三个主机IP
192.168.186.77 zoo1 k1
192.168.186.18 zoo2 k2
192.168.186.216 zoo3 k3

注:zoo1是192.168.186.77的别名,zoo2是192.168.186.18的别名,zoo3是192.168.186.126的别名,IP自行修改即可,其他配置可以直接使用。

 2. 项目结构 

注:本文将宿主机的当前目录下的data目录挂载到容器的/data目录,data目录是需要自己创建且跟docker-compose.yml是平级关系,读者可以根据需求自行调整配置文件。

3. docker-compose.yml (Zookeeper集群)

3.1 主机1 (IP:192.168.186.77)

version: '3.8'  # 使用Docker Compose文件版本3.8services:zookeeper:  # 定义了一个服务image: "zookeeper:latest"  # 指定使用的Docker镜像为zookeeper的最新版hostname: zoo1  # 容器内的主机名container_name: zookeeper1  # Docker容器名称ports:- "2181:2181"  # 将容器的2181端口映射到宿主机的2181端口,用于客户端连接- "2888:2888"  # 将容器的2888端口映射到宿主机的2888端口,用于节点之间的数据同步- "3888:3888"  # 将容器的3888端口映射到宿主机的3888端口,用于集群中leader选举environment:ZOO_MY_ID: 1  # 设置该Zookeeper节点的ID为1,每个节点必须有一个唯一的IDZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181# 配置集群信息,定义了三个服务器的地址和端口配置ZOOKEEPER_CONF: |tickTime=2000  # Zookeeper服务器之间或客户端与服务器之间最长可以响应的时间间隔,以毫秒为单位initLimit=10  # Follower在启动过程中与Leader同步所能容忍的最多心跳数(tickTime的数量)syncLimit=5  # Follower与Leader之间发送消息、接收确认所能容忍的最多心跳数autopurge.snapRetainCount=3  # 自动清理功能,保留的快照数量autopurge.purgeInterval=1  # 清理快照的时间间隔,以小时为单位volumes:- ./data:/data  # 将宿主机的当前目录下的data目录挂载到容器的/data目录,用于数据存储restart: always  # 设置容器总是重启

 3.2 主机2 (IP:192.168.186.18)

version: '3.8'services:zookeeper:image: "zookeeper:latest"hostname: zoo2container_name: zookeeper2ports:- "2181:2181"- "2888:2888"- "3888:3888"environment:ZOO_MY_ID: 2ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181ZOOKEEPER_CONF: |tickTime=2000initLimit=10syncLimit=5autopurge.snapRetainCount=3autopurge.purgeInterval=1volumes:- ./data:/datarestart: always

 3.3 主机3 (IP:192.168.186.216)

version: '3.8'services:zookeeper:image: "zookeeper:latest"hostname: zoo3container_name: zookeeper3ports:- "2181:2181"- "2888:2888"- "3888:3888"environment:ZOO_MY_ID: 3ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181ZOOKEEPER_CONF: |tickTime=2000initLimit=10syncLimit=5autopurge.snapRetainCount=3autopurge.purgeInterval=1volumes:- ./data:/datarestart: always

3.4 运行结果

4.1 主机1

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose up -d
[+] Running 9/9
 ✔ zookeeper 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                      

.......
liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose ps
NAME                IMAGE               COMMAND                  SERVICE             CREATED             STATUS              PORTS
zookeeper3          zookeeper:latest    "/docker-entrypoint.…"   zookeeper           29 seconds ago      Up 24 seconds       0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 0.0.0.0:2888->2888/tcp, :::2888->2888/tcp, 0.0.0.0:3888->3888/tcp, :::3888->3888/tcp, 8080/tcp

liber@liber-VMware-Virtual-Platform:/home/zookeeper$  docker-compose exec zookeeper zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

4.2 主机2

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose up -d
[+] Running 0/1
[+] Running 9/9lling                                                                                                                   .......

liber@liber-VMware-Virtual-Platform:/home/zookeeper$  docker-compose exec zookeeper zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader 

4.3 主机3

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose up -d
[+] Running 9/9
 ✔ zookeeper 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                       ......
liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose ps
NAME                IMAGE               COMMAND                  SERVICE             CREATED             STATUS              PORTS
zookeeper3          zookeeper:latest    "/docker-entrypoint.…"   zookeeper           29 seconds ago      Up 24 seconds       0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 0.0.0.0:2888->2888/tcp, :::2888->2888/tcp, 0.0.0.0:3888->3888/tcp, :::3888->3888/tcp, 8080/tcp
liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose logs 
zookeeper3  | ZooKeeper JMX enabled by default
zookeeper3  | Using config: /conf/zoo.cfg
zookeeper3  | 2024-07-21 03:17:03,935 [myid:] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: /conf/zoo.cfg
zookeeper3  | 2024-07-21 03:17:03,948 [myid:] - INFO  [main:QuorumPeerConfig@435] - clientPort is not set
zookeeper3  | 2024-07-21 03:17:03,949 [myid:] - INFO  [main:QuorumPeerConfig@448] - secureClientPort is not set
zookeeper3  | 2024-07-21 03:17:03,949 [myid:] - INFO  [main:QuorumPeerConfig@464] - observerMasterPort is not set
zookeeper3  | 2024-07-21 03:17:03,953 [myid:] - INFO  [main:QuorumPeerConfig@481] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
zookeeper3  | 2024-07-21 03:17:04,021 [myid:3] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
.......

liber@liber-VMware-Virtual-Platform:/home/zookeeper$  docker-compose exec zookeeper zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

4.4 标红代码的作用

        docker-compose up -d命令会启动docker-compose.yml文件中定义的所有服务。如果服务所依赖的镜像尚未被下载,Docker Compose会自动从Docker Hub或指定的镜像仓库拉取,-d 参数确保容器在后台运行。docker-compose logs查看正在运行的服务的日志。docker-compose ps查看容器的状态。docker-compose exec zookeeper zkServer.sh status获取 Zookeeper 实例的当前状态和角色信息

5.docker-compose.yml(zookeeper集群+Kafka集群)

5.1 主机1 (IP:192.168.186.77)

services:zookeeper:image: "zookeeper:latest"  # 使用Docker Hub上的最新官方Zookeeper镜像。hostname: zoo1             # 容器内的主机名设置为 zoo1。container_name: zookeeper1 # 设置 Docker 容器的名称为 zookeeper1。ports:- "2181:2181"  # 将容器的 2181 端口映射到宿主机的同一端口,Zookeeper 客户端连接端口。- "2888:2888"  # 用于集群中的服务器之间相互通信的端口。- "3888:3888"  # 用于选举 leader 时使用的端口。environment:ZOO_MY_ID: 1   # 设置此 Zookeeper 实例的服务器 ID 为 1。ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181 # 配置集群中所有 Zookeeper 服务器的地址和端口。volumes:- ./data:/data # 将宿主机当前目录下的data目录挂载到容器的/data目录,用于数据持久化。restart: always  # 设置容器总是重新启动。kafka:image: "wurstmeister/kafka:latest"  #使用Docker Hub上的最新wurstmeister/kafka镜像。hostname: k1                        # 设置容器的主机名为 k1。container_name: kafka1              # 设置Docker容器的名称为kafka1。ports:- "9092:9092"  # 将容器的9092端口映射到宿主机的同一端口,Kafka broker监听端口。environment:KAFKA_BROKER_ID: 1                     # Kafka broker的唯一标识符。KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181 # 连接到Zookeeper集群的地址,用于管理Kafka的状态和配置。KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092   # Kafka对内部通信开放的接口和端口。KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://k1:9092 # Kafka对外广播的接口和端口,通知给生产者和消费者。KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true' # 允许自动创建主题。volumes:- /var/run/docker.sock:/var/run/docker.sock # 将宿主机的Docker套接字文件挂载到容器内部,允许Kafka容器内操作宿主机的Docker实例。depends_on:- zookeeper                            # 确保在启动Kafka服务前Zookeeper服务已经启动。restart: always                          # 设置容器总是重新启动。

5.2 主机2 (IP:192.168.186.18)

services:zookeeper:image: "zookeeper:latest"hostname: zoo2container_name: zookeeper2ports:- "2181:2181"- "2888:2888"- "3888:3888"environment:ZOO_MY_ID: 2ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./data:/datarestart: alwayskafka:image: "wurstmeister/kafka:latest"hostname: k2  container_name: kafka2ports:- "9092:9092"environment:KAFKA_BROKER_ID: 2KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://k2:9092 KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'volumes:- /var/run/docker.sock:/var/run/docker.sockdepends_on:- zookeeperrestart: always

5.3 主机3 (IP:192.168.186.216)

services:zookeeper:image: "zookeeper:latest"hostname: zoo3container_name: zookeeper3ports:- "2181:2181"- "2888:2888"- "3888:3888"environment:ZOO_MY_ID: 3ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./data:/datarestart: alwayskafka:image: "wurstmeister/kafka:latest"hostname: k3  container_name: kafka3ports:- "9092:9092"environment:KAFKA_BROKER_ID: 3KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://k3:9092KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'volumes:- /var/run/docker.sock:/var/run/docker.sockdepends_on:- zookeeperrestart: always

 5.4 验证kafka集群

5.4.1 进入Kafka容器
docker-compose exec kafka /bin/bash
5.4.2 查看集群中的 brokers
 kafka-broker-api-versions.sh --bootstrap-server localhost:9092

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose exec kafka /bin/bash

bash-5.1# kafka-broker-api-versions.sh --bootstrap-server localhost:9092
k3:9092 (id: 3 rack: null) -> (
        Produce(0): 0 to 9 [usable: 9],
        ......
        OffsetDelete(47): 0 [usable: 0],
        DescribeClientQuotas(48): 0 to 1 [usable: 1],
        AlterClientQuotas(49): 0 to 1 [usable: 1],
        DescribeUserScramCredentials(50): 0 [usable: 0],
        AlterUserScramCredentials(51): 0 [usable: 0],
        AlterIsr(56): 0 [usable: 0],
        UpdateFeatures(57): 0 [usable: 0],
        DescribeCluster(60): 0 [usable: 0],
        DescribeProducers(61): 0 [usable: 0]
)
k2:9092 (id: 2 rack: null) -> (
        Produce(0): 0 to 9 [usable: 9],
        Fetch(1): 0 to 12 [usable: 12],
        ListOffsets(2): 0 to 6 [usable: 6],
        Metadata(3): 0 to 11 [usable: 11],
        ........
        InitProducerId(22): 0 to 4 [usable: 4],
        OffsetForLeaderEpoch(23): 0 to 4 [usable: 4],
        AddPartitionsToTxn(24): 0 to 3 [usable: 3],
        AddOffsetsToTxn(25): 0 to 3 [usable: 3],
        EndTxn(26): 0 to 3 [usable: 3],
        WriteTxnMarkers(27): 0 to 1 [usable: 1],
        TxnOffsetCommit(28): 0 to 3 [usable: 3],
        DescribeAcls(29): 0 to 2 [usable: 2],
        CreateAcls(30): 0 to 2 [usable: 2],
        DeleteAcls(31): 0 to 2 [usable: 2],
        DescribeConfigs(32): 0 to 4 [usable: 4],
        AlterConfigs(33): 0 to 2 [usable: 2],
        AlterReplicaLogDirs(34): 0 to 2 [usable: 2],
        DescribeLogDirs(35): 0 to 2 [usable: 2],
        SaslAuthenticate(36): 0 to 2 [usable: 2],
        CreatePartitions(37): 0 to 3 [usable: 3],
        CreateDelegationToken(38): 0 to 2 [usable: 2],
        RenewDelegationToken(39): 0 to 2 [usable: 2],
        ExpireDelegationToken(40): 0 to 2 [usable: 2],
        DescribeDelegationToken(41): 0 to 2 [usable: 2],
        DeleteGroups(42): 0 to 2 [usable: 2],
        ElectLeaders(43): 0 to 2 [usable: 2],
        IncrementalAlterConfigs(44): 0 to 1 [usable: 1],
        AlterPartitionReassignments(45): 0 [usable: 0],
        ListPartitionReassignments(46): 0 [usable: 0],
        OffsetDelete(47): 0 [usable: 0],
        DescribeClientQuotas(48): 0 to 1 [usable: 1],
        AlterClientQuotas(49): 0 to 1 [usable: 1],
        DescribeUserScramCredentials(50): 0 [usable: 0],
        AlterUserScramCredentials(51): 0 [usable: 0],
        AlterIsr(56): 0 [usable: 0],
        UpdateFeatures(57): 0 [usable: 0],
        DescribeCluster(60): 0 [usable: 0],
        DescribeProducers(61): 0 [usable: 0]
)
k1:9092 (id: 1 rack: null) -> (
        Produce(0): 0 to 9 [usable: 9],
        Fetch(1): 0 to 12 [usable: 12],
        ListOffsets(2): 0 to 6 [usable: 6],
        Metadata(3): 0 to 11 [usable: 11],
        LeaderAndIsr(4): 0 to 5 [usable: 5],
        StopReplica(5): 0 to 3 [usable: 3],
        UpdateMetadata(6): 0 to 7 [usable: 7],
        ControlledShutdown(7): 0 to 3 [usable: 3],
        OffsetCommit(8): 0 to 8 [usable: 8],
        .........
        InitProducerId(22): 0 to 4 [usable: 4],
        OffsetForLeaderEpoch(23): 0 to 4 [usable: 4],
        .........
        UpdateFeatures(57): 0 [usable: 0],
        DescribeCluster(60): 0 [usable: 0],
        DescribeProducers(61): 0 [usable: 0]
)

5.4.3 创建主题
kafka-topics.sh --create --topic test --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092
5.4.4 查看主题详细信息

主机1创建:

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose exec kafka /bin/bash
bash-5.1# kafka-topics.sh --create --topic test --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092
Error while executing topic command : Topic 'test' already exists.
[2024-07-21 07:06:13,536] ERROR org.apache.kafka.common.errors.TopicExistsException: Topic 'test' already exists.
 (kafka.admin.TopicCommand$)
bash-5.1# kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092
Topic: test     TopicId: AIpDyj5rTlyuMXFTPmdQFg PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: test     Partition: 0    Leader: 3       Replicas: 3     Isr: 3

2.主机2查询:

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose exec kafka /bin/bash
bash-5.1# kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092
Topic: test     TopicId: AIpDyj5rTlyuMXFTPmdQFg PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: test     Partition: 0    Leader: 3       Replicas: 3     Isr: 3

 

5.5.5 其他验证方法 
# 进入zooper容器
docker-compose exec zookeeper zkCli.sh -server localhost:2181# 查询brokers所有节点id
ls /brokers/ids

liber@liber-VMware-Virtual-Platform:/home/zookeeper$ docker-compose exec zookeeper zkCli.sh -server localhost:2181
Connecting to localhost:2181
2024-07-21 07:22:47,180 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2024-07-21 07:22:47,189 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=zoo2
2024-07-21 07:22:47,191 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=11.0.13
2024-07-21 07:22:47,199 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2024-07-21 07:22:47,201 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/local/openjdk-11
2024-07-21 07:22:47,204 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/classes:/apache-zookeeper-3.7.0-bin/bin/../build/classes:/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/lib/*.jar:/apache-zookeeper-3.7.0-bin/bin/../build/lib/*.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-jute-3.7.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-3.7.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-log4j12-1.7.30.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient-0.9.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-resolver-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-handler-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-common-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-codec-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/netty-buffer-4.1.59.Final.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/log4j-1.2.17.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jline-2.14.6.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-server-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-security-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-io-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-http-9.4.38.v20210224.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-core-2.10.5.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-annotations-2.10.5.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/commons-cli-1.4.jar:/apache-zookeeper-3.7.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/apache-zookeeper-3.7.0-bin/bin/../zookeeper-*.jar:/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/conf:
2024-07-21 07:22:47,207 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
2024-07-21 07:22:47,209 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2024-07-21 07:22:47,209 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2024-07-21 07:22:47,210 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2024-07-21 07:22:47,211 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2024-07-21 07:22:47,211 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=6.8.0-31-generic
2024-07-21 07:22:47,213 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2024-07-21 07:22:47,213 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2024-07-21 07:22:47,215 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/apache-zookeeper-3.7.0-bin
2024-07-21 07:22:47,215 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=61MB
2024-07-21 07:22:47,223 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=256MB
2024-07-21 07:22:47,224 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=64MB
2024-07-21 07:22:47,234 [myid:] - INFO  [main:ZooKeeper@637] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7946e1f4
2024-07-21 07:22:47,249 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2024-07-21 07:22:47,266 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2024-07-21 07:22:47,292 [myid:] - INFO  [main:ClientCnxn@1726] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
JLine support is enabled
2024-07-21 07:22:47,384 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.
2024-07-21 07:22:47,401 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2024-07-21 07:22:47,449 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:36038, server: localhost/0:0:0:0:0:0:0:1:2181
2024-07-21 07:22:47,499 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1438] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, session id = 0x200023e46880000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /brokers/ids 
[1, 2, 3]
[zk: localhost:2181(CONNECTED) 1] 
 

6. CMAK管理工具

6.1 主机1 (IP:192.168.186.77)

services:zookeeper:image: "zookeeper:latest"hostname: zoo1container_name: zookeeper1ports:- "2181:2181"- "2888:2888"- "3888:3888"environment:ZOO_MY_ID: 1ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./data:/datarestart: alwayskafka:image: "wurstmeister/kafka:latest"hostname: k1container_name: kafka1ports:- "9092:9092"environment:KAFKA_BROKER_ID: 1KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://k1:9092KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'volumes:- /var/run/docker.sock:/var/run/docker.sockdepends_on:- zookeeperrestart: alwayscmak:image: hlebalbau/kafka-manager:latest  # 使用Docker Hub上的最新CMAK镜像hostname: cmakcontainer_name: cmakports:- "9000:9000"  # 将容器的9000端口映射到宿主机的同一端口environment:ZK_HOSTS: "zoo1:2181,zoo2:2181,zoo3:2181"  # 配置连接到Zookeeper的地址APPLICATION_SECRET: "random-secret"  # 一个随机字符串,用作应用的密钥depends_on:- zookeeperrestart: always

注:只演示一个主机,如果需要自行修改配置文件。 

6.3 浏览器访问

         添加集群,主要是zookeeper的集群。

6.2 运行结果

7. 总结

        基于Ubuntu24.04 TLS稳定版进行测试安装,仅供参考学习。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/383579.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

react中组件间的通信

一、父传子 1.代码展示 import React, { useState } from react;function SonPage(props){ // 子组件const {msg} propsreturn (<div>我是子组件 {msg}</div>) }function App() { // 父组件const [msgText,setMsgText] useState(父传子)return (<div classN…

全国区块链职业技能大赛第八套区块链产品需求分析与方案设计

任务1-1:区块链产品需求分析与方案设计 医疗健康平台中涉及到医院、医生、患者等参与方,他们需要在区块链医疗健康平台中完成账户注册、身份上链、挂号就诊、查询病例等多种业务活动。通过对业务活动的功能分析,可以更好的服务系统的开发流程。基于医疗健康平台系统架构,以…

Vue3可媲美Element Plus Tree组件开发之append节点

在前面的章节&#xff0c;我们完成了可媲美Element Plus Tree组件的基本开发。通过实现各种计算属性&#xff0c;tree数据状态变化引起的视图更新被计算属性所接管了&#xff0c;无需我们再手动做各种遍历、查找以及手动监听操作&#xff0c;这样后续开发高级功能变得易如反掌啦…

kafka架构+原理+源码

1.安装jdk17 sudo yum -y update sudo wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm sudo yum -y install ./jdk-17_linux-x64_bin.rpm、 sudo java -version 2.安装kafka How to easily install kafka without zookeeper | Aditya’s Blog …

好用的资产管理系统 国内5款资产管理系统排名

选择合适的固定资产管理系统对于企业的资产跟踪和维护至关重要。市场上有许多优秀的资产管理系统&#xff0c;每款系统都有其独特的功能和优势。本文将盘点5个好用的固定资产管理系统排名不分先后&#xff0c;帮助您了解它们的主要特点和适用场景&#xff0c;从而选择最适合您企…

【Java 数据结构】ArrayList类介绍

ArrayList类介绍 初识List接口ArrayList类ArrayList类是什么顺序表的模拟实现初始化增加元素删除元素查找元素修改元素 ArrayList类使用构造方法ArrayList源码阅读常用方法及其注意事项 初识List接口 List 是集合框架中的一个接口, 它的里面包含了一些方法, 例如add(), remove…

JAVA项目样本

学生管理系统SISM-v2.0 项目构建 ebtity 学生类:属性,setter,getter,toString(),构造器… dao层 数据交互,数组CRUD(增删改查) 接口 实现

《Techporters架构搭建》-Day03 功能权限设计

功能权限设计 引言权限介绍什么是权限权限的作用 RBAC概述RBAC的组成RBAC支持的安全原则RBAC模型 基于RBAC的权限设计用户管理角色管理菜单管理部门管理岗位管理 权限系统设计ER图标准RBAC模型表复杂RBAC模型表 多租户架构什么是多租户&#xff1f;多租户特点多租户模型竖井隔离…

汽车免拆诊断案例 | 2014 款上汽名爵 GT 车发动机无法起动

故障现象 一辆2014款上汽名爵GT车&#xff0c;搭载15S4G发动机&#xff0c;累计行驶里程约为18.4万km。该车因左前部发生碰撞事故进厂维修&#xff0c;更换损坏的部件后起动发动机&#xff0c;起动机运转有力&#xff0c;但无着机迹象。用故障检测仪检测&#xff0c;发现无法与…

(leetcode学习)236. 二叉树的最近公共祖先

给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个节点 p、q&#xff0c;最近公共祖先表示为一个节点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可能大&#xff08;一个节点也可以是它自己的祖…

【BUG】已解决:TypeError: the JSON object must be str, bytes or bytearray, not dict

已解决&#xff1a;TypeError: the JSON object must be str, bytes or bytearray, not dict 目录 已解决&#xff1a;TypeError: the JSON object must be str, bytes or bytearray, not dict 【常见模块错误】 错误原因&#xff1a; 解决方案&#xff1a; 欢迎来到英杰社区…

2024最新手机软件APP下载排行网站源码 软件下载站PHP源码

源码介绍 这是一款简洁蓝色的手机软件下载应用排行、平台和最新发布网站源码&#xff0c;主要包括主页、APP列表页、APP详情介绍页、新闻资讯列表、新闻详情页、关于我们等模块页面。 软件下载站PHP网站源码&#xff0c;简单的部署上线&#xff0c;访问首页安装程序&#xff…

探索PyMuPDF:Python中的强大PDF处理库

探索PyMuPDF&#xff1a;Python中的强大PDF处理库 背景&#xff1a;为何选择PyMuPDF 在数字化时代&#xff0c;PDF文件因其跨平台的兼容性和对格式的严格保持而成为文档交换的通用格式。然而&#xff0c;处理PDF文件往往需要专门的工具或库。这就是PyMuPDF库的用武之地。PyMuP…

飞书群聊机器人自定义机器人接入,并实现艾特@群成员功能

飞书群聊机器人还是比钉钉的要麻烦一点&#xff0c;钉钉的直接通过手机号就可以艾特群里面的人&#xff0c;但是飞书的要想艾特群里面的人&#xff0c;需要使用用户的 Open ID 或 User ID。这两个ID怎么获取呢&#xff1f;还需要在飞书的开放平台上创建一个应用&#xff0c;然后…

【MySQL是怎样运行的 | 第二篇】MySQL三大日志文件

文章目录 2.MySQL三大日志文件2.1日志文件列表2.1.1 redo log2.1.2 bin log2.1.3 undo log 2.2redo log日志详讲2.3 binglog和redo log有什么区别&#xff1f;2.4一条更新语句的执行过程 2.MySQL三大日志文件 2.1日志文件列表 redo log&#xff1a;重做日志&#xff0c;记录了…

mysql面试(五)

前言 本章节从数据页的具体结构&#xff0c;分析到如何生成索引&#xff0c;如何构成B树的索引结构。 以及什么是聚簇索引&#xff0c;什么是联合索引 InnoDB数据结构 行数据 我看各种文档中有好多记录数据结构的&#xff0c;但是这些都是看完就忘的东西。在这里详细讲也没…

深度学习复盘与论文复现E

文章目录 一、项目复现的问题及其解决方案1、 Cannot find DGL C graphbolt library2、 “is“ with a literal. Did you mean ““?”3、运行SEG、SPG查看GATNet的网络结构4、关于LI-FPN项目找不到数据粒度不匹配问题5、关于LI-FPN项目num_samples为空6、解决路径问题7、 !ss…

Fork软件笔记:一键拉取仓库所有模块

Fork是一个好用的git工具&#xff0c;只是没有中文而已&#xff08;不过不用翻译也能看使用&#xff09;。 工具下载地址&#xff1a;https://fork.dev/ 界面展示&#xff1a; 当项目中仓库模块比较多时&#xff0c;可以看到每个模块都是一个分页&#xff0c;每一个都要手动切换…

Git 分布式版本控制系统、创建分支,跳转分支、git拉取、在码云上创建项目,进行pull 和 push、克隆码云上任意项目

目录 1.Git 分布式版本控制系统&#xff1a; 1.安装git 2.创建目录&#xff0c;进行初始化 3.写入Java文件&#xff0c;提交文件 4.文件放入仓库 2.创建分支&#xff0c;跳转分支&#xff08;所有的git操作都应该工作在&#xff0c;指定的init 目录下进行&#xff09; 1.…

【前端学习笔记】CSS基础一

一、什么是CSS 1.CSS 介绍 CSS&#xff08;Cascading Style Sheets&#xff0c;层叠样式表&#xff09;是一种用来控制网页布局和设计外观的样式语言。它使得开发者可以分离网页的内容&#xff08;HTML&#xff09;和表现形式&#xff08;样式&#xff09;&#xff0c;提高了…