Docker-compose 一键安装所有中间件

说明

在研发环境中,我们要安装各种中间件来支持我们的程序运行,但是一个一个的安装配置起来非常的麻烦和浪费时间,所以我们使用编排工具做到一键命令安装好所有我们所需的中间件,简单省事。

本次安装包括

  • mysql
  • redis
  • nginx
  • mycat
  • rabbitmq
  • zookeeper
  • fdfs

其他的可以更改yml文件增加。

开始

使用一键安装之前先确保是否安装Docker
https://blog.csdn.net/lulongji2035/article/details/107983973

确定是否安装Docker-compose
https://blog.csdn.net/lulongji2035/article/details/107984037

确保docker和docker-compose安装好之后到gitee上动动你的小手点击star 和fork。
Docker-compose 一键安装所有中间件_第1张图片

下载 https://gitee.com/Bruce-Tools/tools-docker.git 到服务上 并在第四个docker中间件配置目录下执行docker-compose命令安装相关中间件。
Docker-compose 一键安装所有中间件_第2张图片

命令如下:

docker-compose up -d 

如果只是安装一个中间件,则注释掉其他的或者执行如下命令:

#示例只安装nginx
docker-compose up -d nginx

安装完成后
Docker-compose 一键安装所有中间件_第3张图片

使用

redis

host:当前服务器ip
密码:123456
端口:6379

mysql

host:当前服务器ip
账号:root
密码:root
端口:3306

rabbitmq

host:当前服务器ip
账号:guest
密码:guest
端口:默认

其他的请根据docker-compose自行适配

docker-compose.yml

version: '3'

services:
###################nginx###########################
nginx:
  restart: always
  image: nginx
  container_name: nginx
  ports:
    - 80:80
    - 443:443
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/hosts:/etc/hosts:ro
    - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/conf.d:/etc/nginx/conf.d
    - ./nginx/logs:/var/log/nginx
    - ./nginx/html:/usr/share/nginx/html
    - ./nginx/etc/letsencrypt:/etc/letsencrypt
    - ./nginx/conf:/etc/nginx
  network_mode: "host"
###################redis###########################
redis:
  image: redis
  container_name: redis
  ports:
    - 6379:6379
  restart: always
  command: redis-server --requirepass 123456 --dir /data
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/hosts:/etc/hosts:ro
    - ./redis/data:/data
    - ./redis/conf/redis.conf:/etc/redis/redis.conf
  network_mode: "host"

###################mysql###########################
mysql:
  restart: always
  image: mysql:5.7
  container_name: mysql
  privileged: true
  command: --default-authentication-plugin=mysql_native_password #这行代码解决无法访问的问题
  ports:
    - 3306:3306
  environment:
    MYSQL_ROOT_PASSWORD: root
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/hosts:/etc/hosts:ro
    - ./mysql/data:/var/lib/mysql
    - ./mysql/conf/my.cnf:/etc/mysql/my.cnf
  network_mode: "host"


  ###################mycat###########################
  mycat:
    restart: always
    image: longhronshens/mycat-docker
    build: ./mycat
    container_name: mycat
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/hosts:/etc/hosts
      - ./mycat/conf:/usr/local/mycat/conf
    ports:
      - 8066:8066 # 暴露mycat服务端口
      - 9066:9066 # 暴露mycat管理端口
    network_mode: "host"

###################rabbitmq###########################
rabbitmq:
  restart: always
  image: rabbitmq:management
  container_name: rabbitmq
  privileged: true
  ports:
    - 4369:4369
    - 5671:5671
    - 5672:5672
    - 15672:15672
    - 25672:25672
  environment:
    RABBITMQ_DEFAULT_VHOST: /
    RABBITMQ_DEFAULT_USER: guest
    RABBITMQ_DEFAULT_PASS: guest
    RABBITMQ_LOGS: /var/lib/rabbitmq/rabbitmq.log
    RABBITMQ_SASL_LOGS: /var/lib/rabbitmq/rabbitmq-sasl.log
    RABBITMQ_ERLANG_COOKIE: LZJADKXKLULIXFKAALGX
  logging:
    driver: "json-file"
    options:
      max-size: "200k"
      max-file: "10"
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/hosts:/etc/hosts:ro
    - ./rabbitmq:/var/lib/rabbitmq
  network_mode: "host"

###################fdfs###########################
tracker:
  restart: always
  image: morunchang/fastdfs
  container_name: tracker
  hostname: tracker
  entrypoint: sh ./tracker.sh
  ports:
    - "22122:22122"
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/hosts:/etc/hosts:ro
    - /app/im_attach/fdfs:/data/fast_data
  network_mode: "host"

storage:
  restart: always
  image: morunchang/fastdfs
  container_name: storage
  hostname: storage
  entrypoint: sh ./storage.sh
  ports:
    - 9999:9999
    - 23000:23000
  volumes:
    - /app/im_attach/fdfs:/data/fast_data
    - ./fastdfs/nginx.conf:/etc/nginx/conf/nginx.conf
  environment:
    - "TRACKER_IP=192.168.183.133:22122"
    - "GROUP_NAME=group1"
  network_mode: "host"

 ###################influxdb###########################
influxdb:
  image: influxdb:latest
  container_name: tig-influxdb
  ports:
    - "8083:8083"
    - "8086:8086"
    - "8090:8090"
  env_file:
    - 'env.influxdb'
  volumes:
    - ./influxdb/data:/var/lib/influxdb
    - ./etc/timezone:/etc/timezone:ro
    - /etc/hosts:/etc/hosts:ro
    - ./etc/localtime:/etc/localtime:ro
  restart: unless-stopped
  network_mode: "host"


  ###################grafana###########################
grafana:
  image: grafana/grafana
  container_name: grafana
  environment:
    - GF_AUTH_ANONYMOUS_ENABLED=true #公开仪表板
  ports:
    - 3000:3000
  volumes:
    - ./grafana/data:/var/lib/grafana
    - ./etc/timezone:/etc/timezone:ro
    - /etc/hosts:/etc/hosts:ro
    - ./etc/localtime:/etc/localtime:ro
  restart: unless-stopped
  network_mode: "host"

感谢

本文只做学习参考,如有任何不准确的地方欢迎指正。

你可能感兴趣的:(Docker,centos,centos,docker,docker-compose)