docker下搭建kafka服务相关命令

docker start zookeeper
sudo docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 --env KAFKA_ADVERTISED_PORT=9092 --volume /Users/liweijun/Downloads:/etc/localtime wurstmeister/kafka

#进入kafka目录
docker exec -ti kafka /bin/bash
cd /opt/kafka_2.12-2.2.0/bin

#后面的操作在linux下都相同

#启动kafka
sh kafka-server-start.sh ../config/server.properties

#config/server.properties可以配置监听(多个端口需配置多个配置文件在kafka启动时选定对应的配置文件即可)
#如
#server1.properties
#advertised.listeners=PLAINTEXT://192.168.1.xxx:9092 
#port=9092
#server2.properties
#advertised.listeners=PLAINTEXT://192.168.1.xxx:9093 
#port=9093

#启动zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties &

#启动kafka
bin/kafka-server-start.sh config/server.properties &

#停止kafka
bin/kafka-server-stop.sh

#停止zookeeper
bin/zookeeper-server-stop.sh

#开启zookeeper端口
firewall-cmd --zone=public --add-port=2181/tcp --permanent

#开启kafka端口
firewall-cmd --zone=public --add-port=9092/tcp --permanent

#重启firewall
firewall-cmd --reload 

#创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

#展示topic
bin/kafka-topics.sh --list --zookeeper localhost:2181

#描述topic
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic

#生产者:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic

#消费者:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginnin
#如果创建消费者报错 consumer zookeeper is not a recognized option请使用下面命令
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

#查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2181

你可能感兴趣的:(程序人生,Linux)