kafka 설치 및 구성/구성 가이드

cluster(3.6.0) 단일 서버ver 구성가이드

saay-hi 2024. 6. 21. 14:11
구성 1대의 서버에 테스트 용도로 클러스터 구성 ( 각 node id, 사용하는 디렉터리, port 번호 안겹게 진행)
구조

 

1. Zookeepr cluster 구축

참고) 

분산 서버 각 서버마다 zookeeper.properteis 파일을 server host만 변경하여 사용 / 나머진 동일
단일 서버 zookeeper.properties 여러 개 생성(copy)하여 client port, dataDir 서로 다르게 변경 (host는 동일)

1) zookeeper config 수정

$>vi zookeeper.properties
 

 

 

2) Node id 설정

-dataDir 디렉토리 아래의 myid라는 파일을 만든 후,  instance id를 명시해 주어야 함

-myid설정값은  zookeeper node끼리 구분하는 값으로, zookeeper.properties중 자신의 server.{id}와 일치해 함

echo 1 > /tmp/zookeeper/myid
echo 2 > /tmp/zookeeper/myid
echo 3 > /tmp/zookeeper/myid

 

2. Kafka cluster 설정

Broker.id  Kafka들의 노드 아이디 같은 것으로서 서로 다르게 설정
Listeners 단일 서버에서는 각 Kafka마다 port번호만 서로 다르게 변경, 분산은 필요없음
Log.dirs 기본으로 tmp로 되어있으니 변경, 단일서버는 각자 다른 위치로 변경
Zookeeper.connect Zookeeper 노드들을 설정

 

1) 각 broker id 설정

$>vi server.properties
 


$>vi server2.properties
 


$>vi server3.properties
 

 

2)  zookeeper와 연동을 위하여 zookeeper.connect 라는 항목에 zookeeper 인스턴스들의 정보를 입력

-broker.id 변경 불가. 변경 시 연결 안됨 ( connectionException : 연결 거부됨이 반복 )

########### server basics ###############
broker.id=0  #개별 broker id 값 지정
########### socket server settings  ###############
listeners=PLAINTEXT://192.168.56.105:9092  #broker 2는 9093, broker3은 9094로 수정
num.network.threads=3
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
########### log basics ###############
log.dirs=/tmp/kafka-logs #broker 2는 kafka2-logs , broker3은 kafka3-logs로 수정
num.partitions=3      #3으로 하지 않은 경우에도 자동으로 partition 3개 생성됨
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
########### log retention ###############
log.retention.hours=168
log.retention.check.interval.ms=300000
########### zookeeper ###############
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183    #broker 3대 모두 동일하게 작성
zookeeper.connection.timeout.ms=18000
########### group coordinator settings  ###############
group.initial.rebalance.delay.ms=0

 

3. 단일 서버 topic 생성 test

$>$ ./kafka-topics.sh --bootstrap-server 192.168.56.105:9092 --create --topic cluster_test
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic cluster_test.
 
$> ./kafka-topics.sh --bootstrap-server 192.168.56.105:9092 --list
__consumer_offsets
basic-consere
basic-consumer
basic-topic
basic-topic1
basic-topic2
basic-topic3
cluster_test
test_topic
thetechcheck
time_test_topic
time_test_topic1
time_test_topic2
 
$> ./kafka-topics.sh --bootstrap-server 192.168.56.105:9093 --list
__consumer_offsets
basic-consere
basic-consumer
basic-topic
basic-topic1
basic-topic2
basic-topic3
cluster_test
test_topic
thetechcheck
time_test_topic
time_test_topic1
time_test_topic2
 
$> ./kafka-topics.sh --bootstrap-server 192.168.56.105:9094 --list
__consumer_offsets
basic-consere
basic-consumer
basic-topic
basic-topic1
basic-topic2
basic-topic3
cluster_test
test_topic
thetechcheck
time_test_topic
time_test_topic1
time_test_topic2

 

4. 메시지 취득 확인

[kafka@localhost bin]$ ./kafka-console-consumer.sh --bootstrap-server 192.168.56.105:9092 --topic cluster_test --from-beginning
test1
^CProcessed a total of 1 messages
[kafka@localhost bin]$ ./kafka-console-consumer.sh --bootstrap-server 192.168.56.105:9093 --topic cluster_test --from-beginning
test1
^CProcessed a total of 1 messages
^[[A[kafka@localhost bi./kafka-console-consumer.sh --bootstrap-server 192.168.56.105:9094 --topic cluster_test --from-beginning
test1
^CProcessed a total of 1 messages