-
로컬에 주키퍼, 카프카 설치하기 (Standalone)개발자 라이프/카프카 2020. 1. 14. 21:04반응형
들어가며
이번 글은 주키퍼와 카프카를 로컬에 설치하는 방법에 대해 알아봅니다. 로컬에 설치하기 때문에 주키퍼와 카프카 모두 standalone 방식으로 구성합니다. 로컬에서 개발 환경을 구성하고 싶으신 분들은 참고하시면 되겠습니다. :)
또한 설치하는 주키퍼와 카프카의 설정은 최소 설정입니다. 혹여나 커스텀한 설정이 필요하신 분은 설정 파일을 별도로 수정하시면 됩니다.
기본적인 것들
Java
기존 설치 확인
javac -version
OpenJdk 설치
sudo yum install java-1.8.0-openjdk-devel.x86_64 -y
정상 설치 확인
javac -version
wget
기존 설치 확인
yum list installed | grep wget
설치
sudo yum install wget -y
정상 설치 확인
yum list installed | grep wget
ZooKeeper
Zk 설치 (3.4.14)
zk 파일 다운로드
wget http://mirror.navercorp.com/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar 압축 해제
tar -xzf zookeeper-3.4.14.tar.gz
심볼릭 링크 생성
ln -s zookeeper-3.4.14 zookeeper
환경 변수 설정
cd zookeeper export ZK_HOME=$PWD ~~e~~xport ZK_DATA_DIR=/usr/local/lib/zookeeper/data # 앞으로 사용할 data 디렉토리 관련 환경변수
Zk Service 구성
data 디렉터리 구성
sudo mkdir -p $ZK_DATA_DIR
myid 설정
sudo sh -c "echo 1 > $ZK_DATA_DIR/myid" # 쌍따옴표 주의
zoo.cfg 설정
echo " tickTime=2000 dataDir=$ZK_DATA_DIR clientPort=2181 initLimit=5 syncLimit=2 ### HOSTS #server.1=zk-1:2888:3888 #server.2=zk-2:2888:3888 #server.3=zk3:2888:3888 " > $ZK_HOME/conf/zoo.cfg
zookeeper.service 생성
sudo sh -c "echo ' [Unit] Description=ZooKeeper Service Documentation=http://zookeeper.apache.org Requires=network.target After=network.target [Service] Type=forking User=root Group=root ExecStart=$ZK_HOME/bin/zkServer.sh start $ZK_HOME/conf/zoo.cfg ExecStop=$ZK_HOME/bin/zkServer.sh stop $ZK_HOME/conf/zoo.cfg ExecReload=$ZK_HOME/bin/zkServer.sh restart $ZK_HOME/conf/zoo.cfg WorkingDirectory=$(dirname $ZK_DATA_DIR) [Install] WantedBy=default.target ' > /etc/systemd/system/zookeeper.service"
데몬 리로드
sudo systemctl daemon-reload
Zk 실행
sudo systemctl start zookeeper sudo systemctl status zookeeper
Kafka
kafka 설치 (2.3.1)
파일 다운로드
wget http://mirror.navercorp.com/apache/kafka/2.3.1/kafka_2.12-2.3.1.tgz
tar 압축 해제
tar -xzf kafka_2.12-2.3.1.tgz
심볼릭 링크 생성
ln -s kafka_2.12-2.3.1 kafka
환경 변수 등록
cd kafka export KAFKA_HOME=$PWD export KAFKA_DATA_DIR=/usr/local/lib/kafka/data export KAFKA_BROKER_ID=1 export KAFKA_ZK_CONNECT=localhost:2181 export KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 export KAFKA_ADVERTISED_LISTENERS="PLAINTEXT://localhost:9092"
Kafka 서비스 구성
data 디렉토리 구성
sudo mkdir -p $KAFKA_DATA_DIR/kafka-logs
설정 파일 수정
echo " # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the 'License'); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################# Server Basics ############################# broker.id=$KAFKA_BROKER_ID ############################# Socket Server Settings ############################# advertised.listeners=$KAFKA_ADVERTISED_LISTENERS num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 ############################# Log Basics ############################# log.dirs=$KAFKA_DATA_DIR/kafka-logs num.partitions=1 num.recovery.threads.per.data.dir=1 ############################# Internal Topic Settings ############################# offsets.topic.replication.factor=$KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 ############################# Log Flush Policy ############################# ############################# Log Retention Policy ############################# log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 ############################# Zookeeper ############################# zookeeper.connect=$KAFKA_ZK_CONNECT zookeeper.connection.timeout.ms=6000 " > $KAFKA_HOME/config/server-min.properties
kafka-server.service
sudo sh -c "echo ' [Unit] Description=kafka-server After=network.target [Service] Type=simple User=root Group=root SyslogIdentifier=kafka-server WorkingDirectory=$KAFKA_HOME Restart=no RestartSec=0s ExecStart=$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server-min.properties ExecStop=$KAFKA_HOME/bin/kafka-server-stop.sh [Install] WantedBy=multi-user.target ' > /etc/systemd/system/kafka-server.service"
데몬 리로드
sudo systemctl daemon-reload
Kafka 실행
sudo systemctl start kafka-server sudo systemctl status kafka-server
마무리
이번 글을 통해 로컬에 주키퍼와 카프카를 설치하는 방법에 대해 알아봤습니다. 혹여 틀린 부분이나 부족한 부분은 댓글을 통해 알려 주시기 바랍니다. 감사합니다. :)
반응형