Home > System Tutorial > LINUX > Step-by-step guide: Installing Kafka from scratch on Linux

Step-by-step guide: Installing Kafka from scratch on Linux

WBOY
Release: 2024-01-31 15:09:07
Original
479 people have browsed it

1. Preparation

Before starting the installation, you need to ensure that your system meets the following requirements:

  • Operating system: Ubuntu 16.04 or higher
  • Memory: At least 4GB
  • Hard disk space: At least 500GB
  • Java: Version 8 or higher
  • ZooKeeper: Version 3.4 or higher

2. Install Java

  1. Use the following command to update the system package list:
sudo apt-get update
Copy after login
  1. Install Java:
sudo apt-get install openjdk-8-jdk
Copy after login
  1. Verify whether Java has been successfully installed:
java -version
Copy after login

3. Install ZooKeeper

  1. Download ZooKeeper:
wget https://mirrors.estointernet.in/apache/zookeeper/zookeeper-3.6.3/zookeeper-3.6.3.tar.gz
Copy after login
  1. Unzip ZooKeeper:
tar -xzvf zookeeper-3.6.3.tar.gz
Copy after login
  1. Move ZooKeeper to the installation directory:
sudo mv zookeeper-3.6.3 /opt/zookeeper
Copy after login
  1. Create ZooKeeper users and groups:
sudo groupadd zookeeper
sudo useradd -g zookeeper zookeeper
Copy after login
  1. Grant permissions to the ZooKeeper user and group on the installation directory:
sudo chown -R zookeeper:zookeeper /opt/zookeeper
Copy after login
  1. Edit the ZooKeeper configuration file:
sudo nano /opt/zookeeper/conf/zoo.cfg
Copy after login
  1. In the configuration file , change the values ​​of the dataDir and clientPort options to /var/lib/zookeeper and 2181 respectively:
dataDir=/var/lib/zookeeper
clientPort=2181
Copy after login
  1. Create ZooKeeper data directory:
sudo mkdir -p /var/lib/zookeeper
sudo chown -R zookeeper:zookeeper /var/lib/zookeeper
Copy after login
  1. Start ZooKeeper:
sudo /opt/zookeeper/bin/zkServer.sh start
Copy after login
  1. Verify that ZooKeeper has started successfully:
sudo netstat -plnt | grep 2181
Copy after login

4. Install Kafka

  1. Download Kafka:
wget https://mirrors.estointernet.in/apache/kafka/2.8.1/kafka_2.13-2.8.1.tgz
Copy after login
  1. Unzip Kafka:
tar -xzvf kafka_2.13-2.8.1.tgz
Copy after login
  1. Move Kafka to the installation directory:
sudo mv kafka_2.13-2.8.1 /opt/kafka
Copy after login
  1. Create Kafka user and group:
sudo groupadd kafka
sudo useradd -g kafka kafka
Copy after login
  1. Grant Kafka user and group to the installation directory Permissions:
sudo chown -R kafka:kafka /opt/kafka
Copy after login
  1. Edit Kafka configuration file:
sudo nano /opt/kafka/config/server.properties
Copy after login
  1. In the configuration file, change the values ​​of the following options to:
broker.id=0
listeners=PLAINTEXT://:9092
zookeeper.connect=localhost:2181
Copy after login
  1. Create Kafka data directory:
sudo mkdir -p /var/lib/kafka
sudo chown -R kafka:kafka /var/lib/kafka
Copy after login
  1. Start Kafka:
sudo /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
Copy after login
  1. Verify whether Kafka has been started successfully :
sudo netstat -plnt | grep 9092
Copy after login

5. Test Kafka

  1. Create a topic:
kafka-topics --create --topic test --partitions 1 --replication-factor 1
Copy after login
  1. Send a message to the topic:
kafka-console-producer --topic test --message "Hello, world!"
Copy after login
  1. Receive messages from the topic:
kafka-console-consumer --topic test --from-beginning
Copy after login

6. Summary

You have successfully installed Kafka under Linux. Now, you can start building distributed systems using Kafka.

The above is the detailed content of Step-by-step guide: Installing Kafka from scratch on Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template