赞
踩
前言:
本方法适用于开发测试环境。
集群方式搭建 见 《kafka集群搭建》
[root@kafka-01 data]# ll
drwxr-xr-x 7 root root 4096 3月 2 15:28 kafka_2.13-2.7.0
-rw-r--r-- 1 root root 68583422 3月 2 15:07 kafka_2.13-2.7.0.tgz
drwx------ 2 root root 16384 3月 2 10:54 lost+found
[root@kafka-01 data]# ln -s /data/kafka_2.13-2.7.0 /opt/kafka
[root@kafka-01 data]# cd /opt/
[root@kafka-01 opt]# ll
总用量 4
lrwxrwxrwx 1 root root 22 3月 2 15:33 kafka -> /data/kafka_2.13-2.7.0
测试环境使用kafka自带zookeeper即可
# cd /opt/kafka/bin
# nohup ./zookeeper-server-start.sh ../config/zookeeper.properties > /tmp/zookeeper-run.log 2>&1 &
############################# Socket Server Settings #############################
listeners=SASL_PLAINTEXT://172.xxx.xxx.149:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
advertised.listeners=SASL_PLAINTEXT://47.xxx.xxx.140:9092
listeners
写ECS的IP地址
advertised.listeners
写绑定的弹性IP(因为测试的是阿里云环境,因此需要多配置一个外网,如果不用外网只去掉这一行配置即可)
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="kafka"
password="xxxxxxx"
user_kafka="xxxxxxx"
user_enduser="xxxxxxx";
};
修改启动脚本
在 /opt/kafka/bin/kafka-server-start.sh脚本中,kafka-run-class.sh启动前,添加如下内容:
if [ "x$KAFKA_OPTS" = "x" ]; then
export KAFKA_OPTS="-Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf"
fi
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="enduser"
password="xxxxxx";
};
if [ "x$KAFKA_OPTS" = "x" ]; then
export KAFKA_OPTS="-Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"
fi
if [ "x$KAFKA_OPTS" = "x" ]; then
export KAFKA_OPTS="-Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"
fi
nohup /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties 1>/dev/null 2>&1 &
./kafka-topics.sh --zookeeper localhost:2181 --create --topic Test --partitions 1 --replication-factor 1
[root@kafka-01 bin]# ./kafka-console-producer.sh --broker-list 47.xxx.xxx.140:9092 --topic Test --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.mechanism=PLAIN
>111
>hongjian
[root@kafka-01 bin]# ./kafka-console-consumer.sh --bootstrap-server 47.xxx.xxx.140:9092 --topic Test --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.mechanism=PLAIN --from-beginning
111
hongjian
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。