Installation kafka need to install jdk.
First, download
the official website: http: //kafka.apache.org/downloads.html
Second, the installation
Installation Reference: https: //segmentfault.com/a/1190000012990954
1. Unzip the installation (I install directory / opt / kafka /)
# Tar -zvxf kafka_2.11-2.1.0.tgz
2. modify the configuration
# vim /opt/kafka/kafka_2.11-2.1.0/config/server.properties
3. modify
listeners=PLAINTEXT://ip:9092
Note: ip refers local ip
Third, the verification
1. installation package script starts Zookeeper single node Example:
# cd /opt/kafka/kafka_2.11-2.1.0
# bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
2. Use kafka-server-start.sh start kafka services:
# bin/kafka-server-start.sh config/server.properties
3. Use kafka-topics.sh create partitions but single copy of the topic test
# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
4. Send message kafka-console-producer.sh
# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
5. kafka-console-consumer.sh terminal receives the message and print
# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
Fourth, configure the boot from Kai (systemctl)
1. Create a zookeeper service and kafka service configuration files in / lib / systemd / system / directory.
# vim zookeeper.service
zookeeper.service add content:
[Unit]
Description=Zookeeper service
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/jdk-11.0.1/bin"
User=root
Group=root
ExecStart=/opt/kafka/kafka_2.11-2.1.0/bin/zookeeper-server-start.sh /opt/kafka/kafka_2.11-2.1.0/config/zookeeper.properties
ExecStop=/opt/kafka/kafka_2.11-2.1.0/bin/zookeeper-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
# vim kafka.service
kafka.service add content:
[Unit]
Description=Apache Kafka server (broker)
After=network.target zookeeper.service
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/jdk-11.0.1/bin"
User=root
Group=root
ExecStart=/opt/kafka/kafka_2.11-2.1.0/bin/kafka-server-start.sh /opt/kafka/kafka_2.11-2.1.0/config/server.properties
ExecStop=/opt/kafka/kafka_2.11-2.1.0/bin/kafka-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Note: The above two files the appropriate changes according to their own and kafka jdk installation directory.
2. Refresh configuration.
# systemctl daemon-reload
3. zookeeper, kafka service to join the post.
#systemctl enable zookeeper
#systemctl enable kafka
4. systemctl startup / shutdown / restart zookeeper, kafka service systemctl start / stop / restart zookeeper / kafka.
Note: Before starting kafka must first start zookeeper.
# systemctl start zookeeper
# systemctl start kafka
5. Check status.
# systemctl status zookeeper
# systemctl status kafka