0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOSでApache Kafkaを動かす

Last updated at Posted at 2019-09-04

#はじめに
CentOSにKafkaをダウンロードして、トピックを作りメッセージを送受信する手順です

#環境
CentOS 7.2.1511
※自分は、MacOS上のCentOSで動かしています
macOS+Vagrant(CentOS)でpysparkを動かす

#kafkaのダウンロードと解凍

$ sudo su -
# wget -O /tmp/kafka_2.12-2.3.0.tgz http://ftp.jaist.ac.jp/pub/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz
# tar -xzf /tmp/kafka_2.12-2.3.0.tgz -C /opt
# mv /opt/kafka_2.12-2.3.0 /opt/kafka

#Zookeeperをバックグラウンドで起動させる

# nohup /opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties &

#kafkaをバックグラウンドで起動させる

# nohup /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties &

#トピックの作成

# /opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic sample-topic
Created topic sample-topic.

#トピックの確認

# /opt/kafka/bin/kafka-topics.sh --list --zookeeper localhost:2181 sample-topic

#トピックにメッセージを送信する
※コンソールが立ち上がるので、メッセージ(なんでも良い)を打ち込んでください

# /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic sample-topic

>value1
>value2
>value3

#メッセージを受信する
※受信できていれば、先ほど打ち込んだメッセージが表示されます

# /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic sample-topic --from-beginning

value1
value2
value3
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?