参考:https://gist.github.com/vipmax/9ceeaa02932ba276fa810c923dbcbd4f

启动命令

#启动
$ systemctl daemon-reload
$ systemctl enable kafka-zookeeper.service
$ systemctl enable kafka.service
$ systemctl start kafka-zookeeper.service
$ systemctl start kafka.service
$ netstat -ano -p |grep 2181 #zookeeper
$ netstat -ano -p |grep 9092 #kafka

zookeeper开机启动

$ usseradd www
$ groupadd www
$ mkdir /apps/zookeeper-data/
$ chown -R www:www /apps/zookeeper-data/
$ chmod -R 775 /apps/zookeeper-data/
#修改data dir 为 /apps/zookeeper-data/
$ vim /usr/local/kafka_2.12-2.4.1/config/zookeeper.properties
#编辑启动脚本,JAVA_HOME和kafka-zookeeper请修改为你自己机器的路径
$ vim /etc/systemd/system/kafka-zookeeper.service
[Unit]
Description=Apache Zookeeper server (Kafka)
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=www
Group=www
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
ExecStart=/usr/local/kafka_2.12-2.4.1/bin/zookeeper-server-start.sh /usr/local/kafka_2.12-2.4.1/config/zookeeper.properties
ExecStop=/usr/local/kafka_2.12-2.4.1/bin/zookeeper-server-stop.sh

[Install]
WantedBy=multi-user.target

kafka开机启动

#kafka开机启动 参考:https://gist.github.com/vipmax/9ceeaa02932ba276fa810c923dbcbd4f
$ vi /etc/systemd/system/kafka.service
[Unit]
Description=Apache Kafka server (broker)
Documentation=http://kafka.apache.org/documentation.html
Requires=network.target remote-fs.target
After=network.target remote-fs.target kafka-zookeeper.service

[Service]
Type=simple
User=www
Group=www
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
ExecStart=/usr/local/kafka_2.12-2.4.1/bin/kafka-server-start.sh /usr/local/kafka_2.12-2.4.1/config/server.properties
ExecStop=/usr/local/kafka_2.12-2.4.1/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

# 端口设置
$ vi /usr/local/kafka_2.12-2.4.1/config/server.properties
$ edit listeners propertie
$ listeners=PLAINTEXT://192.168.13.133:9092

欢迎留言