03.Kafka Windows初体验
Step1:下载kafka组件
访问http://kafka.apache.org/官网,下载相应的版本
我的文件目录如下,下面的文件路径也是基于此,按照自己的实际文件路径自行更改

Step2:启动ZooKeeper实例,启动Broker
zookeeper-server-start.bat ..\..\config\zookeeper.properties
kafka-server-start.bat ..\..\config\server.properties
部分配置文件
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=/tmp/zookeeper # the port at which the clients will connect clientPort=2181 # disable the per-ip limit on the number of connections since this is a non-production config maxClientCnxns=0
server.properties
# The id of the broker. This must be set to a unique integer for each broker. broker.id=0 # The number of threads handling network requests num.network.threads=3 # The number of threads doing 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 # A comma seperated list of directories under which to store log files log.dirs=/tmp/kafka-logs # 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 # The minimum age of a log file to be eligible for deletion log.retention.hours=168 # A size-based retention policy for logs. Segments are pruned from the log as long as the remaining # segments don't drop below log.retention.bytes. #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 # 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 # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002". zookeeper.connect=localhost:2181 # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=6000
Step3:创建Topic
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Step4:启动producer发送消息
kafka-console-producer.bat --broker-list localhost:9092 --topic test
Step5:启动Consumer接收消息
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
------------------------------------------华丽丽的分割线----------------------------------------------------
以上是单个的broker,下面我们进行创建多broker的集群
Step6:创建两个broker
复制两份server.properties分别为server-1.properties和server-2.properties
两个配配置文件其他位置与server.properties相同,不同之处如下
#config/server-1.properties: broker.id=1 listeners=PLAINTEXT://:9093 log.dirs=/tmp/kafka-logs-1
#config/server-2.properties: broker.id=2 listeners=PLAINTEXT://:9094 log.dirs=/tmp/kafka-logs-2
启动zookeeper启动两个broker
zookeeper-server-start.bat ..\..\config\zookeeper.properties
kafka-server-start.bat ..\..\config\server-1.properties
kafka-server-start.bat ..\..\config\server-2.properties
Step7:创建新的topic
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic my-replicated-topic
Step8:启动producer发送消息
kafka-console-producer.bat --broker-list localhost:9093,localhost:9094 --topic my-replicated-topic
Step9:启动Consumer接收消息
kafka-console-consumer.bat --zookeeper localhost:2181 --topic my-replicated-topic --from-beginning
Step10:我们关掉server-1或者server-2中的其中一个仍然可以收发消息
http://www.cnblogs.com/makexu/

浙公网安备 33010602011771号