setup - zookeeper + kafka + kafka-manager

INSANEZINDOL·2021년 11월 25일
0

docker

목록 보기
10/16
post-thumbnail
  1. docker-compose.yml 작성
version: '2'

services:

zookeeper:
	container_name: zookeeper
	image: wurstmeister/zookeeper
	ports:
		- "2181:2181"	
	restart: always

kafka:
	image: wurstmeister/kafka
	container_name: kafka
	environment:
		KAFKA_ADVERTISED_LISTENERS: [PLAINTEXT://localhost:9092](plaintext://localhost:9092)
		KAFKA_LISTENERS: [PLAINTEXT://0.0.0.0:9092](plaintext://0.0.0.0:9092)
		KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
		KAFKA_ADVERTISED_PORT: 9092
		KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
		KAFKA_CREATE_TOPICS: "test:1:1,dean:1:1"
	volumes:
		- /var/run/docker.sock:/var/run/docker.sock
	ports:
		- "9092:9092"
	depends_on:
		- zookeeper
	restart: always

kafka-manager:
	container_name: kafka-manager
	image: sheepkiller/kafka-manager
	ports:
		- "9000:9000"
	environment:
	ZK_HOSTS: "zookeeper:2181"
	APPLICATION_SECRET: "letmein"
	restart: always
  1. 설치
docker-compose up -d
  1. docker ps 로 이름 확인
docker ps -a
  1. bash shell 접속
docker exec -it kafka bash
  1. 토픽 확인
/opt/kafka/bin/kafka-topics.sh --describe --topic test --zookeeper zookeeper

Topic:test PartitionCount:1 ReplicationFactor:1 Configs:
Topic: test Partition: 0 Leader: 1001 Replicas: 1001 Isr: 1001
  1. 카프카에 메시지를 send 했을 때 모니터링하기 위한 모드 스크립트 실행
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test
  1. 현재 생성된 topic 조회
/opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper --list
  1. topic 생성 (dean)
/opt/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper --replication-factor 1 --partitions 1 --topic dean
  1. topic 삭제 (dean)
/opt/kafka/bin/kafka-topics.sh --delete --zookeeper zookeeper --topic dean
  1. 로그 확인
docker logs --tail 20 -f kafka
  1. 브라우저 접속 확인
💡 [http://localhost:9000](http://ubuntu-server:9000/)

[zookeeper + kafka 재기동]

  1. kafka stop
/usr/local/kafka/bin/kafka-server-stop.sh
  1. zookeeper stop
/usr/local/kafka/bin/zookeeper-server-stop.sh
  1. zookeeper start
/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
  1. kafka start
/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
profile
Java Backend Developer

0개의 댓글

관련 채용 정보