kafka入門教程

2021-10-05 00:14:56 字數 4003 閱讀 8085

1,安裝zookeeper

由於kafka依賴於zookeeper·,所以需要先安裝zookeeper

1.1 選擇目錄解壓zookeeper·安裝包 比如(/usr/yyj/zookeeper)

tar -zxvf zookeeper-3.4.5.tar.gz
1.2 修改zookeeper配置檔案

先進入zookeeper的conf目錄

cd /usr/yyj/zookeeper/zookeeper-3.4.5
然後複製zoo檔案

cp zoo_sample.cfg zoo.cfg
之後編輯zoo.cfg檔案

vim zoo.cfg
修改datadir引數

# the number of milliseconds of each tick

ticktime=2000

# the number of ticks that the initial

# synchronization phase can take

initlimit=10

# the number of ticks that can pass between

# sending a request and getting an acknowledgement

synclimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

datadir=/usr/yyj/zookeeper/zookeeper-3.4.5/data

# the port at which the clients will connect

clientport=2181

## be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

## ## the number of snapshots to retain in datadir

#autopurge.snapretaincount=3

# purge task interval in hours

# set to "0" to disable auto purge feature

#autopurge.purgeinterval=1

1.3 建立data目錄

mkdir /usr/yyj/zookeeper/zookeeper-3.4.5/data
1.4 修改環境變數

vim /etc/profile
export zk_home=/usr/yyj/zookeeper/zookeeper-3.4.5

export path=.:$zk_home/bin:$path

1.5 修改完成後使其生效:

source /etc/profile
2 執行zookeeper

zkserver.sh start

zkserver.sh status

3 安裝kafka

tar  -xvf kafka_2.11-2.1.0.tgz
3.1 修改配置檔案

[root@along kafka_2.11-2.1.0]

# cat | grep "^[^#]" config/server.properties

broker.id=0

listeners=plaintext://localhost:9092

num.network.threads=3

num.io.threads=8

socket.send.buffer.bytes=102400

socket.receive.buffer.bytes=102400

socket.request.max.bytes=104857600

log.dirs=/tmp/kafka-logs

num.partitions=1

num.recovery.threads.per.data.dir=1

offsets.topic.replication.factor=1

transaction.state.log.replication.factor=1

transaction.state.log.min.isr=1

log.retention.hours=168

log.segment.bytes=1073741824

log.retention.check.interval.ms=300000

zookeeper.connect=localhost:2181

zookeeper.connection.timeout.ms=6000

group.initial.rebalance.delay.ms=0

注:可根據自己需求修改配置檔案

broker.id:唯一標識id

listeners=plaintext://localhost:9092:kafka服務監聽位址和埠

log.dirs:日誌儲存目錄

zookeeper.connect:指定zookeeper服務

3.2 配置環境變數

[root@along ~]

# vim /etc/profile.d/kafka.sh

export kafka_home=

"/usr/yyj/kafka/kafka_2.11-2.4.0"

export path=

"$/bin:$path"

[root@along ~]

# source /etc/profile.d/kafka.sh

4 啟動kafka並測試

4.1啟動乙個broker

bin/kafka-server-start.sh  config/server.properties
4.2 建立乙個topic

topic是乙個訊息的標籤,從業務上講我們只要知道乙個訊息的topic我們就知道他是誰生產的,誰應該消費,負責啥業務的

./kafka-topics.sh --zookeeper 127.0.0.1:2181 --partitions 1 --replication-factor 1 --create --topic productscanlog
上面的命令中–create是建立,zookeeper是指定zookeeper,topic 是指定名字,–replication-factor表示這個topic會備份到多少個broker中,partitions表示這個topic中有多少個partitions(這兩個引數讀者如果不理解可以先放一放),執行成功後我們可以通過下面這個命令檢視我們所有topic的列表

4.3 啟動乙個consumer

bin/./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic productscanlog --from-beginning
4.4 啟動乙個producer

bin/./kafka-console-producer.sh  --broker-list localhost:9092 --topic productscanlog
4.5 在生產者那邊輸入訊息,回車即可。

CSS入門教程

css是 cascading style sheets 的簡稱,中文翻譯為 串接樣式表 也有人翻譯為 樣式表 css用以作為網頁的排版和風格設計,在web標準建站中,對css的熟悉和使用是相當重要的乙個內容。css的作用是彌補html的不足,讓網頁的設計更為靈活。這個文章只是為您介紹css的基礎應用...

CSS入門教程

css是 cascading style sheets 的簡稱,中文翻譯為 串接樣式表 也有人翻譯為 樣式表 css用以作為網頁的排版和風格設計,在web標準建站中,對css的熟悉和使用是相當重要的乙個內容。css的作用是彌補html的不足,讓網頁的設計更為靈活。這個文章只是為您介紹css的基礎應用...

Linux入門教程

linux下有兩種使用者 1.root使用者,提示符 2.普通使用者,提示符 在 etc目錄下有乙個inittab檔案,其中有一行配置 id 3 defualt 其中,數字3就代表一啟動進入字元終端,如果改為5則代表一啟動進入x window 修改口令 passwd 退出登入 exit 關閉機器 只...