首页 > 其他 > 详细

kafka集群搭建

时间:2019-09-09 20:03:20      阅读:92      评论:0      收藏:0      [点我收藏+]

环境:

三台机器vm1,vm2,vm3

zookeeper版本:apache-zookeeper-3.5.5

kafka版本:kafka_2.11-2.3.0 (2.11是scala版本,2.3.0是kafka版本)

 

安装zookeeper集群

前往下载

解压拷贝三份到目标机器相同目录下,

配置,

mv zoo_sample.cfg zoo.cfg

zoo.cfg具体配置如下

# 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=/var/lib/zookeeper/
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# 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
server.1=192.168.1.231:2888:3888
server.2=192.168.1.232:2888:3888
server.3=192.168.1.233:2888:3888

除了配置server信息和dataDir,其它默认配置;如果配置了hosts,可以不用输入ip,直接使用主机名也可以。

接着,在dataDir目录下,即/var/lib/zookeeper下创建名为mypid的文件,其中输入序号即可,三台机器都操作一样,这里vm1机器输入1,vm2机器输入2,vm3机器输入3;

比如vm1,

技术分享图片

 

 

 

启动与校验

三台机器做如下同样的操作,

启动,

[xs@vm1 bin]$ ./zkServer.sh start

验证,

[xs@vm1 bin]$ ./zkServer.sh status

技术分享图片

 

 

 见到类似上面的输出,证明启动成功;

 

 

可能遇到的问题

1、三台机器确认dataDir存在且有权限,可执行下面命令,这里用户是xs,

sudo chown -R xs:xs /var/lib/zookeeper

2、如果下载使用的包是类似下面第二个较小的包,需要把第一个包下载下来解压后将其lib目录导入,否则启动时可能会报类似包找不到的错误。

技术分享图片

 

 

 

 


 

 

安装kafka集群

 

前往下载所需版本kafka 。

将包解压到三台机器的相同目录下,解压包的config目录下server.properties文件中修改如下参数,

broker.id=1  #vm1这里设置1,vm2这里设置2,vm3这里设置3

zookeeper.connect=vm1:2181,vm2:2181,vm3:2181 #配置zookeeper机器信息

 

进入bin目录启动,

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

 

创建topic

./kafka-topics.sh --create --zookeeper vm1:2181,vm2:2181,vm3:2181 --replication-factor 1 --partitions 1 --topic test

列出topic

./kafka-topics.sh --list --bootstrap-server localhost:9092

注意上面,使用了--bootstrap-server,它与--zookeeper有相同的效果;

发送消息

 ./kafka-console-producer.sh --broker-list vm1:9092,vm2:9092,vm3:9092 --topic test

技术分享图片

 

 

接收消息

./kafka-console-consumer.sh --bootstrap-server  vm2:9092 --topic test  --from-beginning

技术分享图片

 

 

 

tips : 具体sh文件命令参数不懂,可以--help查看帮助信息。

 

 

 

 

 

 

 

 

 

 

 

 

参考:

 

https://www.cnblogs.com/cjsblog/p/9409443.html

http://kafka.apache.org/quickstart

 

kafka集群搭建

原文:https://www.cnblogs.com/mylittlecabin/p/11493265.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!