kafka配置内外网访问

使用docker简单部署测试

zookeeper

mkdir data conf
chmod 777 data
启动命令
docker run -itd -p 2181:2181 -e ALLOW_ANONYMOUS_LOGIN=yes --name zookeeper -v $(pwd)/data:/bitnami/zookeeper/data -v $(pwd)/conf/zoo.cfg:/opt/bitnami/zookeeper/conf/zoo.cfg bitnami/zookeeper:3.6.2

kafka

mkdir kafka kafka/data kafka/data1

chmod 777 data data1

起2个kafka broker server

 cat start.sh
docker run -itd --name kafka --restart always\
    --net host \
    -p 9092:9092 \
    -p 9093:9093 \
    -e ALLOW_PLAINTEXT_LISTENER=yes \
    -e KAFKA_CFG_ZOOKEEPER_CONNECT=172.16.xx.xx:2181 \
    -e KAFKA_BROKER_ID=1 \
    -e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT \
    -e KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093 \
    -e KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://172.16.xx.xx:9092,EXTERNAL://119.29.xx.xx:9093 \
    -e KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT \
    -v $(pwd)/data:/bitnami/kafka/data \
    bitnami/kafka:2.6.0
[root@VM-xx-centos kafka]# cat start1.sh
docker run -itd --name kafka1 --restart always\
    --net host \
    -p 9094:9094 \
    -p 9095:9095 \
    -e ALLOW_PLAINTEXT_LISTENER=yes \
    -e KAFKA_CFG_ZOOKEEPER_CONNECT=172.16.xx.xx:2181 \
    -e KAFKA_BROKER_ID=2 \
    -e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT \
    -e KAFKA_CFG_LISTENERS=CLIENT://:9094,EXTERNAL://:9095 \
    -e KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://172.16.xx.xx:9094,EXTERNAL://119.29.xx.xx:9095 \
    -e KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT \
    -v $(pwd)/data1:/bitnami/kafka/data \
    bitnami/kafka:2.6.0

  

创建topic测试 模拟生产者消费者使用情况

[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-topics.sh  --create --topic test --replication-factor 2 --bootstrap-server  119.29.xx.xx:9093
Created topic test.
[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-topics.sh --describe --topic test --bootstrap-server  119.29.xx.xx:9093
Topic: test	PartitionCount: 1	ReplicationFactor: 2	Configs: segment.bytes=1073741824
	Topic: test	Partition: 0	Leader: 2	Replicas: 2,1	Isr: 2,1
[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-topics.sh  --create --topic test1 --bootstrap-server  119.29.xx.xx:9093
Created topic test1.
[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-topics.sh --describe --topic test1 --bootstrap-server  119.29.xx.xx:9093
Topic: test1	PartitionCount: 1	ReplicationFactor: 1	Configs: segment.bytes=1073741824
	Topic: test1	Partition: 0	Leader: 1	Replicas: 1	Isr: 1
[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-console-producer.sh  --topic test --bootstrap-server  119.29.xx.xx:9093
>this is a test
>this is a test

[root@ops_8 kafka_2.13-2.6.0]# bin/kafka-console-consumer.sh --topic test --bootstrap-server  119.29.xx.xx:9093 --from-beginning
this is a test
this is a test

 

查看kafka data目录是否有创建topic文件目录,日志是否报错

 

查看zookeeper注册地址信息

[zk: 172.16.xx.xx(CONNECTED) 1] get /brokers/ids/1
{"listener_security_protocol_map":{"CLIENT":"PLAINTEXT","EXTERNAL":"PLAINTEXT"},"endpoints":["CLIENT://172.16.xx.xx:9092","EXTERNAL://119.29.xx.xx:9093"],"jmx_port":-1,"host":"172.16.xx.xx","timestamp":"1606226631598","port":9092,"version":4}

[zk: 172.16.xx.xx(CONNECTED) 2] get /brokers/ids/2
{"listener_security_protocol_map":{"CLIENT":"PLAINTEXT","EXTERNAL":"PLAINTEXT"},"endpoints":["CLIENT://172.16.xx.xx:9094","EXTERNAL://119.29.xx.xx:9095"],"jmx_port":-1,"host":"172.16.xx.xx","timestamp":"1606226712403","port":9094,"version":4}
cZxid = 0x85

  

posted @ 2020-11-24 22:56  时光依然轻擦  阅读(2454)  评论(0编辑  收藏  举报