目录

Windows安装milvus和图形化管理工具attu

Windows安装milvus和图形化管理工具attu

milvus官方网站并没有针对windows系统的安装有系统性的安装讲解,因此走了很多的弯路,为让兄弟们一路畅通,把安装过程做了如下记录。

另外有几点提醒:

1、 windows无法安装milvus lite (网上大多说不支持,只有个别牛人说支持,但是我历尽千辛万苦,尝试了很多方法,依然无效。所以,权当不支持吧,有不怕苦的兄弟,也可以自己试试)

2、 windows安装milvus只支持docker安装 (原本我想要原生安装的,但也是无果,默哀10分钟)

https://i-blog.csdnimg.cn/direct/6ce83c6cbe0d4e22918ada7c8df2f4ec.png#pic_center

一、准备工作

确保电脑上已装了python 3.8+

二、安装Docker

1、先安装Hyper-V

以此打开开:控制面板 - 程序和功能 - 启用或关闭Windows功能,选中Hyper-V,点确定安装

https://i-blog.csdnimg.cn/direct/461ddccb582043f7b9d75188aff0adfc.png

2、下载Docker桌面版

下载地址:https://www.docker.com/

https://i-blog.csdnimg.cn/direct/0a43c06432c94784a28bf50fabf659f6.png

3、运行一直点击下一步安装至完成

https://i-blog.csdnimg.cn/direct/db923e0a1a8242989093ddcbc3cbb4fe.png

https://i-blog.csdnimg.cn/direct/7a948e27cd6d4df7b9ef1caf79b9b427.png

看到这个画面代表安装成功

https://i-blog.csdnimg.cn/direct/7eb7808f3467445581aebd30fc56ae6f.png

如果中途弹出安装wsl –update失败的窗口,就自己用管理员权限打开Windows PowerShell重新执行以下代码

wsl --update

https://i-blog.csdnimg.cn/direct/3ff1de36ca854b28be088cb89a346bcd.png

三、安装Milvus

1、点击此链接下载文件并保存到本地(可能需要梯子),重命名为:standalone.bat

文件链接:https://raw.githubusercontent.com/milvus-io/milvus/refs/heads/master/scripts/standalone_embed.bat

如果无法下载,请新建standalone.bat文件,并将以下代码粘贴至standalone.bat文件中:

@REM  Licensed to the LF AI & Data foundation under one
@REM  or more contributor license agreements. See the NOTICE file
@REM  distributed with this work for additional information
@REM  regarding copyright ownership. The ASF licenses this file
@REM  to you under the Apache License, Version 2.0 (the
@REM  "License"); you may not use this file except in compliance
@REM  with the License. You may obtain a copy of the License at
@REM 
@REM    http://www.apache.org/licenses/LICENSE-2.0
@REM 
@REM  Unless required by applicable law or agreed to in writing, software
@REM  distributed under the License is distributed on an "AS IS" BASIS,
@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@REM  See the License for the specific language governing permissions and
@REM  limitations under the License.

@echo off
setlocal enabledelayedexpansion

:main
if "%1"=="" (
    echo Please use standalone_embed.bat restart^|start^|stop^|delete
    exit /b 1
)

if "%1"=="restart" (
    call :stop
    call :start
) else if "%1"=="start" (
    call :start
) else if "%1"=="stop" (
    call :stop
) else if "%1"=="delete" (
    call :delete
) else (
    echo Unknown command.
    echo Please use standalone_embed.bat restart^|start^|stop^|upgrade^|delete
    exit /b 1
)
goto :eof

:run_embed
(
echo listen-client-urls: http://0.0.0.0:2379
echo advertise-client-urls: http://0.0.0.0:2379
echo quota-backend-bytes: 4294967296
echo auto-compaction-mode: revision
echo auto-compaction-retention: '1000'
) > embedEtcd.yaml

(
echo # Extra config to override default milvus.yaml
) > user.yaml

if not exist "embedEtcd.yaml" (
    echo embedEtcd.yaml file does not exist. Please try to create it in the current directory.
    exit /b 1
)
if not exist "user.yaml" (
    echo user.yaml file does not exist. Please try to create it in the current directory.
    exit /b 1
)

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 "%cd%\volumes\milvus:/var/lib/milvus" ^
    -v "%cd%\embedEtcd.yaml:/milvus/configs/embedEtcd.yaml" ^
    -v "%cd%\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.5 ^
    milvus run standalone >nul
