码迷,mamicode.com
首页 > 其他好文 > 详细

kakfa+zookeeper集群搭建

时间:2019-12-16 13:09:27      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:ida   network   启动会   offset   amp   reads   syn   div   err   

1:下载对应安装包

zookeeper-3.4.14.tar.gz:链接:https://pan.baidu.com/s/19_eYsv5r9bg0AKv3TzjpZQ    提取码:ik8a
kafka_2.12-2.1.1.tgz:     链接:https://pan.baidu.com/s/1VcLtB17fEzFrVyvran1qhQ     提取码:e4f1 


2:解压对应软件包

 

mkdir /data
tar zxf zookeeper-3.4.14.tar.gz  -C /data/
gzip -d  kafka_2.12-2.1.1.tgz
tar xvf kafka_2.12-2.1.1.tar -C /data/

 

3:进行相对应的配置

cd /data/zookeeper-3.4.14/conf
[root@kafka1 conf]# cat zoo.cfg 
#心跳间隔时间,zookeeper中使用的基本时间单位,毫秒值。每隔2秒发送一个心跳
tickTime=2000   
#leader与客户端连接超时时间。表示10个心跳间隔
initLimit=10
#Leader与Follower之间的超时时间,表示5个心跳间隔
syncLimit=5   
dataDir=/data/zookeeper-3.4.14/data/    #数据目录
dataLogDir=/data/zookeeper-3.4.14/data/  #日志目录
clientPort=2181    #客户端连接端口

server.1=10.251.23.162:2888:3888
server.2=10.251.23.163:2888:3888
server.3=10.251.23.164:2888:3888

  

上述server.{1,2,3} 是zookeeper新增../data/myid配置文件1和kakfa服务内server.properties配置的broker.id和kafkalog/meta.properties 配置文件内的broker.id=1这几个一定要有不然后续启动会报错

启动kafka报错信息如下:

32 [2019-04-03 23:59:20,892] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
33 kafka.common.InconsistentBrokerIdException: Configured broker.id 1 doesn‘t match stored broker.id 0 in meta.properties. If you moved your data, make sure your configured broker.id matches. If you intend to create a new broker, you should remove all data in your data directories (log.dirs).
34     at kafka.server.KafkaServer.getBrokerIdAndOfflineDirs(KafkaServer.scala:686)
35     at kafka.server.KafkaServer.startup(KafkaServer.scala:209)
36     at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
37     at kafka.Kafka$.main(Kafka.scala:75)
38     at kafka.Kafka.main(Kafka.scala)
39 [2019-04-03 23:59:20,899] INFO shutting down (kafka.server.KafkaServer)
40 [2019-04-03 23:59:20,909] INFO [ZooKeeperClient] Closing. (kafka.zookeeper.ZooKeeperClient)
41 [2019-04-03 23:59:20,926] INFO EventThread shut down for session: 0x1000015a06e0000 (org.apache.zookeeper.ClientCnxn)
42 [2019-04-03 23:59:20,929] INFO Session: 0x1000015a06e0000 closed (org.apache.zookeeper.ZooKeeper)
43 [2019-04-03 23:59:20,952] INFO [ZooKeeperClient] Closed. (kafka.zookeeper.ZooKeeperClient)
44 [2019-04-03 23:59:20,971] INFO shut down completed (kafka.server.KafkaServer)
45 [2019-04-03 23:59:20,998] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
46 [2019-04-03 23:59:21,034] INFO shutting down (kafka.server.KafkaServer)

  

4:添加myid文件,每台机器都需要添加,1机器是1,2机器是2,3机器是3

[root@kafka1 conf]# cat /data/zookeeper-3.4.14/data/myid 
1

5:分别启动三台zookeeper  

[root@kafka1 bin]# pwd
/data/zookeeper-3.4.14/bin
[root@kafka1 bin]# ./zkServer.sh start

  

6:查看状态,分为leader和follower,至此zookeeper已安装完成

[root@kafka1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

  

7:三台配置kafka,具体参数含义,百度吧。。。注意broker.id和listeners监听地址

[root@nlp-staging-kafka1 config]# pwd
/data/kafka_2.12-2.1.1/config
[root@nlp-staging-kafka1 config]# cat server.properties
broker.id=1        #当前机器在集群中的唯一标识,和zookeeper的myid性质一样
listeners=PLAINTEXT://10.251.23.162:9092   
num.network.threads=3    #这个是borker进行网络处理的线程数
num.io.threads=8      #这个是borker进行I/O处理的线程数
socket.send.buffer.bytes=102400  #发送缓冲区buffer大小,数据不是一下子就发送的,先回存储到缓冲区了到达一定的大小后在发送,能提高性能
socket.receive.buffer.bytes=102400  #kafka接收缓冲区大小,当数据到达一定大小后在序列化到磁盘
socket.request.max.bytes=104857600  #这个参数是向kafka请求消息或者向kafka发送消息的请请求的最大数,这个值不能超过java的堆栈大小
log.dirs=/data/kafkalogs/     #消息存放的目录,这个目录可以配置为“,”逗号分割的表达式,上面的num.io.threads要大于这个目录的个数这个目录,如果配置多个目录,新创建的topic他把消息持久化的地方是,当前以逗号分割的目录中,那个分区数最少就放那一个
num.partitions=16  #默认的分区数,一个topic默认16个分区数??
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=24  #默认消息的最大持久化时间,24小时
log.retention.bytes=-1
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000 #默认消息的最大持久化时间,300000小时
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
message.max.byte=5242880
log.cleaner.enable=true
delete.topic.enable=true
replica.fetch.max.bytes=5242880
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=3
zookeeper.connect=10.251.23.162:2181,10.251.23.163:2181,10.251.23.164:2181    #设置zookeeper的连接端口
 

  

8:三台都新增一个文件

[root@kafka1 kafkalogs]# pwd
/data/kafkalogs
[root@kafka1 kafkalogs]# cat meta.properties 
version=0
broker.id=1

  

9:三台分别进入kafka的bin目录启动kafka

./kafka-server-start.sh ../config/server.properties &

  

至此完成

 

kakfa+zookeeper集群搭建

标签:ida   network   启动会   offset   amp   reads   syn   div   err   

原文地址:https://www.cnblogs.com/dribs/p/12048449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!