进入/home/appuser/application文件夹,将kafka安装包上传至此处
解压安装包并改名:
bash
tar -xvf kafka_2.13-3.3.1.tgz
mv kafka_2.13-3.3.1.tgz kafka
在kafka文件夹下创建zookeeper数据文件夹,kafka和zookeeper的日志文件存放文件夹:
bash
mkdir zookeeper
mkdir log
cd log
mkdir zookeeper
mkdir kafka
修改相关配置文件:
zookeeper.properties:
bash
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:
bash
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下
配置如下:
bash
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)中:
bash
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目录,执行如下命令:
bash
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 &