티스토리 뷰

카테고리 없음

Kafka설치 with 클러스터링

KyeongRok Kim 2022. 3. 27. 01:37

 

1. Requirements

  • 최소 8GB Ram
  • 최소 500GB 스토리지
  • Ubuntu 14.04 이상

2.서버 정보

Cluster구성을 하기 위해 3대의 서버를 띄웠습니다(t3.medium) 각 서버의 퍼블릭IP는 아래와 같습니다.

kafka01 - 15.165.70.95

kafka02 - 15.164.173.104

kafka03 - 13.125.204.30

3. hosts파일 구성

ip주소가 아니라 서버 이름으로 구성 하기 위해 hosts파일에 추가 해줍니다.

kafka01 `/etc/hosts

0.0.0.0 kb-broker01
15.164.173.104 kb-broker02
13.125.204.30 kb-broker03

kafka02 `/etc/hosts

15.165.70.95 kb-broker01
0.0.0.0 kb-broker02
13.125.204.30 kb-broker03

kafka03 `/etc/hosts

15.165.70.95 kb-broker01
15.164.173.104 kb-broker02
0.0.0.0 kb-broker03

4.Zookeeper설정

 

zookeeper설정 파일은 위와 같이 압축을 푼 디렉토리의 `/config에 있습니다.

dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
# Set the port to something non-conflicting if choosing to enable this
admin.enableServer=false
# admin.serverPort=8080

initLimit=5
syncLimit=2
server.1=kb-broker01:2888:3888
server.2=kb-broker02:2888:3888
server.3=kb-broker03:2888:3888

기존 내용에 위 11, 12, 13번줄과 같이 server.1, server.2, server.3을 추가 해줍니다.

 

initLimit, syncLimit 을 설정하지 않으면 다음에 zookeeper를 실행할 때 실행 되지 않습니다.

5.zookeeper 실행

아래 명령어를 이용해 zookeeper를 실행할 수 있습니다.

sh bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

 

하지만 위와 같이 myid file is missing이라고 나오면서 실행이 안됩니다.

6. myid생성

kafka01

mkdir /tmp/zookeeper
echo 1 > /tmp/zookeeper/myid
cat /tmp/zookeeper/myid

kafka02

mkdir /tmp/zookeeper
echo 2 > /tmp/zookeeper/myid
cat /tmp/zookeeper/myid

kafka03

mkdir /tmp/zookeeper
echo 3 > /tmp/zookeeper/myid
cat /tmp/zookeeper/myid

7.다시 zookeeper 실행하기

-daemon 옵션을 주어야 daemon으로 실행 됩니다.

sh bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

8. kafka설정

config/server.properties 의 설정을 아래와 같이 바꿔 줍니다.

kafka01

broker.id=0
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kb-broker01:9092
zookeeper.connect=kb-broker01:2181,kb-broker02:2181,kb-broker03:2181

kafka02

broker.id=1
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kb-broker02:9092
zookeeper.connect=kb-broker01:2181,kb-broker02:2181,kb-broker03:2181

kafka03

broker.id=2
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://kb-broker03:9092
zookeeper.connect=kb-broker01:2181,kb-broker02:2181,kb-broker03:2181

9.Systemd에 Kafka등록 하기

vi /etc/systemd/system/kafka.service

[Unit]
Description=kafka
Requires=network.target remote-fs.target
After=network.target remote-fs.target kafka-zookeeper.service

[Service]
Type=simple
Environment=JAVA_HOME
ExecStart=/root/kafka_2.13-3.1.0/bin/kafka-server-start.sh /root/kafka_2.13-3.1.0/config/server.properties
ExecStop=/root/kafka_2.13-3.1.0/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

10. Kafka실행 하기

systemctl start kafka

11. Topic만들기

bin/kafka-console-producer.sh --broker-list kb-broker01:9092,kb-broker02:9092,kb-broker03:9092 --topic test_log

12.메세지 Produce하기

bin/kafka-console-producer.sh --broker-list kb-broker01:9092,kb-broker02:2,kb-broker03:9092 --topic test_log

13.메세지 Consume하기

bin/kafka-console-consumer.sh --bootstrap-server kb-broker01:9092,kb-broker02:9092,kb-broker03:9092 --topic test_log --from-beginning

참고

Requirements | Confluent Platform 3.1.1

AWS에 카프카 클러스터를 설치, 실행해보기! - YouTube

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함