>  기사  >  백엔드 개발  >  Kafka 및 Zookeeper 설치 방법을 소개합니다.

Kafka 및 Zookeeper 설치 방법을 소개합니다.

藏色散人
藏色散人앞으로
2021-11-23 15:23:502245검색

이 글은 go 언어튜토리얼 칼럼에서 Kafka와 Zookeeper 설치 방법을 소개하기 위해 작성한 글입니다. 도움이 필요한 친구들에게 도움이 되길 바랍니다!

kafka 및 Zookeeper 설치

Write compose

  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    volumes:
        - ./data/etc/localtime:/etc/localtime
        - ./data/var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.110.147   ## 宿主机IP
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_PORT: 9092
  kafka-manager:
    image: sheepkiller/kafka-manager
    environment:
        ZK_HOSTS:  192.168.110.147                  ## zookeeper地址
    ports:
      - "9091:9000"                                 # 宿主机port:container_port

설치 시작

luwei@luweideMacBook-Pro-2 lnmp % docker-compose up -d zookeeper
Pulling zookeeper (wurstmeister/zookeeper:)...
latest: Pulling from wurstmeister/zookeeper
a3ed95caeb02: Pull complete
ef38b711a50f: Pull complete
e057c74597c7: Pull complete
666c214f6385: Pull complete
c3d6a96f1ffc: Pull complete
3fe26a83e0ca: Pull complete
3d3a7dd3a3b1: Pull complete
f8cc938abe5f: Pull complete
9978b75f7a58: Pull complete
4d4dbcc8f8cc: Pull complete
8b130a9baa49: Pull complete
6b9611650a73: Pull complete
5df5aac51927: Pull complete
76eea4448d9b: Pull complete
8b66990876c6: Pull complete
f0dd38204b6f: Pull complete
Digest: sha256:7a7fd44a72104bfbd24a77844bad5fabc86485b036f988ea927d1780782a6680
Status: Downloaded newer image for wurstmeister/zookeeper:latest
Creating lnmp_zookeeper_1 ... done
luwei@luweideMacBook-Pro-2 lnmp % docker-compose up -d kafka
lnmp_kafka_1 is up-to-date
luwei@luweideMacBook-Pro-2 lnmp % docker-compose up -d kafka        
Starting lnmp_kafka_1 ... done

설치 결과 보기

luwei@luweideMacBook-Pro-2 ~ % docker ps
CONTAINER ID   IMAGE                                                  COMMAND                  CREATED          STATUS                            PORTS                                                NAMES
28a2a3b33856   sheepkiller/kafka-manager                              "./start-kafka-manag…"   3 minutes ago    Up 3 minutes                      0.0.0.0:9091->9000/tcp                               lnmp_kafka-manager_1
d6ae300116f3   wurstmeister/zookeeper                                 "/bin/sh -c '/usr/sb…"   9 minutes ago    Up 8 minutes                      22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   lnmp_zookeeper_1
c9de041d5ace   wurstmeister/kafka                                     "start-kafka.sh"         15 minutes ago   Up 4 seconds                      0.0.0.0:9092->9092/tcp                               lnmp_kafka_1
92b5e1563062   mysql:5.7.16                                           "docker-entrypoint.s…"   2 weeks ago      Up 6 hours                        0.0.0.0:3307->3306/tcp                               my_mysql57
29f0b85f1284   registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   3 weeks ago      Up 6 hours                        0.0.0.0:1521->1521/tcp                               oracle
89c169b8bd14   nginx:alpine                                           "/docker-entrypoint.…"   4 weeks ago      Up 6 hours (healthy)              0.0.0.0:81->80/tcp, 0.0.0.0:444->443/tcp             nginx
e0e4fa4bf177   lnmp_php72                                             "entrypoint php-fpm"     4 weeks ago      Up 6 hours (healthy)              9000-9001/tcp                                        php72
a1ddf67627cd   lnmp_php56                                             "entrypoint php-fpm"     4 weeks ago      Up 6 hours (healthy)              9000/tcp                                             php56
324aa6c8b071   lnmp_php71                                             "entrypoint php-fpm"     4 weeks ago      Up 6 hours (healthy)              9000/tcp                                             php71
4fd5d2ce7612   mongo:4.4.0                                            "docker-entrypoint.s…"   4 weeks ago      Up 6 hours                        0.0.0.0:27018->27017/tcp                             mongo4.4
f212f81e0546   redis:4-alpine                                         "docker-entrypoint.s…"   4 weeks ago      Up 6 hours (healthy)              0.0.0.0:6379->6379/tcp                               redis
e42962aa16c8   mysql:5.6                                              "docker-entrypoint.s…"   4 weeks ago      Restarting (137) 50 seconds ago                                                        mysql
luwei@luweideMacBook-Pro-2 ~ %

kafka 컨테이너 연결

luwei@luweideMacBook-Pro-2 ~ % docker exec -it lnmp_kafka_1 /bin/bash
bash-5.1#

주제 만들기

bash-5.1# find / -name kafka-topics.sh
/opt/kafka_2.13-2.7.1/bin/kafka-topics.sh
bash-5.1# /opt/kafka_2.13-2.7.1/bin/kafka-topics.sh --create --zookeeper 192.168.110.147:2181 --replication-factor 1  --partitions 1 --topic test
Created topic test.
bash-5.1#

생성된 주제 보기

bash-5.1# /opt/kafka_2.13-2.7.1/bin/kafka-topics.sh --list --zookeeper 192.168.110.147:2181
test
bash-5.1#

시작 생산자

bash-5.1# find / -name kafka-console-producer.sh
/opt/kafka_2.13-2.7.1/bin/kafka-console-producer.sh
bash-5.1# /opt/kafka_2.13-2.7.1/bin/kafka-console-producer.sh --broker-list 192.168.110.147:9092 --topic mykafka
>hello donglei
[2021-11-22 08:05:19,506] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 3 : {mykafka=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
>

소비자 시작

bash-5.1# /opt/kafka_2.13-2.7.1/bin/kafka-console-consumer.sh --bootstrap-server 192.168.110.147:9092 --topic mykafka --from-beginning
hello donglei

위 내용은 Kafka 및 Zookeeper 설치 방법을 소개합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 learnku.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제