kafka 3.0.0
windows环境下:.\bin\windows\kafka-server-start.bat .\config\server.properties
启动报错如下:
ERROR Error while writing to checkpoint file D:\kafka\kafka_2.12-3.0.0\logs\log-start-offset-checkpoint (kafka.server.LogDirFailureChannel) java.nio.file.AccessDeniedException: D:\kafka\kafka_2.12-3.0.0\logs
经过尝试发现kafka3.0.0版本因自身问题在windows环境下启动存在问题,可将版本升至3.1.0
启动配置:
因kafka3.0之后内置zk所以不需要额外下载
第一步:配置文件修改
server.properties
# broker.id 要保持唯一,只启动一台的话则不需修改 # The id of the broker. This must be set to a unique integer for each broker. broker.id=0 # 修改日志存放位置 # A comma separated list of directories under which to store log files log.dirs=D://kafka//kafka_2.13-3.1.0//kafka-logs # 修改zk连接地址,默认本机启动则不需要修改 # 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.connect=localhost:2181
zookeeper.properties
# 修改日志存放位置 # 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=D://kafka//kafka_2.13-3.1.0//zookeeper-logs
第二步:启动
要先启动zk
启动语句
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
然后启动kafka
启动语句
.\bin\windows\kafka-server-start.bat .\config\server.properties
使用教程
进入/bin/windows 目录下通过下面的命令创建topic
kafka-topics.bat --bootstrap-server localhost:9092 --create --replication-factor 3 --partitions 1 --topic test
partitions:分区
replication-factor:设置分区副本
查看当前有哪些topic
kafka-topics.bat --bootstrap-server localhost:9092 --list
查看某个topic的详细信息
kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic test
修改topic的配置
kafka-topics.bat --bootstrap-server localhost:9092 --alter --topic test --partitions 3
删除topic会报错,此时停掉所有的cmd,然后将日志文件删除,重新启动可以解决
启动生产者命令/bin/window 目录下
kafka-console-producer.bat --broker-list localhost:9092 --topic test
启动消费者命令/bin/window 目录下
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
然后就可以快乐的发送啦