找回密码
 注册
查看: 387|回复: 2

Kafka环境搭建及使用教程

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2023-1-3 10:58:57 | 显示全部楼层 |阅读模式
kafka里自带了一个zookeeper,可以不需要再去下载zookeeper。在启动kafka前,需要先启动zookeeper。% L2 I2 b. z) C0 ]# s: b9 `: E+ I
2 R7 N( R$ I/ l& {3 L# m/ [" L
(1)首先去修改config目录下的zookeeper.properties+ ^# ~. H2 b! N4 p$ r- {# C
(2)修改config目录下的server.properties,修改log.dirs和zookeeper.connect。log.dirs是日志存放文件夹,zookeeper.connect是zookeeper连接地址(端口和clientPort保持一致)。; p& V! ^$ K# u6 R9 [

* V/ O8 D1 l4 t9 W1 K1 L5 f: c& T至此,kafka单机版环境已搭建完毕。(如果对里面的参数没修改的话,可不修改,直接用默认的), R5 S; _. ~& V: w3 T( y

2 P) I* O; V5 S! k9 r$ s0 B; } ) ]/ E- ?9 w/ [

- x; A0 q7 n1 E2 ikafka使用教程: y2 k1 Q! S; J2 a! e& ^- H
(1)启动kafka自带的zookeeper(加了-daemon,可以让这个进程挂在后台进行,否则会发现是个阻塞进程,只能再开一个终端进行其他操作); v% a/ A  V* f# O! n& `
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
" e8 Q! s1 |; z% ?0 J. ~6 I  n; ?5 G  `8 Y
(2)启动kafka5 a* Y# R( Q( H2 M, b$ Y
bin/kafka-server-start.sh -daemon config/server.properties' g) S8 C9 P# D1 T. G7 U, I; I% @0 r% |
6 r' v# @  c, t% N
(3)创建一个topic
" S9 G; @: b6 ^# H7 G# _bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test( ^9 X8 i7 Y6 `! w6 i
( h. O5 h7 @" a
/ K4 O: c. L8 o( A* S6 V; P4 N. Q
(4)查看topic列表9 n& c: B5 S/ [# H6 F3 X: B9 d
bin/kafka-topics.sh -list -zookeeper localhost:2181
6 Y" {' ~$ e1 T* Z3 Q2 O: X7 P9 e0 M3 {/ \' X% |3 F* Z+ l. d6 U
(5)创建生产者进程  (9092是默认的broker-list端口)
  r" Q4 e+ I; d- ^% J6 L  Z+ k6 bbin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
2 c; T6 h5 i5 Z! \2 V
2 a* k8 Y9 w4 l+ i, B! N, C$ f7 T(6)创建消费者进程
0 [' E9 ]. ]/ R7 M3 }! p, z% Fbin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning/ H/ l( D# L  s2 N( u
9 P4 W; x% x  ?
(7)外网访问 vi config/server.properties, E+ @3 p# [+ E0 q2 {$ g+ @
advertised.listeners=PLAINTEXT://192.168.8.65:9092# p6 Z2 x3 V* l" c% s

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-1-3 11:28:57 | 显示全部楼层
cat config/zookeeper.properties
  q" Q0 O9 r9 n8 z/ D6 f2 k# Licensed to the Apache Software Foundation (ASF) under one or more
* b9 l% d$ H! j( I' ?: [9 j' G  `# contributor license agreements.  See the NOTICE file distributed with
! l( ~, d/ Q0 L( @. {+ I# this work for additional information regarding copyright ownership./ e, L4 W( X/ G9 X4 f
# The ASF licenses this file to You under the Apache License, Version 2.08 y' U4 _$ b6 n- K! U/ a0 ?8 M+ b
# (the "License"); you may not use this file except in compliance with
& y* e; y% G/ X& F7 X( _# the License.  You may obtain a copy of the License at
$ Z% A+ l$ u( q" N2 x# ; E! r! C2 v; U; U2 n# H
#    http://www.apache.org/licenses/LICENSE-2.0( T* I9 q. l9 A( p' [) w% i) ~5 Q
#
. u! }6 r! ~6 L# Unless required by applicable law or agreed to in writing, software
1 q6 v2 F; A5 M+ K, ^# distributed under the License is distributed on an "AS IS" BASIS,
5 d  g0 U* @6 \) \6 w0 @2 K$ u* A3 E# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 T3 |7 S' S3 s) R6 o' y/ w# See the License for the specific language governing permissions and1 \" V$ C( f/ ^2 I6 C
# limitations under the License." f  D+ Z' m0 H: \7 z3 i2 m
# the directory where the snapshot is stored.
$ b! U6 x: n% U% J9 m" t% o3 V1 JdataDir=/mnt/kafka_2.13-3.3.1/data/zookeeper$ P" \! _$ {9 r5 V. R
# the port at which the clients will connect8 c) N, f5 d8 v" }4 b8 F2 F3 u
clientPort=21818 ]& }1 N5 J2 a3 `8 I6 g( \
# disable the per-ip limit on the number of connections since this is a non-production config
5 [" H+ }. z: C2 }  R9 bmaxClientCnxns=0" q4 u, I; Y  D8 [& h
# Disable the adminserver by default to avoid port conflicts.2 J% D6 Y3 R6 j$ m
# Set the port to something non-conflicting if choosing to enable this
4 v4 x6 X  c2 P. i" A: vadmin.enableServer=false& o) N. c5 [' \" R# [4 f
# admin.serverPort=80805 E+ P+ F" y6 S) q8 P# W* _5 y. g* y
# g. b! w+ z/ K  z# X  c4 R

9 m: }7 M; G+ Q: m5 Z! ^4 Dnohup bin/zookeeper-server-start.sh config/zookeeper.properties &* J/ G. p: \# q% g7 G

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2023-1-3 11:40:15 | 显示全部楼层
[root@ceph2 kafka_2.13-3.3.1]# egrep -v "^#|^$" config/server.properties - @- s- v/ G$ e
broker.id=0
4 C$ _! F+ f2 r- ~, R  J3 ~listeners=PLAINTEXT://192.168.0.233:9092
7 m, n/ L! y7 u$ p! u5 Tnum.network.threads=3
) ~" u; F7 x; j6 F8 gnum.io.threads=8' R! L' L. }7 w! x8 D8 I1 X+ |
socket.send.buffer.bytes=1024001 P6 X( R, h6 T6 g% h! v9 r
socket.receive.buffer.bytes=102400
& l1 I" @8 i, @4 J7 |socket.request.max.bytes=104857600
& b- R# Y8 D& c4 blog.dirs=/var/log/kafka-logs6 E6 H2 Z. z$ U5 a/ }6 F4 _
num.partitions=1
* `# _( ~9 t0 b1 ~num.recovery.threads.per.data.dir=1
2 R: r) e% c" j0 [& L' ~% M8 Yoffsets.topic.replication.factor=1
3 Q; v+ c/ Z. f) Y1 q9 v" Mtransaction.state.log.replication.factor=1
# I' G( h- N  @( V1 z6 ttransaction.state.log.min.isr=12 |5 q2 \6 f* e. s, i  B; `
log.retention.hours=168
" c% j5 E4 K7 }% w  R/ Nlog.retention.check.interval.ms=300000
/ \6 u0 O% |, l* ^# R5 C: C# Szookeeper.connect=localhost:21812 S* ]$ S$ z* L& G- g1 T9 c
zookeeper.connection.timeout.ms=18000
/ V+ t* ?5 [2 Ggroup.initial.rebalance.delay.ms=03 K& T1 d8 T6 P" ~9 F
: @; H6 b+ V4 _) x2 ]/ D! r0 f
7 |# x, T3 Q) Z
[root@ceph2 kafka_2.13-3.3.1]# nohup bin/kafka-server-start.sh config/server.properties &3 l5 e. ]( r; O' A9 R3 {# @' h

3 E+ M, u6 l) n' {2 |
9 j- L( v- H' r, ]- Z( b8 h' ~2 x. `7 [4 |% l8 \) Z
netstat  -ntlp |grep java
0 `. W, w- I1 f' E, stcp6       0      0 192.168.0.233:9092      :::*                    LISTEN      21222/java          + F" `' g1 r1 F5 J
tcp6       0      0 :::2181                 :::*                    LISTEN      20780/java          1 e1 F8 b5 H& p1 N5 o/ Z
tcp6       0      0 :::41467                :::*                    LISTEN      21222/java         
) h: n$ h0 J7 vtcp6       0      0 :::40571                :::*                    LISTEN      20780/java          0 j: M9 [" `2 m2 u7 h9 R
  T. d0 ?' p: D# `( H
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 03:21 , Processed in 0.018768 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表