1. 程式人生 > >docker:通過docker-compose部署kafka

docker:通過docker-compose部署kafka

通過github安裝1.14.0版本的docker-compose

curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

docker-compose -version

安裝命令補全
確保bash completion已經安裝,如果當前使用非最小安裝的Linux,bash completion已經OK了,如果是在MAC上,可以使用brew install bash-completion來安裝
將completion指令碼放在/etc/bash_completion.d/(在MAC上是/usr/local/etc/bash_completion.d/)

 curl -L https://raw.githubusercontent.com/docker/compose/1.1.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose 

下載映象

docker pull wurstmeister/kafka

docker-compose.yml指令碼

version: '2'

services:
  kafka1:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ZOOKEEPER_CONNECT: ip:2181
      KAFKA_BROKER_ID: 1
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_CREATE_TOPICS: "stream-in:1:1,stream-out:1:1"
  
    container_name: kafka

重點(不然外網無法訪問):

cd /opt/kafka_2.11-1.1.0/config
vi  server.properties 

advertised.listeners=PLAINTEXT://ip:9092

在docker-compose.yml指令碼存放路徑下執行docker-compose up -d