Windows安装milvus和图形化管理工具attu
Windows安装milvus和图形化管理工具attu
milvus官方网站并没有针对windows系统的安装有系统性的安装讲解,因此走了很多的弯路,为让兄弟们一路畅通,把安装过程做了如下记录。
另外有几点提醒:
1、 windows无法安装milvus lite (网上大多说不支持,只有个别牛人说支持,但是我历尽千辛万苦,尝试了很多方法,依然无效。所以,权当不支持吧,有不怕苦的兄弟,也可以自己试试)
2、 windows安装milvus只支持docker安装 (原本我想要原生安装的,但也是无果,默哀10分钟)
一、准备工作
确保电脑上已装了python 3.8+
二、安装Docker
1、先安装Hyper-V
以此打开开:控制面板 - 程序和功能 - 启用或关闭Windows功能,选中Hyper-V,点确定安装
2、下载Docker桌面版
下载地址:https://www.docker.com/
3、运行一直点击下一步安装至完成
看到这个画面代表安装成功
如果中途弹出安装wsl –update失败的窗口,就自己用管理员权限打开Windows PowerShell重新执行以下代码
wsl --update
三、安装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
(可能需要梯子,请自备)
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
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
等待执行完毕
在浏览器打开:http://127.0.0.1:8000/
确保Milvus地址是docker虚拟IP,端口是19530,点击“连接”,即可看到图形化的管理界面了。
五、运行milvus
经过以上步骤安装好milvus后,第二天会发现电脑重启开启,milvus服务却不能用了。可以按照以下方式手动运行,就可以继续访问了。
步骤如下:
打开Docker - Containers,并选中Actions列的运行按钮(三角型按钮)
点击运行之后,需要等待一段时间,点击Name,可以查看运行进度详情
我们也可以访问http://localhost:19530,如出现下图显示,也代表milvus已运行成功