2013년 7월 22일 월요일

Apache Kafka 0.8 설치

Apache Kafka 0.8 설치



  1. 계정설정
   계정 설정은 반드시 해야 할 필요는 없다.
groupadd -g 3320 kafka
useradd -m -d /usr/local/kafka -s /bin/bash -u 3320 -g 3320 kafka


  1. 프로그램 설치
현재 최신버전은 0.8이며, github에서 다운로드 받을 수 있다.


Stable 릴리즈는 아래의 홈페이지에서 다운로드 할 수 있다.


다운로드 후, 패키지 업데이트를 실행한다.
0.72이하 버전이 설치되어 있는 경우는 서로 호환이 되지 않으니 데이터를 삭제하고 설치해야 함.
$ ./sbt update
$ ./sbt package
$ ./sbt assembly-package-dependency


  1. 설정
A) consumer.properties
분산으로 설치된 경우는 zookeeper  ip만 여러 개 적어주면된다.
# zookeeper 접속 ip
zookeeper.connect=172.27.241.212:2181,172.27.175.60:2181,172.27.139.205:2181


# zookeeper접속 타임아웃
zookeeper.connection.timeout.ms=1000000


#consumer group id
group.id=test-consumer-group


B) producer.properties
분산으로 설치하는 경우는 metadata.broker.list를 분산 할 노드 수만큼 적어준다.
# format: host1:port1,host2:port2 ...
metadata.broker.list=1:172.27.241.212:9092,2:172.27.175.60:9092,3:172.27.139.205:9092
# 메시지 동기식 비동기식 (서버까지) 전송 설정 –sync, async
producer.type=sync


# 압축 유무 : 0, 1, 2 for none, gzip, snappy, respectivally
compression.codec=none


# message encoder
serializer.class=kafka.serializer.DefaultEncoder


C) server.properties
분산하는 경우는 broker.id를 분산 할 노드에 중복되지 않도록 적어주고, num.partition의 개수를 적절 히 잡아준다.
로그파일이 재대로 생성되지 않거나 프로세스가 기동되지 않으면 로그파일 설정을 확인한다.
# 브로커 ID – 분산으로 설치하는 경우 id를 다르게 적어주면 된다.
broker.id=0
# The port the socket server listens on
port=9092


# The number of threads handling network requests
num.network.threads=4


# The number of threads doing disk I/O
num.io.threads=4


# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=1048576


# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=1048576


# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


# 로그파일 저장위치 (로그파일이 안 생기거나 기동이 제대로 안되면 확인)
log.dir=/usr/local/kafka/logs


# The number of logical partitions per topic per server. More partitions allow greater parallelism
# for consumption, but also mean more files.
num.partitions=5


# The number of messages to accept before forcing a flush of data to disk
log.flush.interval.messages=10000


# The maximum amount of time a message can sit in a log before we force a flush
log.flush.interval.ms=1000
# The minimum age of a log file to be eligible for deletion
log.retention.hours=168
# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=536870912
# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.cleanup.interval.mins=1


# zookeeper 노드 정보
zookeeper.connect=172.27.241.212:2181,172.27.175.60:2181,172.27.139.205:2181


# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=1000000


# metrics reporter properties
kafka.metrics.polling.interval.secs=5
kafka.metrics.reporters=kafka.metrics.KafkaCSVMetricsReporter
kafka.csv.metrics.dir=/tmp/kafka_metrics
# Disable csv reporting by default.
kafka.csv.metrics.reporter.enabled=false


D) zookeeper.properties
kafka는 분산 한 노드 수만큼, zookeeper를 실행한다.
kafka가 설치된 모든 노드를 등록한다.
# the directory where the snapshot is stored.
dataDir=/usr/local/kafka/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
initLimit=5
syncLimit=2

# 서버.id = 노드ip:peer끼리 통신포트:leader선출 시, 사용하는 포트
server.0=172.27.241.212:2888:3888
server.1=172.27.175.60:2888:3888
server.2=172.27.139.205:2888:3888


설정 후, /usr/local/kafka/zookeeper 디렉토리에 myid라는 파일을 생성하고, zookeeper.properties에 설정한 서버 id대로 각 서버에 맞춰 id를 적어준다
echo “0” > /usr/local/kafka/zookeeper/myid


  1. 기동
   Classpath 및 Config 설치만 제대로 되면, 정상적으로 동작한다.
A) Producer
bin/zookeeper-server-start.sh config/zookeeper.properties


B) Consumer
bin/kafka-server-start.sh config/server.properties


  1. 테스트
A) Producer
bin/kafka-console-producer.sh --broker-list localhost:2181 --topic test
This is a test
This is more testing


B) Consumer
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
This is a test
This is more testing



댓글 없음:

댓글 쓰기