导读:向量数据库作为AI时代的核心基础设施,Milvus凭借其强大的性能和灵活的架构设计在市场中占据重要地位。然而,许多开发者在部署Milvus时面临架构选择困惑和配置复杂性挑战,导致项目进展受阻。
本文将为您提供一套完整的Milvus部署解决方案,从架构选择策略到Docker实战部署的全流程技术指导。文章深入解析了Milvus Lite、Standalone和Distributed三种部署架构的适用场景,帮助您根据项目规模和数据量级做出最优选择。特别值得关注的是,我们将重点介绍Milvus Standalone部署方案,它能够在单机环境下支持高达1亿向量规模的数据处理能力。
通过阅读本文,您将掌握生产级Milvus服务的完整部署流程,包括网络安全配置、自动化部署脚本使用和Web管理界面操作。文章还提供了经过验证的Shell脚本,实现一键式服务管理功能。无论您是初次接触Milvus的开发者,还是需要优化现有部署方案的架构师,这份实战指南都将为您的向量数据库项目提供有力的技术支撑。
概述
本文将深入探讨Milvus向量数据库的部署架构选择策略以及基于Docker的实际部署操作,为不同规模的项目提供完整的技术解决方案。
部署架构选择策略
架构选择原则
选择合适的Milvus部署架构主要取决于项目的发展阶段和数据规模需求。Milvus为从快速原型开发到大规模企业级部署的各种应用场景提供了灵活且强大的解决方案。
三种主要部署架构
Milvus Lite
- 适用场景:适合小规模数据集处理,支持数百万级向量数据
- 系统要求:不支持Windows操作系统
- 推荐用途:快速原型验证、小型测试项目
Milvus Standalone
- 适用场景:中等规模数据集处理,可扩展至1亿向量规模
- 部署特点:单机服务器部署,所有组件集成在统一Docker镜像中
- 优势:部署简便,适合中小型生产环境
Milvus Distributed
- 适用场景:大规模企业级部署,处理从1亿到数百亿级向量数据集
- 架构特点:分布式设计,支持水平扩展
- 推荐用途:大型企业生产环境,高并发查询场景
Milvus分层架构详解
Milvus采用分层架构设计,在Docker部署中包含以下核心组件:
核心组件功能
| Coordinator | → 管理元数据、负载均衡 |
| Query Node | → 处理查询与数据存储 |
| Data Node | → 处理查询与数据存储 |
| Object Storage (S3) | → 持久化存储(可选MinIO、AWS S3) |
Coordinator层:负责管理系统元数据和实现负载均衡策略
Query Node:专门处理向量查询请求与数据存储管理
Data Node:负责处理数据查询操作与存储管理
Object Storage:提供持久化存储服务,支持S3兼容存储(可选择MinIO或AWS S3)
架构优势
Milvus Standalone将所有组件打包到单个Docker镜像中,大大简化了部署复杂度,特别适合快速部署和测试环境搭建。
云服务解决方案
对于预算充足的企业用户,建议直接采购云厂商提供的托管服务,例如阿里云的Milvus服务(详细信息请参考:https://help.aliyun.com/zh/milvus)。
Linux服务器Docker部署实战
网络配置要求
在阿里云等云平台部署时,需要在网络安全组中开放以下关键端口:
- 2379:etcd服务端口
- 9091:Web UI访问端口
- 19530:Milvus服务主端口
安全提醒:默认配置未启用权限校验机制。生产环境部署时,建议配置内网访问并结合IP白名单策略以确保安全性。
自动化部署脚本
以下是完整的Milvus Standalone自动化部署脚本:
#!/usr/bin/env bash
# Licensed to the LF AI & Data foundation under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
run_embed() {
cat << EOF > embedEtcd.yaml
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://0.0.0.0:2379
quota-backend-bytes: 4294967296
auto-compaction-mode: revision
auto-compaction-retention: '1000'
EOF
cat << EOF > user.yaml
# Extra config to override default milvus.yaml
EOF
if [ ! -f "./embedEtcd.yaml" ]
then
echo "embedEtcd.yaml file does not exist. Please try to create it in the current directory."
exit 1
fi
if [ ! -f "./user.yaml" ]
then
echo "user.yaml file does not exist. Please try to create it in the current directory."
exit 1
fi
sudo docker run -d \
--name milvus-standalone \
--security-opt seccomp:unconfined \
-e ETCD_USE_EMBED=true \
-e ETCD_DATA_DIR=/var/lib/milvus/etcd \
-e ETCD_CONFIG_PATH=/milvus/configs/embedEtcd.yaml \
-e COMMON_STORAGETYPE=local \
-v $(pwd)/volumes/milvus:/var/lib/milvus \
-v $(pwd)/embedEtcd.yaml:/milvus/configs/embedEtcd.yaml \
-v $(pwd)/user.yaml:/milvus/configs/user.yaml \
-p 19530:19530 \
-p 9091:9091 \
-p 2379:2379 \
--health-cmd="curl -f http://localhost:9091/healthz" \
--health-interval=30s \
--health-start-period=90s \
--health-timeout=20s \
--health-retries=3 \
milvusdb/milvus:v2.5.6 \
milvus run standalone 1> /dev/null
}
wait_for_milvus_running() {
echo "Wait for Milvus Starting..."
while true
do
res=`sudo docker ps|grep milvus-standalone|grep healthy|wc -l`
if [ $res -eq 1 ]
then
echo "Start successfully."
echo "To change the default Milvus configuration, add your settings to the user.yaml file and then restart the service."
break
fi
sleep 1
done
}
start() {
res=`sudo docker ps|grep milvus-standalone|grep healthy|wc -l`
if [ $res -eq 1 ]
then
echo "Milvus is running."
exit 0
fi
res=`sudo docker ps -a|grep milvus-standalone|wc -l`
if [ $res -eq 1 ]
then
sudo docker start milvus-standalone 1> /dev/null
else
run_embed
fi
if [ $? -ne 0 ]
then
echo "Start failed."
exit 1
fi
wait_for_milvus_running
}
stop() {
sudo docker stop milvus-standalone 1> /dev/null
if [ $? -ne 0 ]
then
echo "Stop failed."
exit 1
fi
echo "Stop successfully."
}
delete_container() {
res=`sudo docker ps|grep milvus-standalone|wc -l`
if [ $res -eq 1 ]
then
echo "Please stop Milvus service before delete."
exit 1
fi
sudo docker rm milvus-standalone 1> /dev/null
if [ $? -ne 0 ]
then
echo "Delete milvus container failed."
exit 1
fi
echo "Delete milvus container successfully."
}
delete() {
delete_container
sudo rm -rf $(pwd)/volumes
sudo rm -rf $(pwd)/embedEtcd.yaml
sudo rm -rf $(pwd)/user.yaml
echo "Delete successfully."
}
upgrade() {
read -p "Please confirm if you'd like to proceed with the upgrade. The default will be to the latest version. Confirm with 'y' for yes or 'n' for no. > " check
if [ "$check" == "y" ] ||[ "$check" == "Y" ];then
res=`sudo docker ps -a|grep milvus-standalone|wc -l`
if [ $res -eq 1 ]
then
stop
delete_container
fi
curl -sfL https://raw.githubusercontent.com/milvus-io/milvus/master/scripts/standalone_embed.sh -o standalone_embed_latest.sh && \
bash standalone_embed_latest.sh start 1> /dev/null && \
echo "Upgrade successfully."
else
echo "Exit upgrade"
exit 0
fi
}
case $1 in
restart)
stop
start
;;
start)
start
;;
stop)
stop
;;
upgrade)
upgrade
;;
delete)
delete
;;
*)
echo "please use bash standalone_embed.sh restart|start|stop|upgrade|delete"
;;
esac
部署操作指令
完成脚本文件准备后,可使用以下命令进行服务管理:
# 启动Milvus服务
bash standalone_embed.sh start
# 停止Milvus服务
bash standalone_embed.sh stop
# 删除Milvus服务及相关数据
bash standalone_embed.sh delete
# 升级Milvus至最新版本
bash standalone_embed.sh upgrade
# 重启Milvus服务
bash standalone_embed.sh restart
部署完成后的系统状态
服务组件状态
成功执行安装脚本后,系统将建立以下服务状态:
- Milvus主服务容器在19530端口启动并运行
- 嵌入式etcd服务集成在同一容器中,监听2379端口
- Milvus数据卷自动映射到当前目录的volumes/milvus文件夹
Web管理界面访问
可通过浏览器访问Milvus内置的Web管理界面:
http://${MILVUS_PROXY_IP}:9091/webui
例如:http://192.168.11.161:9091/webui/
Web UI功能说明
重要提醒:Milvus Web UI与Attu等第三方可视化管理工具存在功能差异。Web UI是系统内置的轻量级管理工具,主要提供以下基础功能:
- 运行环境状态监控
- 数据库和Collections基本信息查看
- 系统任务执行状态跟踪
- 慢查询请求分析
功能限制:该Web UI不支持数据库的创建、删除等管理操作,也不提供复杂的数据操作任务功能。
参考资源
更多详细的技术文档和配置说明,请参考Milvus官方文档:
https://milvus.io/docs/zh/milvus-webui.md
总结
本文提供了从架构选择到实际部署的完整Milvus解决方案。通过合理选择部署架构并遵循标准化的部署流程,可以快速搭建稳定可靠的向量数据库服务环境。在生产环境中,建议结合具体的业务需求和安全要求,对配置参数进行适当的优化调整。