单机版:https://blog.csdn.net/qq_39276448/article/details/85726161
学习理论:https://blog.csdn.net/qq_39276448/article/details/86024940
还需要配置zk集群版(也可以单机版,这里统一集群)一起使用:https://blog.csdn.net/qq_39276448/article/details/86025192
要先安装jdk
下载kafka并解压到你喜欢的目录 :wget http://mirrors.shuosc.org/apache/kafka/2.1.0/kafka_2.11-2.1.0.tgz
解压完成后
切换到配置kafka目录下config 复制配置文件为三份
cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
cp config/server.properties config/server-3.properties
在当前kafka目录下创建kafka-logs-1,kafka-logs-2,kafka-logs-3文件夹
server-1.properties 设置:
Cannot assign requested这个问题也是这样配置
#port=9092
#host.name=192.168.94.132
不要去学网上的配置port,和hostname;如果没配置port,hostname就会使用以下配置。配置了则使用hostname,port,字数多难得写所以楼主选了以下配置
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://你自己的外网地址:9092
broker.id=1
log.dirs=/usr/local/kafka/kafka-logs-1
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880
zookeeper.connect=本机外网ip:2181,本机外网ip:2182,本机外网ip:2183
delete.topic.enable=true
server-2.properties 设置:
listeners=PLAINTEXT://0.0.0.0:9093
advertised.listeners=PLAINTEXT://你自己的外网地址:9093
broker.id=2
log.dirs=/usr/local/kafka/kafka-logs-2
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880
zookeeper.connect=本机外网ip:2181,本机外网ip:2182,本机外网ip:2183
delete.topic.enable=true
server-3.properties 设置:
listeners=PLAINTEXT://0.0.0.0:9094
advertised.listeners=PLAINTEXT://你自己的外网地址:9094
broker.id=3
log.dirs=/usr/local/kafka/kafka-logs-3
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880
zookeeper.connect=本机外网ip:2181,本机外网ip:2182,本机外网ip:2183
delete.topic.enable=true
然后先启动zk集群
再启动kafka伪节点一:无报错则成功
注:如果单机伪集群内存不够,可以修改启动脚本,将红框内的内存改小些,默认为1G
vim ./bin/kafka-server-start.sh
sh kafka-server-start.sh config/server-1.properties &
再启动kafka伪节点二:无报错则成功
sh kafka-server-start.sh config/server-2.properties &
再启动kafka伪节点三:无报错则成功
sh kafka-server-start.sh config/server-3.properties &
再到zk集群查看是否有三个新注册的节点
切到zk bin目录:zkCli.sh -server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
ls /brokers/ids
有显示id为1,2,3的节点则表示已成功创建kafka集群
接下来验证是否有bug
去参考
单机版:https://blog.csdn.net/qq_39276448/article/details/85726161
yml改为
kafka服务器地址ip:9092,kafka服务器地址ip:9093,kafka服务器地址ip:9094