kafka集群外网访问

Kafka的配置方式有三种 ,分别是单机、伪分布式集群和分布式集群,部署都很常规,博客资源也很多,这里简单介绍,详细说明Kafka集群如何进行外网访问。其中集群配置过程中,本文使用到的内网IP和外网IP只做演示,非真实IP。

1 伪分布式集群部署

内网IP:10.12.100.126 外网IP:47.90.133.76 域名:server1 server2 server3

配置 Kafka server.properties

# server1

broker.id=1

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.126:9092
port=9092

log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880
zookeeper.connect=10.12.100.126:2181,10.12.100.126:2182,10.12.100.126:2183

# server2 

broker.id=2

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.126:9093
port=9093
log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880
zookeeper.connect=10.12.100.126:2181,10.12.100.126:2182,10.12.100.126:2183

# server3

broker.id=3

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.126:9094
port=9094

log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880

zookeeper.connect=10.12.100.126:2181,10.12.100.126:2182,10.12.100.126:2183

2 配置 伪分布式集群外网访问

2.1 修改hosts

# server1
10.12.100.126   server1 改为: 47.90.133.76  server1

# server2


10.12.100.126   server2 改为: 47.90.133.76  server2

# server3

10.12.100.126   server3 改为: 47.90.133.76  server3

2.2 Kafka server.properties文件更改:

# server1

port = 9092
advertised.listeners=PLAINTEXT://47.90.133.76:9092

# server2 

port = 9093
advertised.listeners=PLAINTEXT://47.90.133.76:9093

# server3

port = 9094
advertised.listeners=PLAINTEXT://47.90.133.76:9094

注意:

Server.properties 文件中zookeeper信息不需要更改依旧是
zookeeper.connect=10.12.100.126:2181,10.12.100.126:2182,10.12.100.126:2183

3 分布式集群部署

内网IP:10.12.100.126 10.12.100.127 10.12.100.128 外网IP:47.90.133.76 47.90.133.77 47.90.133.78 用户名:server1 server2 server3

server1  

/opt/kafka/kafka_2.11-0.10.2.2/config vi server.properties

## 增加下列配置信息

broker.id=1

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.126:9092

log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880

zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181

server2 

/opt/kafka/kafka_2.11-0.10.2.2/config  vi server.properties
## 增加下列配置信息

broker.id=2

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.127:9092

log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880

zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181
server3

/opt/kafka/kafka_2.11-0.10.2.2/config  vi server.properties
## 增加下列配置信息

broker.id=3

delete.topic.enable=true
auto.create.topic.enable = true

listeners=PLAINTEXT://10.12.100.128:9092

log.dirs=/opt/kafka/kafkaLog

message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880

zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181

4 配置分布式集群使用hostname外网访问

# 三台服务器操作一致
vi /etc/hosts

10.12.100.126   server1
10.12.100.127   server2
10.12.100.128   server3

47.90.133.76    server1
47.90.133.77    server2
47.90.133.78    server3

# kafka
# vi server.properties

#server1

broker.id=1

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
listeners=PLAINTEXT://server1:9092

zookeeper.connect=10.12.100.126 :2181,10.12.100.127:2181,10.12.100.128:2181

#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890



# server2
broker.id=2

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
listeners=PLAINTEXT://server2:9092
zookeeper.connect=10.12.100.126 :2181,10.12.100.127:2181,10.12.100.128:2181

#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890

#server3

broker.id=3

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
listeners=PLAINTEXT://server3:9092
zookeeper.connect=10.12.100.126 :2181,10.12.100.127:2181,10.12.100.128:2181

#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890

测试验证

sh kafka-console-producer.sh --broker-list server1:9092, server2:9092, server3:9092 --topic test #hostname生产
sh kafka-console-consumer.sh --zookeeper server1:2181, server2:2181, server3:2181 --topic test --from-beginning  #hostname消费

5 配置分布式集群使用外网IP访问

# 三台服务器操作一致
vi /etc/hosts

10.12.100.126   server1
10.12.100.127   server2
10.12.100.128   server3

47.90.133.76    server1
47.90.133.77    server2
47.90.133.78    server3

# kafka
# vi server.properties

#server1

broker.id=1

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
advertised.listeners=PLAINTEXT://47.90.133.76:9092


zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181

#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890



# server2
broker.id=2

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
advertised.listeners=PLAINTEXT://47.90.133.77:9092
zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181

#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890

#server3

broker.id=3

delete.topic.enable=true
auto.create.topic.enable = true

port = 9092
advertised.listeners=PLAINTEXT://47.90.133.78:9092

zookeeper.connect=10.12.100.126:2181,10.12.100.127:2181,10.12.100.128:2181


#zookeeper
# zoo.cfg
server.1= 10.12.100.126:2888:3888
server.2= 10.12.100.127:2889:3889
server.3= 10.12.100.128:2890:3890
测试:
sh kafka-console-producer.sh --broker-list 47.90.133.76:9092,47.90.133.77:9092,47.90.133.78:9092 --topic test  #外网ip生产
sh kafka-console-consumer.sh --bootstrap-server 47.90.133.76:9092,47.90.133.77:9092,47.90.133.78:9092 --topic test --from-beginning  #外网ip消费

注意:若使用阿里云ECS点对点,首先需要集群间可以通信,telnet通

posted @ 2019-12-23 22:35  Christine_7  阅读(4961)  评论(0编辑  收藏  举报