激情畅聊!十分钟搭建一个插件化易拓展的开源即时聊天(IM)应用——Tailchat

创建一下安装的目录:

sudo -i

mkdir -p /root/data/docker_data/tailchat

cd /root/data/docker_data/tailchat

新建文件:

vim docker-compose.yml

复制以下内容:

version: "3.3"

services:
  # 应用网关
  service-gateway:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: core/gateway
      PORT: 3000
    depends_on:
      - mongo
      - redis
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
      - "traefik.http.services.api-gw.loadbalancer.server.port=3000"
    networks:
      - internal

  # 用户服务
  service-user:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: core/user/*
    depends_on:
      - mongo
      - redis
    networks:
      - internal

  # 群组服务
  service-group:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: core/group/*
    depends_on:
      - mongo
      - redis
    networks:
      - internal

  # 聊天服务
  service-chat:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: core/chat/*
    depends_on:
      - mongo
      - redis
    networks:
      - internal

  # 文件服务 / 插件注册中心 / 配置服务
  service-file:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: core/file,core/plugin/registry,core/config
    depends_on:
      - mongo
      - redis
      - minio
    networks:
      - internal

  service-openapi:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICES: openapi/app,openapi/oidc/oidc
      OPENAPI_PORT: 3003
      OPENAPI_UNDER_PROXY: "true"
    depends_on:
      - mongo
      - redis
      - minio
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.openapi-oidc.rule=PathPrefix(`/open`)"
      - "traefik.http.services.openapi-oidc.loadbalancer.server.port=3003"
    networks:
      - internal

  # 插件服务(所有插件)
  service-all-plugins:
    build:
      context: .
    image: tailchat
    restart: unless-stopped
    env_file: docker-compose.env
    environment:
      SERVICEDIR: plugins
    depends_on:
      - mongo
      - redis
      - minio
    networks:
      - internal

  # 数据库
  mongo:
    image: mongo:4
    restart: on-failure
    volumes:
      - ./data:/data/db
    networks:
      - internal

  # 数据缓存与中转通讯
  redis:
    image: redis:alpine
    restart: on-failure
    networks:
      - internal

  # 存储服务
  minio:
    image: minio/minio
    restart: on-failure
    networks:
      - internal
    environment:
      MINIO_ROOT_USER: tailchat
      MINIO_ROOT_PASSWORD: com.msgbyte.tailchat
    volumes:
      - ./storage:/data
    command: minio server /data --console-address ":9001"

  # 路由转发
  traefik:
    image: traefik:v2.1
    restart: unless-stopped
    command:
      - "--api.insecure=true" # Don't do that in production!
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
      - "--entryPoints.web.forwardedHeaders.insecure" # Not good
    ports:
      - 11000:80            # 11000可以改成自己服务器上没有被占用的端口
      - 127.0.0.1:11001:8080    
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - internal
      - default

networks:
  internal:
    name: tailchat-internal

新建文件:

vim docker-compose.env

复制如下内容:

LOGGER=true
LOGLEVEL=info
SERVICEDIR=services

TRANSPORTER=redis://redis:6379

CACHER=redis://redis:6379

REDIS_URL=redis://redis:6379
MONGO_URL=mongodb://mongo/tailchat
SECRET=adswddWEQ@4  # 改成自己的密钥

# file
API_URL=https://chat.886699.xyz   # 改成自己的网站

# minio
MINIO_URL=minio:9000
MINIO_USER=tailchat
MINIO_PASS=com.msgbyte.tailchat

# SMTP
SMTP_SENDER=
SMTP_URI=

# metrics
PROMETHEUS=1

然后执行:

docker pull moonrailgun/tailchat
docker tag moonrailgun/tailchat tailchat # 修改tag以让配置文件能够识别
docker-compose up -d   # 执行以下命令一键启动
访问: http://<server ip>:11000 即可打开tailchat

注意部分云服务可能需要手动开放防火墙端口。

在docker-compose.env文件中提供了部分环境变量可供配置。

tailchat 的docker-compose.yml配置默认提供了如下配置:

mongodb: 持久化数据库
redis: KV数据库与消息中转服务
minio: 分布式文件服务

By 行政