使用 docker-compose 安装 es、kibana、mysql、redis、kafka
由于经常的安装虚拟机,每次都要重装环境比较麻烦。
这次写了一个 docker-compose
文件,一次性搞定安装问题。
一键安装
git clone https://gitee.com/rush_peng/docker-compose_db.git
在项目的根目录下,执行 docker-compose up -d
docker-compose
目录结果如下:
---
version: "3.1"
networks:
zh-net:
driver: bridge
services:
db:
image: mysql:latest
container_name: zh_mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
- TZ=Asia/Shanghai
volumes:
- /home/peng/docker/data/mysql:/var/lib/mysql
- ./mysql/init/:/docker-entrypoint-initdb.d/
ports:
- 3306:3306
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
redis:
image: redis:latest
container_name: zh_redis
ports:
- 6379:6379
etcd:
image: bitnami/etcd:latest
container_name: zh_etcd
environment:
- ALLOW_NONE_AUTHENTICATION=yes
ports:
- 2379:2379
es:
image: elasticsearch:7.17.5
container_name: zh_es
environment:
- discovery.type=single-node
volumes:
- /home/peng/docker/conf/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /home/peng/docker/conf/elasticsearch/plugins:/usr/share/elasticsearch/plugins
ports:
- 9200:9200
networks:
- zh-net
kibana:
image: kibana:7.17.5
container_name: zh_kibana
volumes:
- /home/peng/docker/conf/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- 5601:5601
networks:
- zh-net
depends_on:
- es
zookeeper:
image: confluentinc/cp-zookeeper:7.0.1
container_name: zh_zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-kafka:7.0.1
container_name: zh_broker
ports:
# To learn about configuring Kafka for access across networks see
# https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/
- "9092:9092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
kafka-map:
image: dushixiang/kafka-map:latest
container_name: zh_kafka-map
volumes:
- /home/peng/docker/data/kafka-map:/usr/local/kafka-map/data
environment:
- DEFAULT_USERNAME=admin
- DEFAULT_PASSWORD=admin
networks:
- zh-net
ports:
- 8089:8080
depends_on:
- broker
非持久化安装
---
version: "3.1"
networks:
net-zh:
driver: bridge
services:
db:
image: mysql:latest
container_name: mysql_zh
environment:
- MYSQL_ROOT_PASSWORD=123456
- TZ=Asia/Shanghai
networks:
- net-zh
ports:
- 3306:3306
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
redis:
image: redis:latest
container_name: redis_zh
networks:
- net-zh
ports:
- 6379:6379
etcd:
image: bitnami/etcd:latest
container_name: etcd_zh
environment:
- ALLOW_NONE_AUTHENTICATION=yes
networks:
- net-zh
ports:
- 2379:2379
es:
image: elasticsearch:7.17.5
container_name: es_zh
environment:
- discovery.type=single-node
networks:
- net-zh
ports:
- 9200:9200
kibana:
image: kibana:7.17.5
container_name: kibana_zh
networks:
- net-zh
ports:
- 5601:5601
depends_on:
- es
zookeeper:
image: confluentinc/cp-zookeeper:7.0.1
container_name: zookeeper_zh
networks:
- net-zh
ports:
- 2181:2181
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-kafka:7.0.1
container_name: zh_broker
networks:
- net-zh
ports:
- 9092:9092
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
kafka-map:
image: dushixiang/kafka-map:latest
container_name: kafka-map_zh
environment:
- DEFAULT_USERNAME=admin
- DEFAULT_PASSWORD=admin
networks:
- net-zh
ports:
- 8089:8080
depends_on:
- broker
创建 mysql 容器时,自动初始化数据库
docker run -it --rm --name mysql-zdp -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v ./initsql:/docker-entrypoint-initdb.d/ -d mysql:5.7.44
其中 initsql
是个文件夹,里面可包含多个 .sql
结尾的sql文件,将其映射到 mysql 容器的 /docker-entrypoint-initdb.d/
目录下即可