安装配置Kafka
Apache Kafka
从releases下载二进制版本
Apache Kafka
从releases下载二进制版本
Requirements
- Java 1.8
1. 添加系统账号
groupadd --system kafka
useradd -M -s /bin/bash -g kafka -d /usr/local/kafka kafka
2. 解包安装
tar -xzvf kafka_2.12-2.4.1.tgz --directory=/usr/local
cd /usr/local
ln -s kafka_2.12-2.4.1 kafka
chown -R kafka:kafka kafka kafka_2.12-2.4.1
mkdir /data1/kafka
chown kafka:kafka /data1/kafka
3. 编辑配置 config/server.properties
broker.id=1
log.dirs=/data1/kafka
delete.topic.enable=true
auto.create.topics.enable=false
zookeeper.connect=10.16.19.181:2181,10.16.19.182:2181,10.16.19.183:2181
4. 使用systemd管理进程 vim /usr/lib/systemd/system/kafka.service
mkdir /etc/systemd/system/kafka.service.d/
vim /etc/systemd/system/kafka.service.d/limit.conf
# If you need to change max open file limit
# for example, when you change maxclient in configuration
# you can change the LimitNOFILE value below
# see "man systemd.exec" for information
[Service]
LimitNOFILE=65536
[Unit]
Description=Apache Kafka
Requires=network.target
After=network.target
[Service]
Type=simple
User=kafka
Environment=JAVA_HOME=/usr/java/latest
Environment=PATH=/usr/java/latest/bin:/usr/bin
Environment="KAFKA_HEAP_OPTS=-Xms8G -Xmx8G"
Environment=JMX_PORT=9988
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
Restart=always
[Install]
WantedBy=multi-user.target
5. systemctl管理命令
# 开机自启动
systemctl enable kafka
# 重启服务
systemctl restart kafka
6. 特殊配置说明
# sudo
visudo
hadoop ALL=NOPASSWD: /bin/su - kafka
7. 使用hadoop用户登录修改配置
$ sudo su - kafka
vim config/server.properties
./bin/kafka-server-stop.sh stop
# 停止后会自动重启