IT 꿈나무의 일상

kafka standalone으로 설치하기 (1) 본문

IT 관련

kafka standalone으로 설치하기 (1)

viera 2021. 12. 27. 23:20
반응형
## 카프카를 설치하기 위해서는 Zookeeper를 설치해야 합니다. 
## 해당 글은 서버 한대에 zookeeper와 kafka를 모두 실행합니다.

 

1. 카프카 유저생성 하기
[root@localhost home]# useradd kafka
[root@localhost home]# passwd kafka
[root@localhost home]# chmod -R 777 /home/kafka​

 

2. 카프카 설치
# app과 data 디렉토리 생성
[kafka@localhost ~]$ mkdir app
[kafka@localhost ~]$ mkdir data
[kafka@localhost ~]$ ls
app  data

# 카프카 2.12-2.8.0 버전 다운로드
[kafka@localhost ~]$ cd app/
[kafka@localhost app]$ wget https://mirror.navercorp.com/apache/kafka/2.8.0/kafka_2.12-2.8.0.tgz

--2021-07-19 18:35:37--  https://mirror.navercorp.com/apache/kafka/2.8.0/kafka_2.12-2.8.0.tgz
Resolving mirror.navercorp.com (mirror.navercorp.com)... 125.209.216.167
Connecting to mirror.navercorp.com (mirror.navercorp.com)|125.209.216.167|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 71542357 (68M) [application/octet-stream]
Saving to: ‘kafka_2.12-2.8.0.tgz’

100%[====================================================================>] 71,542,357  27.5MB/s   in 2.5s   

2021-07-19 18:35:40 (27.5 MB/s) - ‘kafka_2.12-2.8.0.tgz’ saved [71542357/71542357]
 
3. 압축풀기
[kafka@localhost app]$ tar xvfzp kafka_2.12-2.8.0.tgz
 
4. 편의를 위해 심볼릭 링크 걸어주기
[kafka@localhost app]$ ln -s kafka_2.12-2.8.0 kafka
[kafka@localhost app]$ ls
kafka  kafka_2.12-2.8.0  kafka_2.12-2.8.0.tgz
 
5. zookeeper 와 kafka의 데이터 디렉토리를 만든다
[kafka@localhost data]$ mkdir zookeeper1
[kafka@localhost data]$ mkdir zookeeper2
[kafka@localhost data]$ mkdir zookeeper3

[kafka@localhost data]$ chmod -R 777 zookeeper1
[kafka@localhost data]$ chmod -R 777 zookeeper2
[kafka@localhost data]$ chmod -R 777 zookeeper3
 

## 주키퍼 설정 시작 ##

6. zookeeper 의 노드 구분 ID 를 생성
[kafka@localhost data]$ echo 1 > /home/kafka/data/zookeeper1/myid
[kafka@localhost data]$ echo 2 > /home/kafka/data/zookeeper2/myid  
[kafka@localhost data]$ echo 3 > /home/kafka/data/zookeeper3/myid

 

7. 카프카설치경로($KAFKA_HOME)/config 에서 zookeeper 설정 파일을 수정하기
[kafka@localhost data]$ cd /home/kafka/app/kafka/config

# 해당 경로에서 zookeeper.properties 파일을 복사하여 설정파일 만들기
[kafka@localhost config]$ cp zookeeper.properties zookeeper1.properties
[kafka@localhost config]$ cp zookeeper.properties zookeeper2.properties
[kafka@localhost config]$ cp zookeeper.properties zookeeper3.properties
# 설정파일 수정 (3개의 파일 모두 수행)

vim zookeeper1.properties
---------------------
#zookeeper location and multi server setting
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2181
dataDir=/home/kafka/data/zookeeper1/
server.1={IP주소입력}:28881:38881
server.2={IP주소입력}:28882:38882
server.3={IP주소입력}:28883:38883
---------------------

vim zookeeper2.properties
---------------------
#zookeeper location and multi server setting
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2182
dataDir=/home/kafka/data/zookeeper2/
server.1={IP주소입력}:28881:38881
server.2={IP주소입력}:28882:38882
server.3={IP주소입력}:28883:38883
---------------------

vim zookeeper3.properties
---------------------
#zookeeper location and multi server setting
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2183
dataDir=/home/kafka/data/zookeeper3/
server.1={IP주소입력}:28881:38881
server.2={IP주소입력}:28882:38882
server.3={IP주소입력}:28883:38883
---------------------
 
8. zookeeper 실행, 중지 스크립트 작성
[kafka@localhost config]$ cd /home/kafka/app/kafka

# 실행 스크립트 생성
vi start_zookeeper1.sh
------------------------
nohup /home/kafka/app/kafka/bin/zookeeper-server-start.sh -daemon /home/kafka/app/kafka/config/zookeeper1.properties > /dev/null 2>&1 &
------------------------

vi start_zookeeper2.sh
------------------------
nohup /home/kafka/app/kafka/bin/zookeeper-server-start.sh -daemon /home/kafka/app/kafka/config/zookeeper2.properties > /dev/null 2>&1 &
------------------------

vi start_zookeeper3.sh
------------------------
nohup /home/kafka/app/kafka/bin/zookeeper-server-start.sh -daemon /home/kafka/app/kafka/config/zookeeper3.properties > /dev/null 2>&1 &
------------------------
# 중지 스크립트
vi stop_zookeeper1.sh
-------------------------
PID=`ps -ef | grep java | grep "zookeeper1" | grep -v grep | awk '{print $2}'`
echo "PID = $PID"
kill ${PID}
-------------------------

vi stop_zookeeper2.sh
-------------------------
PID=`ps -ef | grep java | grep "zookeeper2" | grep -v grep | awk '{print $2}'`
echo "PID = $PID"
kill ${PID}
-------------------------

vi stop_zookeeper3.sh
-------------------------
PID=`ps -ef | grep java | grep "zookeeper3" | grep -v grep | awk '{print $2}'`
echo "PID = $PID"
kill ${PID}
-------------------------

 

--> kafka standalone으로 설치하기(2)로 이동

반응형
Comments