DEV Community

Goffity Corleone
Goffity Corleone

Posted on

Install Apache Kafka on CentOS

How to install apache Kafka on centos 7.

  1. Prerequisite.
  2. Download the Kafka package.
  3. Create an OS service.

1. Prerequisite

Make sure your OS has JAVA and Scala.
Following this command to chack a JAVA installed.

java -version 
Enter fullscreen mode Exit fullscreen mode

Output should be

openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+11)
OpenJDK 64-Bit Server VM (build 11.0.8+11, mixed mode)
Enter fullscreen mode Exit fullscreen mode

if not or your machine hasn't JDK

yum update -y
sudo yum install java-1.8.0-openjdk -y
Enter fullscreen mode Exit fullscreen mode

Scala

wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.rpm

sudo yum install scala-2.11.8.rpm -y
Enter fullscreen mode Exit fullscreen mode

2. Download the Kafka package.

wget https://downloads.apache.org/kafka/2.6.0/kafka_2.13-2.6.0.tgz -O /opt/kafka_2.13-2.6.0.tgz

tar -xvf /opt/kafka_2.13-2.6.0.tgz

ln -s /opt/kafka_2.13-2.6.0 /opt/kafka

useradd kafka
chown -R kafka:kafka /opt/kafka*
Enter fullscreen mode Exit fullscreen mode

3. Create an OS service.

3.1 Create zookeeper service.

Create service flie "zookeeper.service" in /etc/systemd/system/

[Unit] 
Description=zookeeper 
After=syslog.target network.target 
[Service] 
Type=simple 
User=kafka 
Group=kafka 
ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh 
[Install] 
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

3.2 Create Kafka service.

Create file "kafka.service" in /etc/systemd/system/

[Unit] 
Description=Apache Kafka 
Requires=zookeeper.service 
After=zookeeper.service 
[Service] 
Type=simple 
User=kafka 
Group=kafka 
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties 
ExecStop=/opt/kafka/bin/kafka-server-stop.sh 
[Install] 
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

3.3 Enable and start service

sudo systemctl daemon-reload
sudo systemctl enable zookeeper.service
sudo systemctl enable kafka.service
sudo systemctl start zookeeper.service
sudo systemctl start kafka.service
Enter fullscreen mode Exit fullscreen mode

Top comments (0)