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.mzph.cn/news/875446.shtml

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

相关文章

企元数智引领新零售合规分销系统免费送

企元数智近日宣布推出全新的新零售合规分销系统&#xff0c;并免费向企业提供这一创新解决方案。这一举措旨在帮助更多企业实现数字化转型&#xff0c;提高管理效率&#xff0c;促进业务增长。 新零售合规分销系统是企元数智引领的一项全新数字解决方案&#xff0c;涵盖了销售数…

Linux第四节课(指令与权限)

1、date指令(时间) 程序运行到自己的每一个关键时刻&#xff0c;都要自己打日志&#xff01; 日志包括时间、日志等级、日志具体信息、其他信息等&#xff0c;然后按照行为单位写入文件中&#xff0c;这个文件被称为日志文件&#xff01; 在日志文件中筛选信息时&#xff0c…

【Unity国产化信创平台】虚拟机VMware Workstation Pro虚拟机下载安装

目录 一、虚拟机软件VMware Workstation Pro下载 二、虚拟机安装流程 1.傻瓜式安装 2.是否自动安装WHP 一、虚拟机软件VMware Workstation Pro下载 https://www.vmware.com/products/desktop-hypervisor/workstation-and-fusion 官网各种访问出错&#xff0c;下载界面总是…

H3CNE(vlan与子接口技术)

目录 10.1 vlan间通信技术 示例一&#xff08;多臂路由&#xff09;&#xff1a; 10.2 子接口技术 示例二&#xff08;子接口技术&#xff09;&#xff1a; 10.3 vlannif接口技术 10.3.1 三层交换机与VLANNIF技术 示例三VLANNIF配置&#xff08;将交换机当成路由器使用&…

DLMS/COSEM中公开密钥算法的使用_椭圆曲线加密法

1.概述 椭圆曲线密码涉及有限域上的椭圆曲线上的算术运算。椭圆曲线可以定义在任何数字域上(实数、整数、复数)&#xff0c;但在密码学中&#xff0c;椭圆曲线最常用于有限素数域。 素数域上的椭圆曲线由一组实数(x, y)组成&#xff0c;满足以下等式: 方程的所有解的集合构成…

Go语言---list的声明、常用方法以及遍历

List所在的库 Go语言的链表实现在其标准库的container/list代码包中。 import "container/list"这个包含了两个公开的程序实体&#xff1a;List和Element。 List代表一个双向链表&#xff0c;其零值为一个空的、可用的链表&#xff1b;Element代表双向链表中的一个…

Python | Leetcode Python题解之第279题完全平方数

题目&#xff1a; 题解&#xff1a; class Solution { public:// 判断是否为完全平方数bool isPerfectSquare(int x) {int y sqrt(x);return y * y x;}// 判断是否能表示为 4^k*(8m7)bool checkAnswer4(int x) {while (x % 4 0) {x / 4;}return x % 8 7;}int numSquares(i…

注册邮箱需要实名认证吗

注册邮箱需要进行实名认证吗&#xff1f;都需要认证哪些信息呢&#xff1f;邮箱实名认证提高安全性和责任感&#xff0c;但可能涉及隐私顾虑。本文将详细介绍邮箱实名认证的相关内容。 一、邮箱实名认证的定义和目的 1、定义 电子邮件实名验证是指客户在注册电子邮件服务时&…

初阶数据结构之栈和队列

栈和队列是两种特殊的线性表&#xff0c;都可以用数组或者链表来实现&#xff0c;接下来就让我们看看栈和队列会有什么奥秘吧~ 目录 1.栈 1.1栈的概念 1.2栈的实现 1.2.1 Stack.h 1.2.2 Stack.c 1.2.3 test.c 2.队列 2.1队列的概念 2.2队列的实现 2.2.1 Queue.h 2…

【科研】# Taylor Francis 论文 LaTeX template模版 及 Word模版

【科研写论文】系列 文章目录 【科研写论文】系列前言一、Word 模板&#xff08;附下载网址&#xff09;&#xff1a;二、LaTeX 版本方法1&#xff1a;直接网页端打开&#xff08;附网址&#xff09;方法2&#xff1a;直接下载到本地电脑上编辑下载地址说明及注意事项 前言 给…

