kafka
Kafka是最初由Linkedin公司开发,是一个分布式、支持分区的(partition)、多副本的(replica),基于zookeeper协调的分布式消息系统,它的最大的特性就是可以实时的处理大量数据以满足各种需求场景:比如基于hadoop的批处理系统、低延迟的实时系统、storm/Spark流式处理引擎,web/nginx日志、访问日志,消息服务等等,用scala语言编写,Linkedin于2010年贡献给了Apache基金会并成为顶级开源项目。
单机直接使用内置zookeeper部署安装即可 以下为单机配置server.properties文件
broker.id=1
listeners=SASL_PLAINTEXT://:9092
advertised.listeners=SASL_PLAINTEXT://:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/opt/kafka/logs
num.partitions=10
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.76.131:2181
zookeeper.connection.timeout.ms=60000
group.initial.rebalance.delay.ms=0
advertised.host.name=192.168.76.131
security.inter.broker.protocol=SASL_PLAINTEXT
port=9092
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
配置文件里加了kafka的验证,不需要的可以去掉 验证加在config/jaas/jaas.conf下 这里基于kafka sasl用户名密码验证
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="kafka"
password="passwd"
user_kafka="passwd"
user_emotibot="passwd";
};
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="user"
password="passwd";
};
根据需要修改用户名密码
然后需要在
kafka-server-start.sh
kafka-console-producer.sh
kafka-console-consumer.sh
三个文件中增加
kafka安装路径自行修改
export KAFKA_OPTS="-Djava.security.auth.login.config=/opt/kafka/config/jaas/jaas.conf"
依次启动zookeeper 和kafka
/opt/kafka/bin/zookeeper-server-start.sh -daemon /opt/kafka/config/zookeeper.properties && /opt/kafkae/bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties
集群版需要至少三节点部署 zookeeper集群配置文件 dataDir=/tmp/zookeeper
clientPort=2181
maxClientCnxns=0
admin.enableServer=false
tickTime=2000
initLimit=10
syncLimit=5
server.1=192.168.76.129:2888:3888
server.2=192.168.76.130:2888:3888
server.3=192.168.76.131:2888:3888
kafka配置文件server.properties需要zookeeper连接地址
zookeeper.connect=192.168.76.129:2181,192.168.76.130:2181,192.168.76.131:2181
然后启动即可
/opt/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test1
/opt/kafka/bin/kafka-topics.sh --list --zookeeper zookeeper:2181
/opt/kafka/bin/kafka-console-producer.sh --broker-list 192.168.76.129:9092 --topic test1 --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.mechanism=PLAIN
>1111
>
开启另外一个窗口验证
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.168.76.129:9092 --topic test1 --from-beginning --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.mechanism=PLAIN
一键自动安装脚本地址 https://download.csdn.net/download/w2909526/20403512
|