解压安装包并改名:
- tar -xvf kafka_2.13-3.3.1.tgz
- mv kafka_2.13-3.3.1.tgz kafka
在kafka文件夹下创建zookeeper数据文件夹,kafka和zookeeper的日志文件存放文件夹:
- mkdir zookeeper
- mkdir log
- cd log
- mkdir zookeeper
- mkdir kafka
zookeeper.properties:
- authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
- requireClientAuthScheme=sasl
- jaasLoginRenew=3600000
- dataDir=/home/appuser/application/kafka/zookeeper
- #zookeeper端口
- clientPort=2282
- tickTime=2000
- initLimit=10
- syncLimit=5
- server.0=当前服务器ip:2999:3999
server.properties:
- broker.id=0
- listeners=SASL_PLAINTEXT://当前服务器ip:9092
- advertised.listeners=SASL_PLAINTEXT://当前服务器ip:9092
- security.inter.broker.protocol=SASL_PLAINTEXT
- sasl.enabled.mechanisms=PLAIN
- sasl.mechanism.inter.broker.protocol=PLAIN
- authorizer.class.name=kafka.security.authorizer.AclAuthorizer
- allow.everyone.if.no.acl.found=true
- super.users=User:admin
- zookeeper.set.acl=true
- log.dirs=/home/appuser/application/kafka/log/kafka
- zookeeper.connect=当前服务器ip:2282
新建jaas.conf文件,放置在kafka/config下
配置如下:
- Server {
- org.apache.kafka.common.security.plain.PlainLoginModule required
- username="admin"
- password="admin@1234"
- user_kafka="admin@1234"
- user_admin="admin@1234";
- };
- Client {
- org.apache.kafka.common.security.plain.PlainLoginModule required
- username="kafka"
- password="admin@1234";
- };
- KafkaServer {
- org.apache.kafka.common.security.plain.PlainLoginModule required
- username="kafka"
- password="admin@1234"
- user_admin="admin@1234"
- user_kafka="admin@1234";
- };
- KafkaClient {
- org.apache.kafka.common.security.plain.PlainLoginModule required
- username="kafka"
- password="admin@1234";
- };
将jaas.conf文件加入到kafka启动脚本(/kafka/bin/kafka-server-start.sh)和zookeeper启动脚本(/kafka/bin/zookeeper-server-start.sh)中:
- if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
- export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G -Djava.security.auth.login.config=/home/appuser/application/kafka/config/jaas.conf"
- fi
- if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
- export KAFKA_HEAP_OPTS="-Xmx512M -Xms512M -Djava.security.auth.login.config=/home/appuser/application/kafka/config/jaas.conf"
- fi
进入kafka目录,执行如下命令:
- nohup ./bin/zookeeper-server-start.sh ./config/zookeeper.properties >./log/zookeeper/zookeeper.log 2>1 &
-
- nohup ./bin/kafka-server-start.sh ./config/server.properties >./log/kafka/kafka.log 2>1 &