if %errorlevel% neq 0 (
    echo Failed to start Milvus container.
    exit /b 1
)

goto :eof

:wait_for_milvus_running
echo Wait for Milvus Starting...
:wait_loop
for /f "tokens=*" %%A in ('docker ps ^| findstr "milvus-standalone" ^| findstr "healthy"') do set running=1
if "!running!"=="1" (
    echo Start successfully.
    echo To change the default Milvus configuration, edit user.yaml and restart the service.
    goto :eof
)
timeout /t 1 >nul
goto wait_loop

:start
for /f "tokens=*" %%A in ('docker ps ^| findstr "milvus-standalone" ^| findstr "healthy"') do (
    echo Milvus is running.
    exit /b 0
)

for /f "tokens=*" %%A in ('docker ps -a ^| findstr "milvus-standalone"') do set container_exists=1
if defined container_exists (
    docker start milvus-standalone >nul
) else (
    call :run_embed
)

if %errorlevel% neq 0 (
    echo Start failed.
    exit /b 1
)

call :wait_for_milvus_running
goto :eof

:stop
docker stop milvus-standalone >nul
if %errorlevel% neq 0 (
    echo Stop failed.
    exit /b 1
)
echo Stop successfully.
goto :eof

:delete_container
for /f "tokens=*" %%A in ('docker ps ^| findstr "milvus-standalone"') do (
    echo Please stop Milvus service before delete.
    exit /b 1
)
docker rm milvus-standalone >nul
if %errorlevel% neq 0 (
    echo Delete Milvus container failed.
    exit /b 1
)
echo Delete Milvus container successfully.
goto :eof

:delete
call :delete_container
rmdir /s /q "%cd%\volumes"
del /q embedEtcd.yaml
del /q user.yaml
echo Delete successfully.
goto :eof

:EOF

2、执行安装

standalone.bat start

https://i-blog.csdnimg.cn/direct/8c7bc9c623fd47aaa01659d0e66364be.png

(可能需要梯子,请自备)

3、测试链接

在本地新建test.py文件,贴上以下代码,执行后不报错,说明已经安装成功

from pymilvus import connections

# 连接到 Milvus 服务
connections.connect(
    alias="default",
    host='localhost',
    port='19530'
)

四、安装图形化管理工具attu

1、查看docker虚拟IP

打开cmd命令行窗口,并执行以下代码

ipconfig

找到如下IP(WSL (Hyper-V firewall) IPv4地址),如:172.24.208.1

https://i-blog.csdnimg.cn/direct/526bf9b24911412bb398148c4d5aef0e.png

2、执行安装attu

将以下命令中的{milvus server IP}替换成上一步获取到的docker虚拟IP

docker run -p 8000:3000 -e MILVUS_URL={milvus server IP}:19530 zilliz/attu:v2.5

如:

docker run -p 8000:3000 -e MILVUS_URL=172.24.208.1:19530 zilliz/attu:v2.5

等待执行完毕

https://i-blog.csdnimg.cn/direct/0e2c4a587f6f43919eaaabc2b1bc7636.png

在浏览器打开:http://127.0.0.1:8000/

https://i-blog.csdnimg.cn/direct/64ddb285b89f4ba0bfc2241e7ebfced5.png

确保Milvus地址是docker虚拟IP,端口是19530,点击“连接”,即可看到图形化的管理界面了。

https://i-blog.csdnimg.cn/direct/00c5a627285e47c196bd86fa35bd925d.png

五、运行milvus

经过以上步骤安装好milvus后,第二天会发现电脑重启开启,milvus服务却不能用了。可以按照以下方式手动运行,就可以继续访问了。

步骤如下:

打开Docker - Containers,并选中Actions列的运行按钮(三角型按钮)

https://i-blog.csdnimg.cn/direct/61215672fc674fa59c57bfd0bc7341e9.png

点击运行之后,需要等待一段时间,点击Name,可以查看运行进度详情

https://i-blog.csdnimg.cn/direct/a484b245c56a40a4ab28619663d8fac0.png

我们也可以访问http://localhost:19530,如出现下图显示,也代表milvus已运行成功

https://i-blog.csdnimg.cn/direct/d779a01da78c45a385fff8be0467f1a7.png