为AI而生的向量数据库 - milvus(二) | 单机Standalone安装

科技   2024-11-26 18:01   山西  

-推荐关注-

-正文-
  • 1. Milvus Standalone介绍

  • 2. 下载安装脚本:docker-compose.yml

  • 3. 启动数据库服务

  • 4. 代码测试

  • 5. 停止并删除该容器


Milvus是一款由Zilliz公司开发的开源向量数据库,专为处理大规模向量数据设计。它主要用于存储、索引和管理由深度神经网络和其他机器学习模型生成的嵌入向量,适用于图像、视频、音频和文本等非结构化数据的特征表示。

1.Milvus Standalone介绍

目前,Milvus 有三种部署选项:Milvus LiteMilvus StandaloneMilvus Distributed

Milvus Standalone 是单机服务器部署。Milvus Standalone 的所有组件都打包在一个 Docker 镜像中,使部署变得方便。如果您有生产工作负载但不想使用 Kubernetes,在具有足够内存的单机上运行 Milvus Standalone 是一个好的选择。此外,Milvus Standalone 通过主从复制支持高可用性。

standalone 部署的性能见:为AI而生的向量数据库 - milvus(一) | milvus是什么

使用 Docker 脚本或 Docker Compose 配置安装 Milvus Standalone 时,将自动获取并配置以下依赖项:

SoftwareVersion
etcd3.5.0
MinIORELEASE.2023-03-20T20-16-18Z
Pulsar2.8.2

Docker 是一种工具,用来将应用程序和它的运行环境(比如依赖的库、配置文件等)打包成一个“容器”,这样就可以在任何地方运行它,而不需要担心“这台机器支持吗”之类的问题

当你的项目变复杂时,往往不仅仅需要一个容器。比如一个网站可能需要:

  • 一个容器运行网页的代码(比如 Node.js、Django 等)。
  • 一个容器运行数据库(比如 MySQL)。
  • 另一个容器运行缓存服务(比如 Redis)。

手动管理这些容器会很麻烦:启动顺序、配置、网络通信等等。Docker Compose 就是一个工具,可以用来同时定义和管理多个容器

docker的安装详见:Docker在Windows环境(WSL2)的安装

2.下载安装脚本:docker-compose.yml

浏览器打开脚本地址:https://github.com/milvus-io/milvus/releases


1.新建目录:milvus (作为我们数据库的工作目录)

2.cd milvus

3.命令行下载对应的脚本,保存到新建的目录milvus下(或在浏览器选择具体脚本名点击“另存为”):

wget -O milvus-standalone-docker-compose-gpu.yml https://github.com/milvus-io/milvus/releases/download/v2.4.6/milvus-standalone-docker-compose-gpu.yml

GPU版本:

https://github.com/milvus-io/milvus/releases/download/v2.4.6/milvus-standalone-docker-compose-gpu.yml

CPU版本:

https://github.com/milvus-io/milvus/releases/download/v2.4.6/milvus-standalone-docker-compose.yml

3.启动数据库服务

1.启动docker服务

因为使用的docker环境,因此要一致保证docker是启动状态

windows环境需要打开Docker Desktop,保证左下角是“Engine running”


2.cd milvus

3.docker compose -f milvus-standalone-docker-compose-gpu.yml up -d (milvus-standalone-docker-compose-gpu.yml是刚下载的脚本)

