kafka——命令备份——docker启动——linux下启动

docker 下启动 kafka 
docker run -d \ --name zookeeper \ -p 2181:2181 \ -e ZOOKEEPER_CLIENT_PORT=2181 \ confluentinc/cp-zookeeper docker run -d \ --name kafka \ -p 9092:9092 \ -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.1.100:9092 \ -e KAFKA_ZOOKEEPER_CONNECT=192.168.1.100:2181 \ confluentinc/cp-kafka docker exec -it kafka kafka-topics --list --bootstrap-server 192.168.1.100:9092

kafka-topics --list --bootstrap-server 192.168.1.100:9092

kafka-topics --create --bootstrap-server 192.168.1.100:9092 --replication-factor 1 --partitions 1 --topic test_topic

kafka-console-consumer --bootstrap-server 192.168.1.100:9092 --topic test_topic --from-beginning
 

  sh kafka-topics.sh  --list --bootstrap-server 47.104.201.169:9092

 

 注:  

在阿里云内外网情况下, KAFKA_ADVERTISED_LISTENERS  得是外网 ip  


2、测试 kafka 是否可用:
写
kafka-console-producer  --broker-list localhost:9092 --topic log_topic

读
kafka-console-consumer --bootstrap-server localhost:9092 --topic log_topic --from-beginning

 

3、win10下命令行读写本地kafka

kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test_topic
kafka-topics --list --bootstrap-server localhost:9092
kafka-console-consumer --bootstrap-server localhost:9092 --topic test_topic --from-beginning
kafka-console-producer  --broker-list localhost:9092 --topic test_topic

 

4、linux 下docker 命令行读写 kafka

docker run -d \
    --name zookeeper \
    -p 2181:2181 \
    -e ZOOKEEPER_CLIENT_PORT=2181 \
    confluentinc/cp-zookeeper
docker run -d \
    --name kafka \
    -p 9092:9092 \
    -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.31.140.171:9092 \
    -e KAFKA_ZOOKEEPER_CONNECT=172.31.140.171:2181 \
    confluentinc/cp-kafka

docker exec -it kafka  kafka-topics --create --bootstrap-server 172.31.140.171:9092 --replication-factor 1 --partitions 1 --topic test_topic
docker exec -it kafka  kafka-topics --list --bootstrap-server 172.31.140.171:9092
docker exec -it kafka  kafka-console-consumer --bootstrap-server 172.31.140.171:9092 --topic test_topic --from-beginning
docker exec -it kafka  kafka-console-producer  --broker-list 172.31.140.171:9092 --topic test_topic

 

5、普通 linux 下启动 kafka

wget https://downloads.apache.org/kafka/3.5.1/kafka_2.12-3.5.1.tgz
scp -i codex_cipher_key.pem /Users/xingchong/Documents/soft/kafka/kafka_2.12-3.5.1.tgz root@47.104.201.169:/root/data/soft/kafka/

启动 kafka 命令,单 broker,可在 server.properties 下配置 kafka-logs 目录

修改配置文件:

vim config/server.properties 
advertised.listeners=PLAINTEXT://172.31.140.161:9092
listeners=PLAINTEXT://172.31.140.161:9092

log.dirs=/root/data/soft/kafka/kafka-logs

sh run_kafka.sh

filepath=$(cd "$(dirname "$0")"; pwd)
echo "filepath="$filepath
cd $filepath
pwd

cd kafka_2.13-3.2.0
screen -dmS zookeeper sh bin/zookeeper-server-start.sh config/zookeeper.properties
screen -dmS kafka     sh bin/kafka-server-start.sh config/server.properties

测试是否启动成功

sh kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test_topic
sh kafka-topics.sh --list --bootstrap-server localhost:9092
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --from-beginning
sh kafka-console-producer.sh  --broker-list localhost:9092 --topic test_topic

 

sh kafka-topics.sh --create --bootstrap-server 172.31.140.161:9092 --replication-factor 1 --partitions 1 --topic test_topic
sh kafka-topics.sh --list --bootstrap-server 172.31.140.161:9092
sh kafka-console-consumer.sh --bootstrap-server 172.31.140.161:9092 --topic test_topic --from-beginning
sh kafka-console-producer.sh  --broker-list 172.31.140.161:9092 --topic test_topic

 

posted @ 2023-08-18 18:43  会飞的斧头  阅读(121)  评论(0编辑  收藏  举报