零.前期准备:
1.登录centos7x服务器,安装必要工具如;yum
2.在线安装docker命令如下:
1)删除原来的docker:
yum -y remove docker
2)安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils
3)设置yum源远程下载docker:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4)生成缓存
yum makecache fast
5)查看可用版本有哪些
yum -y install docker-ce
6)可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce.x86_64 --showduplicates | sort -r
7)启动docker:
systemctl start docker
8)在docker运行一个镜像:
docker run hello-world
9)查看docker版本:
docker version
10)查看启动的容器:
docker ps -a
11)查看镜像
docker images
一.镜像拉取
docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
二.定义docker-compose.yml
将kafka-manager也一起配置好
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
restart: always
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
restart: always
hostname: kafka
container_name: kafka
depends_on: [ zookeeper ]
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.1.100
KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /data/product/zj_bigdata/data/kafka/docker.sock:/var/run/docker.sock
kafka-manager:
image: sheepkiller/kafka-manager
restart: always
hostname: kafka-manager
container_name: kafka-manager
environment:
ZK_HOSTS: 192.168.133.128:2181
ports:
- "9000:9000"
在docker-compose.yml文件目录进行服务打包
[root@localhost bin]#docker-compose build
zookeeper uses an image, skipping
三.启动服务
[root@localhost bin]# docker-compose up -d
启动完成后查启动的容器:
[root@localhost bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
86ad42597817 wurstmeister/kafka "start-kafka.sh" 2 hours ago Up 2 hours 0.0.0.0:9092->9092/tcp, :::9092->9092/tcp kafka
ae5a57781bdb wurstmeister/zookeeper "/bin/sh -c '/usr/sb…" 2 hours ago Up 2 hours 22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp zookeeper
d2d7cd5a9e64 sheepkiller/kafka-manager "./start-kafka-manag…" 2 hours ago Up 2 hours 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp kafka-manager
四.启动测试
记住启动的启动名称,kafka为 kafka,zookeeper 为 zookeeper.
如果docker-compose正常启动,此时docker ps会看到以上两个容器。进入kafka容器
docker exec -it kafka bash
创建一个topic
$KAFKA_HOME/bin/kafka-topics.sh --create --topic topic --partitions 4 --zookeeper zookeeper:2181 --replication-factor 1
***注意–zookeeper后面的参数为,容器的name
查看刚刚创建的topic
$KAFKA_HOME/bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic test
发布信息
$KAFKA_HOME/bin/kafka-console-producer.sh --topic=test --broker-list kafka:9092
接收消息
$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --from-beginning --topic test
五.kafka集群管理界面
http://192.168.1.100:9000/