一直都在看kafka,今天想玩玩,所以查了一下资料动手整一下,开始上车。
第一步,安装docker
curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun
然后运行命令查看
docker info
第二步,修改Docker目录
docker安装完成后,默认目录/var/lib/docker
我在数据盘创建了docker目录
mkdir -p /web/docker
vim /usr/lib/systemd/system/docker.service
查找ExecStart=/usr/bin/dockerd -H fd://,将其改为
ExecStart=/usr/bin/dockerd --graph /web/docker -H fd://
然后重启 systemctl restart docker
docker info看到路径改变了。
Docker Root Dir: /web/docker
第三步,安装docker-compose
yes | cp docker-compose-Linux-$(uname -m) /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
第四步,安装kafka
创建
.env
docker-compose.yml
version: '3'
services:
zookeeper:
image: bitnami/zookeeper:3.6.3
container_name: zookeeper
environment:
ALLOW_ANONYMOUS_LOGIN: "yes"
networks:
- elk-network
kafka-node1:
image: wurstmeister/kafka:2.12-2.4.0
volumes:
- /var/run/docker.sock:/var/run/docker.sock
container_name: kafka-node1
ports:
- 9092:9092
- 19999:19999
environment:
TZ: Asia/Shanghai
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_MESSAGE_MAX_BYTES: 2000000
KAFKA_DELETE_TOPIC_ENABLE: "true"
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
JMX_PORT: 19999
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_HOST_NAME: ${HOST}
networks:
- elk-network
kafka-manager:
image: hlebalbau/kafka-manager:3.0.0.5
container_name: kafka-manager
depends_on:
- zookeeper
ports:
- 9000:9000
environment:
ZK_HOSTS: "zookeeper:2181"
APPLICATION_SECRET: "random-secret"
networks:
- elk-network
networks:
elk-network:
driver: bridge
在当前目录下运行命令: docker-compose up -d
安装完成后用命令查看docker images
显示有zookeeper ,kafka-manager,kafka即代表安装成功。
PS:如何删除docker images,首先要将容器停止: docker stop $(docker ps -a -q)
删除container docker rm 容器ID
删除image docker rmi <image ID >
查询占用该端口的进程
netstat -tln | grep 9000
杀死该进程
kill -9 pid
重新启动容器即可
dockers restart container_id