kafka 설치

카프카 프로듀서, 브로커, 컨슈머, 주키퍼로 분류

이전에 jdk가 설치 되어 있어야 한다.


Zookeeper 설치


$wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz

주키퍼는 서버 여러대를 클러스터로 구성하고, 분산 애플리케이션들이 각각 클라이언트가 되어 주키퍼 서버들과 커넥션을 맺은후, 상태 정보를 주고받음

상태정보들은 znode라 불리는곳에 key-value형태로 저장

znode에 key-value형태로 저장된 것을 이용하여 분산 애플리케이션들은 서로 데이터를 주고 받음

znode는 데이터를 저장하기 위한 공간의 이름으로 컴퓨터의 파일이나 폴더의 개념

znode에 저장하는 데이터 크기는 byte에서 kilobyte정도로 매우 작음

디렉토리와 비슷한 형태로 자식노드를 가지고 있는 계층형으로 구성


지노드는 데이터 변경 등에 유효성 검사 등을 위해 버전 번호를 관리, 데이터가 변경될 때마다 지노드의 번호가 증가


주키퍼에 저장되는 데이터는 모두 메모리에 저장되어 처리량이 크고 속도도 빠르다.


주키퍼는 별도의 디렉토리를 사용

디렉토리에는 지노드의 복사본인 스냅샷과 트랜잭션 로그들이 저장

(지노드의 변경이 일어나면 트랜잭션 로그에 추가 됨) 로그가 어느정도 커지면 모든 지노드의 상태 스탭샷이 파일시스템에 저장


주키퍼 설치시에 위와 같은 스냅샷과 트랜잭션을 저장할 디렉토리가필요


$mkdir -p ~/zdata

주키퍼 노드를 구분 하기 위한 id를 만들어야한다.

zookeeper에서는 myid라고 부르며 정수 형태로 만들어주면된다.

$cd ~/zdata
$echo 1 > myid

다른 주키퍼 아이디들도 myid를 각자 붙여준다.


Zookeeper_home/config/zoo.cfg 파일

# The number of milliseconds of each tick 주키퍼가 사용하는 시간에 대한 기본측정단위
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take 초기 연결하는 시간에 대한 타임아웃 tick의 수 
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement 팔로워가 리더와 동기화 하는 시간에 대한 타임아웃 tick의 수 
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes. 주키퍼 트랜잭션 로그와 스냅샷이 저장되는 데이터 저장경로
dataDir=/home/morriskim/kafka/data
# the port at which the clients will connect 주키퍼 TCP 사용 포트
clientPort=2181
...
server.1=localhost:2888:3888 // 주키퍼 앙상블을 위산 서버 설정, server.id 형식으로 사용

여기서 아이디를 잘 기억해야하는데 이 아이디는 서버의 id로 !!

2888포트와 3888포트는 노드끼리 연결하고, 리더 선출에 사용됨

Zookeeper 실행

$zkServer.sh start

service 등록해서 실행도 가능


Kafka 설치

$wget http://apache.mirror.cdnetworks.com/kafka/2.1.0/kafka_2.11-2.1.0.tgz

$./kafka-topics.sh --topic morris --create --zookeeper 127.0.0.1:2181 --partitions 1 --replication-factor 1

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Created topic "morris".

Producer

[morriskim@localhost bin]$ ./kafka-console-producer.sh --broker-list localhost:9092 --topic morris
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
>hi
>are you there?
>

consumer

[morriskim@localhost bin]$ ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic morris --from-beginning
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
hi
are you there?

+ Recent posts