zookeeper
快来分享你的内容吧~
Kafka集群Windows配置
# 配置成功的效果 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/1nxq4aih-image.webp" alt="image.png" width="100%" /> ## 详细配置 ### 环境安装 当前Java软件开发中,主流的版本就是Java 8,而Kafka 3.X官方建议Java版本更新至Java11,但是Java8依然可用。未来Kafka 4.X版本会完全弃用Java8,不过,咱们当前学习的Kafka版本为3.6.1版本,所以使用Java8即可,无需升级。也可以使用Java8以上的版本 安装Kafka 下载软件安装包:kafka_2.12-3.6.1.tgz,[下载地址](https://kafka.apache.org/downloads) 这里演示版本是3.6.1,是Kafka软件的版本。 2.12是对应的Scala开发语言版本。Scala2.12和Java8是兼容的,所以可以直接使用。 tgz是一种linux系统中常见的压缩文件格式,类似与windows系统的zip和rar格式。所以Windows环境中可以直接使用压缩工具进行解压缩。 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/9Qlu9nox-image.webp" alt="image.png" width="100%" /> ## 解压文件 kafka_2.12-3.6.1.tgz,解压目录为非系统盘的根目录,比如e:/ <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/I5DsqhLr-image.webp" alt="image.png" width="100%" /> 为了访问方便,可以将解压后的文件目录改为kafka, 更改后的文件目录结构如下: | 文件夹名称 |功能 | | --- | --- | | bin | linux系统下可执行脚本文件 | | bin/windows | windows系统下可执行脚本文件 | |config|配置文件| |libs|依赖类库| |licenses|许可信息| |site-docs|文档| |logs|服务日志| (1)在磁盘根目录创建文件夹cluster,文件夹名称不要太长 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/NVO3Q7dn-image.png" alt="image.png" width="100%" /> (2)将kafka安装包kafka-3.6.1-src.tgz解压缩到kafka文件夹 ### 安装ZooKeeper (1)修改文件夹名为kafka-zookeeper 因为kafka内置了ZooKeeper软件,所以此处将解压缩的文件作为ZooKeeper软件使用。 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/imtlM0EC-image.webp" alt="image.png" width="282px" /> (2)修改config/zookeeper.properties文件 ``` # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # the directory where the snapshot is stored. # 此处注意,如果文件目录不存在,会自动创建 dataDir=E:/cluster/kafka-zookeeper/data # the port at which the clients will connect # ZooKeeper默认端口为2181 clientPort=2181 # disable the per-ip limit on the number of connections since this is a non-production config maxClientCnxns=0 # Disable the adminserver by default to avoid port conflicts. # Set the port to something non-conflicting if choosing to enable this admin.enableServer=false # admin.serverPort=8080 ``` ### 安装Kafka (1)将上面解压缩的文件复制一份,改名为kafka_broker_1 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/IfTzMYio-image.png" alt="image.png" width="100%" /> (2)修改config/server.properties配置文件 ```bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # # This configuration file is intended for use in ZK-based mode, where Apache ZooKeeper is required. # See kafka.server.KafkaConfig for additional details and defaults # ############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker. # kafka节点数字标识,集群内具有唯一性 broker.id=1 ############################# Socket Server Settings ############################# # The address the socket server listens on. If not configured, the host name will be equal to the value of # java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 # 监听器 9091为本地端口,如果冲突,请重新指定 listeners=PLAINTEXT://:9091 # Listener name, hostname and port the broker will advertise to clients. # If not set, it uses the value for "listeners". #advertised.listeners=PLAINTEXT://:9091 # Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details #listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL # The number of threads that the server uses for receiving requests from the network and sending responses to the network num.network.threads=3 # The number of threads that the server uses for processing requests, which may include disk I/O num.io.threads=8 # The send buffer (SO_SNDBUF) used by the socket server socket.send.buffer.bytes=102400 # The receive buffer (SO_RCVBUF) used by the socket server socket.receive.buffer.bytes=102400 # The maximum size of a request that the socket server will accept (protection against OOM) socket.request.max.bytes=104857600 ############################# Log Basics ############################# # A comma separated list of directories under which to store log files # 数据文件路径,如果不存在,会自动创建 log.dirs=E:/cluster/kafka-node-1/data # The default number of log partitions per topic. More partitions allow greater # parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1 # The number of threads per data directory to be used for log recovery at startup and flushing at shutdown. # This value is recommended to be increased for installations with data dirs located in RAID array. num.recovery.threads.per.data.dir=1 ############################# Internal Topic Settings ############################# # The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state" # For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3. offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 ############################# Log Flush Policy ############################# # Messages are immediately written to the filesystem but by default we only fsync() to sync # the OS cache lazily. The following configurations control the flush of data to disk. # There are a few important trade-offs here: # 1. Durability: Unflushed data may be lost if you are not using replication. # 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush. # 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks. # The settings below allow one to configure the flush policy to flush data after a period of time or # every N messages (or both). This can be done globally and overridden on a per-topic basis. # The number of messages to accept before forcing a flush of data to disk #log.flush.interval.messages=10000 # The maximum amount of time a message can sit in a log before we force a flush #log.flush.interval.ms=1000 ############################# Log Retention Policy ############################# # The following configurations control the disposal of log segments. The policy can # be set to delete segments after a period of time, or after a given size has accumulated. # A segment will be deleted whenever *either* of these criteria are met. Deletion always happens # from the end of the log. # The minimum age of a log file to be eligible for deletion due to age log.retention.hours=168 # A size-based retention policy for logs. Segments are pruned from the log unless the remaining # segments drop below log.retention.bytes. Functions independently of log.retention.hours. #log.retention.bytes=1073741824 # The maximum size of a log segment file. When this size is reached a new log segment will be created. #log.segment.bytes=1073741824 log.segment.bytes=190 log.flush.interval.messages=2 log.index.interval.bytes=17 # The interval at which log segments are checked to see if they can be deleted according # to the retention policies log.retention.check.interval.ms=300000 ############################# Zookeeper ############################# # Zookeeper connection string (see zookeeper docs for details). # This is a comma separated host:port pairs, each corresponding to a zk # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002". # You can also append an optional chroot string to the urls to specify the # root directory for all kafka znodes. # ZooKeeper软件连接地址,2181为默认的ZK端口号 /kafka 为ZK的管理节点 zookeeper.connect=localhost:2181/kafka # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=18000 ############################# Group Coordinator Settings ############################# # The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance. # The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms. # The default value for this is 3 seconds. # We override this to 0 here as it makes for a better out-of-the-box experience for development and testing. # However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup. group.initial.rebalance.delay.ms=0 ``` (3)将kafka_broker_1文件夹复制两份,改名为kafka_broker_2,kafka_broker_3 (4)分别修改kafka-node-2,kafka-node-3文件夹中的配置文件server.properties 将文件内容中的broker.id=1分别改为broker.id=2,broker.id=3 将文件内容中的9091分别改为9092,9093(如果端口冲突,请重新设置) 将文件内容中的kafka-node-1分别改为kafka-node-2,kafka-node-3 ## 封装启动脚本 因为Kafka启动前,必须先启动ZooKeeper,并且Kafka集群中有多个节点需要启动,所以启动过程比较繁琐,这里我们将启动的指令进行封装。 (1)在kafka-zookeeper文件夹下创建zk.cmd批处理文件 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/cEQgroV0-image.png" alt="image.png" width="100%" /> (2)在zk.cmd文件中添加内容 ```# 添加启动命令 call bin/windows/zookeeper-server-start.bat config/zookeeper.properties ``` (3)在kafka_broker_1,kafka_broker_2,kafka_broker_3文件夹下分别创建kfk.cmd批处理文件 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/Q4Z57hZQ-image.png" alt="image.png" width="100%" /> ```# 添加启动命令 call bin/windows/kafka-server-start.bat config/server.properties ``` (5)在cluster文件夹下创建cluster.cmd批处理文件,用于启动kafka集群 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/cnso0hf9-image.png" alt="image.png" width="100%" /> (6)在cluster.cmd文件中添加内容 ``` cd kafka_zookeeper start zk.cmd ping 127.0.0.1 -n 10 >nul cd ../kafka_broker_1 start kfk.cmd cd ../kafka_broker_2 start kfk.cmd cd ../kafka_broker_3 start kfk.cmd ``` (7)在cluster文件夹下创建cluster-clear.cmd批处理文件,用于清理和重置kafka数据 ``` cd kafka_zookeeper rd /s /q data cd ../kafka_broker_1 rd /s /q data cd ../kafka_broker_2 rd /s /q data cd ../kafka_broker_3 rd /s /q data ``` (9)双击执行cluster.cmd文件,启动Kafka集群 集群启动命令后,会打开多个黑窗口,每一个窗口都是一个kafka服务,请不要关闭,一旦关闭,对应的kafka服务就停止了。如果启动过程报错,主要是因为zookeeper和kafka的同步问题,请先执行cluster-clear.cmd文件,再执行cluster.cmd文件即可。 <img src="https://pic.code-nav.cn/post_picture/1623004460282298369/eJUDol8u-7a56fddbc5a334f2c18861f27e1f743.webp" alt="7a56fddbc5a334f2c18861f27e1f743.png" width="100%" />
#分享# #资源# #zookeeper# 最新zookeeper分享 「【尚硅谷】大数据技术之Zo...新付费课程))(1)」等文件 https://www.aliyundrive.com/s/LdTurv6V2jE 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。
