赞
踩
共三台虚拟机同处overlay网段,每台虚拟机部署一套kafka和zookeeper,kafka_manager安装其中一台虚拟机上即可。
Hostname | IP addr | Port | Listener |
---|---|---|---|
zk1 | docker-swarm分配 | 2183:2181 | |
zk2 | docker-swarm分配 | 2184:2181 | |
zk3 | docker-swarm分配 | 2185:2181 | |
k1 | docker-swarm分配 | 内部9093:9093,外部9193:9193 | kafka1 |
k2 | docker-swarm分配 | 内部9094:9094,外部9194:9194 | kafka2 |
k3 | docker-swarm分配 | 内部9095:9095,外部9195:9195 | kafka3 |
kafka_manager | 8094:9000 |
找到/etc/sysconfig/selinux文件,把其中的SELINUX设置为disabled,保存文件之后重启CentOS系统。
yum update -y
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo [https://download.docker.com/linux/centos/docker-ce.repo](https://download.docker.com/linux/centos/docker-ce.repo)
yum install docker-ce docker-ce-cli containerd.io
docker swarm init --advertise-addr <本虚拟机ip>
管理主机调用初始化swarm集群的命令后会生成一段命令(如下图),将该段命令复制到每台从主机上执行。
docker network ls
docker node ls
docker network create -d overlay --attachable swarm_kafka
docker run -d --restart always --hostname zk1 --name zk1 -p 2183:2181 -v "/root/zookeeper1/data:/data" -v "/root/zookeeper1/datalog:/datalog" -v "/root/zookeeper1/logs:/logs" -e ZOO_MY_ID=1 -e ZOO_SERVERS="server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181" --network swarm_kafka zookeeper:latest
docker run -d --restart always --hostname k1 --name k1 -p 9093:9093 -p 9193:9193 -e KAFKA_BROKER_ID=1 -e KAFKA_LISTENERS="INSIDE://:9093,OUTSIDE://:9193" -e KAFKA_ADVERTISED_LISTENERS="INSIDE://<填虚拟机ip>:9093,OUTSIDE://<填虚拟机ip>:9193" -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" -e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE -e KAFKA_ZOOKEEPER_CONNECT="zk1:2181,zk2:2181,zk3:2181" -e ALLOW_PLAINTEXT_LISTENER='yes' -e JMX_PORT=9999 -v "/root/kafka1/wurstmeister/kafka:/wurstmeister/kafka" -v "/root/kafka1/kafka:/kafka" --network swarm_kafka --link zk1 --link zk2 --link zk3 docker.io/wurstmeister/kafka
docker run -d --restart always --hostname zk2 --name zk2 -p 2184:2181 -v "/root/zookeeper2/data:/data" -v "/root/zookeeper2/datalog:/datalog" -v "/root/zookeeper2/logs:/logs" -e ZOO_MY_ID=2 -e ZOO_SERVERS="server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181" --network swarm_kafka zookeeper:latest
docker run -d --restart always --hostname k2 --name k2 -p 9094:9094 -p 9194:9194 -e KAFKA_BROKER_ID=2 -e KAFKA_LISTENERS="INSIDE://:9094,OUTSIDE://:9194" -e KAFKA_ADVERTISED_LISTENERS="INSIDE://<填虚拟机ip>:9094,OUTSIDE://<填虚拟机ip>:9194" -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" -e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE -e KAFKA_ZOOKEEPER_CONNECT="zk1:2181,zk2:2181,zk3:2181" -e ALLOW_PLAINTEXT_LISTENER='yes' -e JMX_PORT=9999 -v "/root/kafka2/wurstmeister/kafka:/wurstmeister/kafka" -v "/root/kafka2/kafka:/kafka" --network swarm_kafka --link zk1 --link zk2 --link zk3 docker.io/wurstmeister/kafka
docker run -d --restart always --hostname zk3--name zk3 -p 2185:2181 -v "/root/zookeeper3/data:/data" -v "/root/zookeeper3/datalog:/datalog" -v "/root/zookeeper3/logs:/logs" -e ZOO_MY_ID=3 -e ZOO_SERVERS="server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181" --network swarm_kafka zookeeper:latest
docker run -d --restart always --hostname k3 --name k3 -p 9095:9095 -p 9195:9195 -e KAFKA_BROKER_ID=3 -e KAFKA_LISTENERS="INSIDE://:9095,OUTSIDE://:9195" -e KAFKA_ADVERTISED_LISTENERS="INSIDE://<填虚拟机ip>:9095,OUTSIDE://<填虚拟机ip>:9195" -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" -e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE -e KAFKA_ZOOKEEPER_CONNECT="zk1:2181,zk2:2181,zk3:2181" -e ALLOW_PLAINTEXT_LISTENER='yes' -e JMX_PORT=9999 -v "/root/kafka3/wurstmeister/kafka:/wurstmeister/kafka" -v "/root/kafka3/kafka:/kafka" --network swarm_kafka --link zk1 --link zk2 --link zk3 docker.io/wurstmeister/kafka
docker run -d --restart always --hostname kafka-manager --name kafka-manager -p 8094:9000 -e ZK_HOSTS="zk1:2181,zk2:2181,zk3:2181" -e KAFKA_BROKERS="k1:9093,k2:9094,k3:9095" -e APPLICATION_SECRET=letmein -e KM_ARGS="-Djava.net.preferIPv4Stack=true" --network swarm_kafka --link zk1 --link zk2 --link zk3 --link k1 --link k2 --link k3 \scjtqs/kafka-manager:latest
打开kafka-manager的Windows管理界面地址:<虚拟机ip>:8094
最后点击save保存,成功配置cluster图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。