G:\milvus>docker compose -f milvus-standalone-docker-compose-gpu.yml up -d
time="2024-07-22T13:02:45+08:00" level=warning msg="G:\\milvus\\milvus-standalone-docker-compose-gpu.yml: `version` is obsolete"
[+] Running 32/32
 ✔ standalone Pulled                                                                                                                                                     261.1s
   ✔ aece8493d397 Pull complete                                                                                                                                           15.2s
   ✔ 5e3b7ee77381 Pull complete                                                                                                                                           16.8s
   ✔ 5bd037f007fd Pull complete                                                                                                                                           25.6s
   ✔ 4cda774ad2ec Pull complete                                                                                                                                           25.7s
   ✔ 775f22adee62 Pull complete                                                                                                                                           25.7s
   ✔ 263fc748118f Pull complete                                                                                                                                          249.6s
   ✔ 16c36d0187d0 Pull complete                                                                                                                                          249.6s
   ✔ e7a56570655c Pull complete                                                                                                                                          249.7s
   ✔ 507fc9045cba Pull complete                                                                                                                                          249.7s
   ✔ f2cfb0cec18a Pull complete                                                                                                                                          250.3s
   ✔ 79a9015779dc Pull complete                                                                                                                                          251.2s
   ✔ a17859ecad5c Pull complete                                                                                                                                          251.3s
   ✔ 883420d7a148 Pull complete                                                                                                                                          256.0s
   ✔ 535376b75c84 Pull complete                                                                                                                                          256.0s
   ✔ eb2f8229d375 Pull complete                                                                                                                                          256.0s
   ✔ 4f4fb700ef54 Pull complete                                                                                                                                          256.1s
 ✔ etcd Pulled                                                                                                                                                           143.9s
   ✔ dbba69284b27 Pull complete                                                                                                                                           93.8s
   ✔ 270b322b3c62 Pull complete                                                                                                                                          101.1s
   ✔ 7c21e2da1038 Pull complete                                                                                                                                          109.2s
   ✔ cb4f77bfee6c Pull complete                                                                                                                                          118.8s
   ✔ e5485096ca5d Pull complete                                                                                                                                          118.9s
   ✔ 3ea3736f61e1 Pull complete                                                                                                                                          122.7s
   ✔ 1e815a2c4f55 Pull complete                                                                                                                                          122.8s
 ✔ minio Pulled                                                                                                                                                           25.5s
   ✔ c7e856e03741 Pull complete                                                                                                                                            7.6s
   ✔ c1ff217ec952 Pull complete                                                                                                                                            7.6s
   ✔ b12cc8972a67 Pull complete                                                                                                                                            7.6s
   ✔ 4324e307ea00 Pull complete                                                                                                                                            7.7s
   ✔ 152089595ebc Pull complete                                                                                                                                            7.7s
   ✔ 05f217fb8612 Pull complete                                                                                                                                           20.2s
[+] Running 4/4
 ✔ Network milvus               Created                                                                                                                                    0.1s
 ✔ Container milvus-etcd        Started                                                                                                                                    1.6s
 ✔ Container milvus-minio       Started                                                                                                                                    1.6s
 ✔ Container milvus-standalone  Started               

启动 Milvus 后 容器 milvus-standalone、milvus-minio 和 milvus-etcd 已启动。

  • The milvus-etcd 容器不向主机暴露任何端口,并将其数据映射到当前文件夹的 volumes/etcd 中。
  • The milvus-minio 容器在本地上提供端口 9090 和 9091,并将其数据映射到当前文件夹中的 volumes/minio。
  • The milvus-standalone 容器使用默认设置在本地监听 19530 端口,并将其数据映射到当前文件夹中的 volumes/milvus。

在docker客户端Docker Desktop上,点击左侧的“Images”能看到下载的3个镜像:


点击左侧的“Containers”查看启动的容器


4.代码测试

安装依赖包:pip install -U pymilvus

新建文件:hello-milvus.py

# 导入PyMilvus包
from pymilvus import connections, utility

# 定义 Milvus 服务器连接配置字典,避免硬编码 IP 地址和端口号
MILVUS_CONFIG = {
    'host''127.0.0.1',
    'port''19530'
}
# 连接服务器
connections.connect(**MILVUS_CONFIG)
# 获取Milvus服务器版本
version = utility.get_server_version()
# 输出版本号
print(f"Milvus server version: {version}")
# G:\workspace\idea\py\hello-milvus-demo\.venv\Scripts\python.exe G:\workspace\idea\py\hello-milvus-demo\hello-milvus.py 
# Milvus server version: v2.4.6-gpu           # 输出数据库版本号

5.停止并删除该容器

docker compose -f milvus-standalone-docker-compose-gpu.yml down

sudo rm -rf volumes


参考:https://milvus.io/docs/install_standalone-docker-compose.md


往日文章:

为AI而生的向量数据库 - milvus(一) | milvus是什么

人工智能小白到高手:余弦相似度(Cosine Similarity)的简单理解

一文说清楚什么是AI Agent(智能体)

- 免费开源AI最先进的2D和3D人脸识别项目insightface-活体检测(六)

- 本地知识库,通过RAG来解决信息的精准生成

10分钟自己动手搭建一个免费的大语言模型

- 人工智能时代的必读宝典:《ChatGPT调研报告》!

一文说清楚CUDA环境


--END--


AI取经路
踏上取经路,比抵达灵山更重要! AI技术、 AI知识 、 AI应用 、 人工智能 、 大语言模型
 最新文章