无人问津的自留地 >>> 无人问津的自留地 >>>

我始终相信,走过平湖烟雨,岁月山河,
那些经历劫数,尝遍百味的人,会更加生动而干净。

目录
中间件 | Kafka 集群
/  

中间件 | Kafka 集群

# 192.168.2.128
Kafka
# 192.168.2.129
Kafka
# 192.168.2.130
Redis
Zookeeper
Kafka

配置源

deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

安装 docker

 $ wget -qO- https://get.docker.com/ | sh

配置不用 sudo

sudo usermod -aG docker $USER
  • 安装 Zookeeper 和 Kafka
$ docker pull wurstmeister/zookeeper
$ docker pull wurstmeister/kafka

Zookeeper

$ docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper

Kafka

$ docker run -d --name kafka -p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.2.130:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.2.130:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 988f4a6ca13c(镜像ID)

其他两台 Kafka 也连接到 130 的 Zookeeper

kafka01  128

$ docker run -d --name kafka01 -p 9092:9092 \
-e KAFKA_BROKER_ID=1 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.2.130:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.2.128:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 988f4a6ca13c

kafka02 129

$ docker run -d --name kafka02 -p 9092:9092 \
-e KAFKA_BROKER_ID=2 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.2.130:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.2.129:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 988f4a6ca13c

查看 Zookeeper 状态

  • 进入容器
$ docker exec -it bb189e36e49a /bin/bash
  • 查看 ids
[zk: localhost:2181(CONNECTED) 3] ls /brokers/ids
[2, 1, 0]

这边的这个 id 就是我们刚才设置的 KAFKA_BROKER_ID


标题:中间件 | Kafka 集群
版权声明:本文为博主「fpdan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.fpdan.cn/articles/2019/09/18/1568822102000.html