kafka_2.11-1.1.0 基礎環境搭建


下載與解壓

  1. 下載kafka安裝包,下載地址:https://www.apache.org/dyn/closer.cgi?path=/kafka/1.1.0/kafka_2.11-1.1.0.tgz
  2. 接下對應的安裝包到你的目錄(我的是:D:\devSoft\kafka_2.11-1.1.0)

修改配置文件

zookeeper配置文件修改

新版本的kafka自帶zookeeper。配置文件的位置在 kafka_2.11-1.1.0\config\zookeeper.properties。需要修改對應的dataDir指向的位置。

# 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=D:\devSoft\kafka_2.11-1.1.0\zookeeperData
# 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

kafka配置文件修改

kafka配置文件的位置在 kafka_2.11-1.1.0\config\server.properties。需要修改對應的dataDir指向的位置。

############################# Log Basics #############################

# A comma separated list of directories under which to store log files
log.dirs=D:\devSoft\kafka_2.11-1.1.0\server_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.

zookeeper啟動

安裝目錄kafka_2.11-1.1.0\bin\windows下執行zookeeper-server-start.bat ..\..\config\zookeeper.properties,默認端口(2181)在配置文件中已配置。

kafka啟動

安裝目錄kafka_2.11-1.1.0\bin\windows下執行kafka-server-start.bat ..\..\config/server.properties,默認端口(9092)

創建與查詢topic

安裝目錄kafka_2.11-1.1.0\bin\windows下執行kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topicDemo創建topicDemo主題。
安裝目錄kafka_2.11-1.1.0\bin\windows下執行kafka-topics.bat --list --zookeeper localhost:2181列出所有主題。

生產者啟動

安裝目錄kafka_2.11-1.1.0\bin\windows下執行kafka-console-producer.bat --broker-list localhost:9092 --topic topicDemo

消費者啟動

安裝目錄kafka_2.11-1.1.0\bin\windows下執行kafka-console-consumer.bat --zookeeper localhost:2181 --topic topicDemo --from-beginning

消息發送接收

測試生產者發送消息

測試消費者接收消息


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM