MySQL、Kafka(含zookeeper)、Redis的docker-composer文件
以下docker-composer文件仅用于开发环境,快速搭建原型使用,生产环境,请进行针对性设置。
MySQL
version: '3.1'
services:
db:
image: mysql:8.0.28
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: app
MYSQL_USER: db_user
MYSQL_PASSWORD: 更新为自己的密码
MYSQL_ROOT_PASSWORD: 更新为自己的密码
ports:
- "16033:3306"
volumes:
- ./data/db:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 18080:8080
Kafka
需要注意,Kafka部署依赖于zookeeper(当前配置文件中,在单机部署三节点zookeeper)。
version: '3.1'
services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
volumes:
- /home/ubuntu/docker/zookeeper/data/zoo1:/data
- /home/ubuntu/docker/zookeeper/datalog/zoo1:/datalog
- /home/ubuntu/docker/zookeeper/logs/zoo1:/logs
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper
restart: always
hostname: zoo2
ports:
- 2182:2181
volumes:
- /home/ubuntu/docker/zookeeper/data/zoo2:/data
- /home/ubuntu/docker/zookeeper/datalog/zoo2:/datalog
- /home/ubuntu/docker/zookeeper/logs/zoo2:/logs
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper
restart: always
hostname: zoo3
ports:
- 2183:2181
volumes:
- /home/ubuntu/docker/zookeeper/data/zoo3:/data
- /home/ubuntu/docker/zookeeper/datalog/zoo3:/datalog
- /home/ubuntu/docker/zookeeper/logs/zoo3:/logs
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
kafka:
image: wurstmeister/kafka
ports:
- "9092"
environment:
DOCKER_API_VERSION: 1.22
KAFKA_ADVERTISED_HOST_NAME: 10.0.4.12
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2182,zoo3:2183
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
depends_on:
- zoo1
- zoo2
- zoo3
Redis
version: '3.1'
services:
redis:
image: redis:7.0.4
hostname: redis
container_name: redis
restart: always
networks:
- business
ports:
- '6379:6379'
volumes:
- /data/redis:/data
- /etc/localtime:/etc/localtime
command: redis-server --save 20 1 --loglevel warning --requirepass 更新为自己的密码
filebeat:
image: docker.elastic.co/beats/filebeat:8.4.0
hostname: filebeat
container_name: filebeat
restart: always
entrypoint: "filebeat -e -strict.perms=false"
volumes:
- /usr/local/openresty/nginx/logs/:/var/log/nginx
- /home/ubuntu/docker/redis-filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
- /etc/localtime:/etc/localtime
depends_on:
- redis
networks:
- business
networks:
business:
driver: bridge
需要注意,这里添加了filebeat,作用是filebeat读取nginx的日志,直接将nginx日志存储至redis中。
filebeat配置文件内容如下所示:
filebeat.inputs:
- type: log
enabled: true
max_bytes: 20480
paths:
- /var/log/nginx/access.log
fields:
source: nginx-access
- type: log
enabled: true
paths:
- /var/log/nginx/error.log
fields:
source: nginx-error
output.redis:
hosts: ["redis:6379"]
db: 0
password: "CkeyrvwY2yyQ5tkkq4VIaU9eBFqBzSEd"
key: "nginx_log"