Fish Speech 1.5生产环境:Docker Compose编排双服务,日志集中采集方案
·
Fish Speech 1.5生产环境:Docker Compose编排双服务,日志集中采集方案
1. 项目背景与需求
Fish Speech 1.5作为新一代文本转语音模型,在实际生产环境中需要稳定可靠的服务架构。传统的单服务部署方式存在日志分散、故障排查困难、服务依赖管理复杂等问题。本文将介绍如何使用Docker Compose编排Fish Speech的双服务架构,并实现日志集中采集的完整方案。
在实际生产环境中,我们需要解决以下核心问题:
- 前端WebUI(端口7860)和后端API服务(端口7861)的协同管理
- 服务依赖关系的自动化管理
- 双服务日志的集中采集和实时监控
- 快速故障定位和性能分析能力
2. Docker Compose编排方案
2.1 服务架构设计
Fish Speech 1.5采用双服务架构,需要精心设计容器编排方案:
version: '3.8'
services:
fish-speech-backend:
image: fish-speech-backend:1.5
build: ./backend
ports:
- "7861:7861"
volumes:
- ./checkpoints:/app/checkpoints
- ./logs:/app/logs
environment:
- CUDA_VISIBLE_DEVICES=0
- PYTHONPATH=/app
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
fish-speech-frontend:
image: fish-speech-frontend:1.5
build: ./frontend
ports:
- "7860:7860"
depends_on:
- fish-speech-backend
environment:
- BACKEND_URL=http://fish-speech-backend:7861
- GRADIO_CDN=false
2.2 容器网络配置
为确保服务间通信安全可靠,我们配置独立的Docker网络:
networks:
fish-speech-net:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
services:
fish-speech-backend:
networks:
- fish-speech-net
ports:
- "7861:7861"
fish-speech-frontend:
networks:
- fish-speech-net
ports:
- "7860:7860"
2.3 健康检查配置
添加健康检查确保服务稳定性:
services:
fish-speech-backend:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7861/docs"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
fish-speech-frontend:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7860"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
3. 日志集中采集方案
3.1 日志输出标准化
首先统一双服务的日志格式:
# 后端服务日志配置
import logging
import json
from datetime import datetime
def setup_logging():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('/app/logs/backend.log'),
logging.StreamHandler()
]
)
# 前端服务日志配置
def setup_frontend_logging():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - FRONTEND - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('/app/logs/frontend.log'),
logging.StreamHandler()
]
)
3.2 Docker日志驱动配置
使用json-file日志驱动并配置日志轮转:
services:
fish-speech-backend:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
tag: "fish-speech-backend"
fish-speech-frontend:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
tag: "fish-speech-frontend"
3.3 使用Fluentd实现日志收集
部署Fluentd作为日志收集器:
services:
fluentd:
image: fluent/fluentd:v1.16-1
volumes:
- ./fluentd.conf:/fluentd/etc/fluent.conf
- ./logs:/fluentd/log
ports:
- "24224:24224"
- "24224:24224/udp"
networks:
- fish-speech-net
fish-speech-backend:
logging:
driver: "fluentd"
options:
tag: "fish-speech.backend"
fluentd-address: "fluentd:24224"
fish-speech-frontend:
logging:
driver: "fluentd"
options:
tag: "fish-speech.frontend"
fluentd-address: "fluentd:24224"
3.4 Fluentd配置示例
创建Fluentd配置文件收集和转发日志:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<filter fish-speech.**>
@type parser
key_name log
format json
reserve_data true
</filter>
<match fish-speech.**>
@type copy
<store>
@type file
path /fluentd/log/fish-speech
compress gzip
<buffer>
timekey 1h
timekey_wait 10m
timekey_use_utc true
</buffer>
</store>
<store>
@type elasticsearch
host elasticsearch
port 9200
index_name fish-speech-%Y%m%d
<buffer>
timekey 1h
timekey_wait 10m
timekey_use_utc true
</buffer>
</store>
</match>
4. 完整生产环境部署
4.1 目录结构规划
fish-speech-production/
├── docker-compose.yml
├── backend/
│ ├── Dockerfile
│ └── app/
├── frontend/
│ ├── Dockerfile
│ └── app/
├── fluentd/
│ ├── Dockerfile
│ └── fluent.conf
├── elasticsearch/
│ └── config/
├── kibana/
│ └── config/
└── logs/
├── backend/
├── frontend/
└── fluentd/
4.2 完整docker-compose配置
version: '3.8'
services:
# Elasticsearch用于日志存储和检索
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
environment:
- discovery.type=single-node
- xpack.security.enabled=false
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
ports:
- "9200:9200"
networks:
- fish-speech-net
# Kibana用于日志可视化
kibana:
image: docker.elastic.co/kibana/kibana:8.11.0
depends_on:
- elasticsearch
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
ports:
- "5601:5601"
networks:
- fish-speech-net
# Fluentd日志收集器
fluentd:
image: fluent/fluentd:v1.16-1
volumes:
- ./fluentd/fluent.conf:/fluentd/etc/fluent.conf
- ./logs/fluentd:/fluentd/log
ports:
- "24224:24224"
- "24224:24224/udp"
networks:
- fish-speech-net
# Fish Speech后端服务
fish-speech-backend:
build: ./backend
ports:
- "7861:7861"
volumes:
- ./checkpoints:/app/checkpoints
- ./logs/backend:/app/logs
environment:
- CUDA_VISIBLE_DEVICES=0
- PYTHONPATH=/app
logging:
driver: "fluentd"
options:
tag: "fish-speech.backend"
fluentd-address: "fluentd:24224"
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
networks:
- fish-speech-net
# Fish Speech前端服务
fish-speech-frontend:
build: ./frontend
ports:
- "7860:7860"
depends_on:
- fish-speech-backend
environment:
- BACKEND_URL=http://fish-speech-backend:7861
- GRADIO_CDN=false
logging:
driver: "fluentd"
options:
tag: "fish-speech.frontend"
fluentd-address: "fluentd:24224"
networks:
- fish-speech-net
volumes:
elasticsearch_data:
networks:
fish-speech-net:
driver: bridge
4.3 服务启动与管理
使用docker-compose管理整个服务栈:
# 启动所有服务
docker-compose up -d
# 查看服务状态
docker-compose ps
# 查看日志
docker-compose logs -f fish-speech-backend
docker-compose logs -f fish-speech-frontend
# 停止服务
docker-compose down
# 重新构建并启动
docker-compose up -d --build
5. 监控与告警配置
5.1 服务健康监控
配置Prometheus监控服务状态:
# 在docker-compose中添加监控服务
monitoring:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- fish-speech-net
# 配置Prometheus抓取目标
scrape_configs:
- job_name: 'fish-speech'
static_configs:
- targets: ['fish-speech-backend:7861', 'fish-speech-frontend:7860']
5.2 日志告警规则
在Kibana中配置关键日志告警:
{
"alert": {
"name": "Fish Speech服务异常",
"condition": {
"script": {
"source": "ctx.payload.hits.total.value > 0",
"lang": "painless"
}
},
"triggers": [
{
"name": "错误日志触发",
"severity": "warning",
"condition": {
"query": {
"match": {
"level": "ERROR"
}
}
}
}
]
}
}
6. 性能优化建议
6.1 日志性能优化
针对高并发场景优化日志性能:
# 使用异步日志记录
import logging
import asyncio
from logging.handlers import QueueHandler, QueueListener
log_queue = asyncio.Queue()
queue_handler = QueueHandler(log_queue)
listener = QueueListener(log_queue, logging.FileHandler('app.log'))
listener.start()
# 在生产代码中使用异步日志
async def process_tts_request(text):
logger.info("开始处理TTS请求", extra={'text_length': len(text)})
# 处理逻辑
6.2 容器资源限制
合理配置容器资源限制:
services:
fish-speech-backend:
deploy:
resources:
limits:
cpus: '4'
memory: 8G
reservations:
cpus: '2'
memory: 6G
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
7. 总结
通过Docker Compose编排Fish Speech 1.5的双服务架构,我们实现了以下目标:
- 服务管理标准化:使用容器化部署,确保环境一致性和可重复性
- 日志集中采集:通过Fluentd实现双服务日志的统一收集和存储
- 监控可视化:集成Elasticsearch和Kibana提供强大的日志查询和分析能力
- 高可用保障:配置健康检查和资源限制,确保服务稳定性
- 扩展性良好:架构支持水平扩展和组件替换
这种方案特别适合生产环境部署,能够有效降低运维复杂度,提高故障排查效率,为Fish Speech 1.5的稳定运行提供有力保障。
实际部署时,建议根据具体业务需求调整资源配置和监控策略,确保系统既满足性能要求又具备良好的可维护性。
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。
更多推荐


所有评论(0)