【Gin】精准应用:Gin框架中工厂模式的现代软件开发策略与实施技巧(下)

【Gin】精准应用&#xff1a;Gin框架中工厂模式的现代软件开发策略与实施技巧(下) 大家好 我是寸铁&#x1f44a; 【Gin】精准应用&#xff1a;Gin框架中工厂模式的现代软件开发策略与实施技巧(下)✨ 喜欢的小伙伴可以点点关注 &#x1f49d; 前言 本次文章分为上下两部分&…

配置web服务器练习

4练习要求&#xff1a; 练习一&#xff1a;配置web服务器&#xff0c;当访问网站 www.haha.com 时显示&#xff1a;haha 练习二&#xff1a;配置web服务器&#xff0c;当访问网站 www.xixi.com/secret/ 时显示&#xff1a;this is secret 具体步骤&#xff1a; 1、配置yum…

压测实操--produce压测方案

作者&#xff1a;九月 环境信息&#xff1a; 操作系统centos7.9&#xff0c;kafka版本为hdp集群中的2.0版本。 Producer相关参数 使用Kafka自带的kafka-producer-perf-test.sh脚本进行压测&#xff0c;该脚本参数为&#xff1a; 在producer涉及到性能的关键因素可能会存在如…

记录|使用HslCommunication库进行写入Real数据的坑

项目场景&#xff1a; 现在已经通过HslCommunication连接上了PLC&#xff0c;需要对DB1.DBD10的位置处进行数据写入。 问题描述 但是进行将12.2写入指定位置DB1.DBD10时&#xff0c;发现无法从博图中实时检测到数据的写入。 下面是我当时错误的数据写入方法&#xff1a;【主…

光伏发电管理软件:光伏企业的核心驱动力

光伏产业面对日益增长的装机容量、复杂多变的运维需求以及激烈的市场竞争&#xff0c;光伏企业如何高效管理、优化运营、提升效益&#xff0c;成为了行业关注的焦点。在此背景下&#xff0c;鹧鸪云光伏发电管理软件应运而生&#xff0c;并逐渐成为光伏企业的核心驱动力。 一、提…

回文数-双指针

题目描述&#xff1a; 个人题解&#xff1a; 先将整数转换成字符串&#xff0c;再利用双指针逐一比较数字。 代码实现&#xff1a; class Solution { public:bool isPalindrome(int x) {if(x<0||(x%100&&x!0)){return false;}//c标准库调用&#xff0c;将整数下转…

opencv - py_calib3d - py_calibration 相机校准

文章目录 Camera Calibration 相机校准目标基础知识代码设置校准去失真1. 使用 **cv.undistort()**2. 使用 **remapping** 重新投影误差 Camera Calibration 相机校准 目标 在本节中&#xff0c;我们将学习 相机造成的失真类型如何找到相机的内在和外在属性如何根据这些属性…

防护勒索攻击:一场勒索攻击与智能防护的较量

近年来&#xff0c;云上数据安全已经成为企业的又一大难题&#xff0c;尤其是勒索攻击频发&#xff0c;有组织的黑客攻击目标已经从核心数据窃取扩展到金融、交通、能源、通信等行业的关键信息基础设施&#xff0c;对企业数据安全构成了极大的威胁和挑战。 同时AI时代&#xff…

tcache attack

Tcache Attack tcache让堆利用更加简单&#xff1a; tcache回顾&#xff1a; 在 tcache 中新增了两个结构体&#xff0c;分别是 tcache_entry 和 tcache_perthread_struct&#xff1a; /* We overlay this structure on the user-data portion of a chunk when the chunk is …

功能教学——如何快速理解并使用数据助手

在企业的数字化管理中&#xff0c;数据处理的重要性不容小觑。它如同一根红线&#xff0c;贯穿企业运营的各个环节&#xff0c;对于提升决策效率、优化运营流程以及增强市场竞争力等方面都发挥着至关重要的作用。而百数的数据助手&#xff0c;作为一款高效的数据处理工具&#…