• 關於 Milvus
  • 開始使用
  • 概念
  • 使用者指南
  • 資料匯入
  • AI 工具
  • 管理指南
  • 工具
  • 整合功能
  • 教學指南
  • 常見問題
  • API Reference

(已停用) 在 EC2 上部署 Milvus 群集

本主題描述如何使用 Terraform 和 Ansible 在Amazon EC2上部署 Milvus 叢集。

此主題已經過時,即將移除。建議您參考在 EKS 上部署 Milvus 叢集。

佈建 Milvus 叢集

本節說明如何使用 Terraform 來佈建 Milvus 叢集。

Terraform是基礎架構即程式碼 (IaC) 軟體工具。透過 Terraform,您可以使用宣告式組態檔案來佈建基礎設施。

先決條件

準備配置

您可以從Google Drive 下載範本配置檔案。

  • main.tf

    此檔案包含配置 Milvus 集群的配置。

  • variables.tf

    此檔案可快速編輯用於設定或更新 Milvus 叢集的變數。

  • output.tf 以及inventory.tmpl

    這些檔案儲存 Milvus 叢集的元資料。本主題中使用的元資料為每個節點實體的public_ip 、每個節點實體的private_ip ,以及所有 EC2 實體 ID。

準備變數.tf

本節說明variables.tf 檔案所包含的配置。

  • 節點數量

    以下範本宣告一個index_count 變數,用於設定索引節點的數量。

    index_count 的值必須大於或等於 1。
    variable "index_count" {
      description = "Amount of index instances to run"
      type        = number
      default     = 5
    }
    
  • 節點類型的實例類型

    以下範本宣告一個index_ec2_type 變數,用來設定索引節點的實體類型。

    variable "index_ec2_type" {
      description = "Which server type"
      type        = string
      default     = "c5.2xlarge"
    }
    
  • 存取權限

    以下範本宣告了key_name 變數和my_ip 變數。key_name 變數代表 AWS 存取權限金鑰。my_ip 變數代表安全群組的 IP 位址範圍。

    variable "key_name" {
      description = "Which aws key to use for access into instances, needs to be uploaded already"
      type        = string
      default     = ""
    }
    
    variable "my_ip" {
      description = "my_ip for security group. used so that ansible and terraform can ssh in"
      type        = string
      default     = "x.x.x.x/32"
    }
    

準備 main.tf

本節說明main.tf 檔案所包含的設定。

  • 雲提供商和區域

    以下範本使用us-east-2 區域。如需詳細資訊,請參閱可用區域。

    provider "aws" {
      profile = "default"
      region  = "us-east-2"
    }
    
  • 安全群組

    以下模板声明了一个安全组,允许来自variables.tf 中声明的my_ip 所代表的 CIDR 地址范围的传入流量。

    resource "aws_security_group" "cluster_sg" {
      name        = "cluster_sg"
      description = "Allows only me to access"
      vpc_id      = aws_vpc.cluster_vpc.id
    
      ingress {
        description      = "All ports from my IP"
        from_port        = 0
        to_port          = 65535
        protocol         = "tcp"
        cidr_blocks      = [var.my_ip]
      }
    
      ingress {
        description      = "Full subnet communication"
        from_port        = 0
        to_port          = 65535
        protocol         = "all"
        self             = true
      }
    
      egress {
        from_port        = 0
        to_port          = 0
        protocol         = "-1"
        cidr_blocks      = ["0.0.0.0/0"]
        ipv6_cidr_blocks = ["::/0"]
      }
    
      tags = {
        Name = "cluster_sg"
      }
    }
    
  • VPC

    以下範本在 Milvus 群集中指定一個具有 10.0.0.0/24 CIDR 區塊的 VPC。

    resource "aws_vpc" "cluster_vpc" {
      cidr_block = "10.0.0.0/24"
      tags = {
        Name = "cluster_vpc"
      }
    }
    
    resource "aws_internet_gateway" "cluster_gateway" {
      vpc_id = aws_vpc.cluster_vpc.id
    
      tags = {
        Name = "cluster_gateway"
      }
    }
    
  • 子網路 (選用)

    以下範本宣告一個子網路,其流量會路由到網際網路閘道。在這種情況下,子網路的 CIDR 區塊大小與 VPC 的 CIDR 區塊大小相同。

    resource "aws_subnet" "cluster_subnet" {
      vpc_id                  = aws_vpc.cluster_vpc.id
      cidr_block              = "10.0.0.0/24"
      map_public_ip_on_launch = true
    
      tags = {
        Name = "cluster_subnet"
      }
    }
    
    resource "aws_route_table" "cluster_subnet_gateway_route" {
      vpc_id       = aws_vpc.cluster_vpc.id
    
      route {
        cidr_block = "0.0.0.0/0"
        gateway_id = aws_internet_gateway.cluster_gateway.id
      }
    
      tags = {
        Name = "cluster_subnet_gateway_route"
      }
    }
    
    resource "aws_route_table_association" "cluster_subnet_add_gateway" {
      subnet_id      = aws_subnet.cluster_subnet.id
      route_table_id = aws_route_table.cluster_subnet_gateway_route.id
    }
    
    
  • 節點實體 (節點)

    以下範本宣告 MinIO 節點實體。main.tf 範本檔案宣告 11 種節點類型的節點。對於某些節點類型,您需要設定root_block_device 。如需詳細資訊,請參閱EBS、Ephemeral 和 Root Block Devices。

    resource "aws_instance" "minio_node" {
      count         = var.minio_count
      ami           = "ami-0d8d212151031f51c"
      instance_type = var.minio_ec2_type
      key_name      = var.key_name
      subnet_id     = aws_subnet.cluster_subnet.id 
      vpc_security_group_ids = [aws_security_group.cluster_sg.id]
    
      root_block_device {
        volume_type = "gp2"
        volume_size = 1000
      }
      
      tags = {
        Name = "minio-${count.index + 1}"
      }
    }
    

套用組態

  1. 開啟終端機,並導航至存放main.tf 的資料夾。

  2. 若要初始化組態,請執行terraform init 。

  3. 若要套用組態,請執行terraform apply ,並在出現提示時輸入yes 。

現在您已使用 Terraform 佈建 Milvus 叢集。

啟動 Milvus 叢集

本節將介紹如何使用 Ansible 啟動已佈建的 Milvus 叢集。

Ansible是用來自動化雲端佈建和配置管理的配置管理工具。

先決條件

下載 Ansible Milvus 節點部署 Playbook

從 GitHub 複製 Milvus 套件庫,下載 Ansible Milvus 節點部署 Playbook。

git clone https://github.com/milvus-io/milvus.git

設定安裝檔案

inventory.ini 和ansible.cfg 檔案用來控制 Ansible playbook 中的環境變數和登入驗證方法。在inventory.ini 檔案中,dockernodes 部份定義了所有 docker 引擎的伺服器。ansible.cfg 部分定義 Milvus 協調器的所有伺服器。node 部份定義 Milvus 節點的所有伺服器。

輸入 Playbook 的本機路徑並設定安裝檔案。

$ cd ./milvus/deployments/docker/cluster-distributed-deployment

inventory.ini

配置inventory.ini ,按照主機在 Milvus 系統中的角色將其分組。

添加主机名,并定义docker 组和vars 。

[dockernodes] #Add docker host names.
dockernode01
dockernode02
dockernode03

[admin] #Add Ansible controller name.
ansible-controller

[coords] #Add the host names of Milvus coordinators.
; Take note the IP of this host VM, and replace 10.170.0.17 with it.
dockernode01

[nodes] #Add the host names of Milvus nodes.
dockernode02

[dependencies] #Add the host names of Milvus dependencies.
; dependencies node will host etcd, minio, pulsar, these 3 roles are the foundation of Milvus. 
; Take note the IP of this host VM, and replace 10.170.0.19 with it.
dockernode03

[docker:children]
dockernodes
coords
nodes
dependencies

[docker:vars]
ansible_python_interpreter= /usr/bin/python3
StrictHostKeyChecking= no

; Setup variables to control what type of network to use when creating containers.
dependencies_network= host
nodes_network= host

; Setup varibale to control what version of Milvus image to use.
image= milvusdb/milvus-dev:master-20220412-4781db8a

; Setup static IP addresses of the docker hosts as variable for container environment variable config.
; Before running the playbook, below 4 IP addresses need to be replaced with the IP of your host VM
; on which the etcd, minio, pulsar, coordinators will be hosted.
etcd_ip= 10.170.0.19
minio_ip= 10.170.0.19
pulsar_ip= 10.170.0.19
coords_ip= 10.170.0.17

; Setup container environment which later will be used in container creation.
ETCD_ENDPOINTS= {{etcd_ip}}:2379 
MINIO_ADDRESS= {{minio_ip}}:9000
PULSAR_ADDRESS= pulsar://{{pulsar_ip}}:6650
QUERY_COORD_ADDRESS= {{coords_ip}}:19531
DATA_COORD_ADDRESS= {{coords_ip}}:13333
ROOT_COORD_ADDRESS= {{coords_ip}}:53100
INDEX_COORD_ADDRESS= {{coords_ip}}:31000

ansible.cfg

ansible.cfg 控制 playbook 的動作,例如 SSH 金鑰等。不要在 docker 主機上透過 SSH key 設定 passphrase。否則 Ansible SSH 連線會失敗。建議在三台主機上設定相同的使用者名稱和 SSH 金鑰,並設定新的使用者帳號無需密碼即可執行 sudo。否則,在執行 Ansible playbook 時,您會收到使用者名稱與密碼不符或未獲賦予提升權限的錯誤。

[defaults]
host_key_checking = False
inventory = inventory.ini # Specify the Inventory file
private_key_file=~/.my_ssh_keys/gpc_sshkey # Specify the SSH key that Ansible uses to access Docker host

deploy-docker.yml

deploy-docker.yml 定義安裝 Docker 時的任務。詳情請參閱檔案中的程式碼註解。

---
- name: setup pre-requisites # Install prerequisite
  hosts: all
  become: yes
  become_user: root
  roles:
    - install-modules
    - configure-hosts-file

- name: install docker
  become: yes
  become_user: root
  hosts: dockernodes
  roles:
    - docker-installation

測試 Ansible 連線性

測試與 Ansible 的連線性。

$ ansible all -m ping

如果您沒有在ansible.cfg 中指定 inventory 檔案的路徑,請在指令中加入-i ,否則 Ansible 會使用/etc/ansible/hosts 。

終端返回如下:

dockernode01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
ansible-controller | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}
dockernode03 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
dockernode02 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

檢查 Playbook 語法

檢查 Playbook 的語法。

$ ansible-playbook deploy-docker.yml --syntax-check

通常,終端返回如下:

playbook: deploy-docker.yml

安裝 Docker

使用 Playbook 安裝 Docker。

$ ansible-playbook deploy-docker.yml

如果 Docker 已成功安裝在三台主機上,終端機會返回如下內容:

TASK [docker-installation : Install Docker-CE] *******************************************************************
ok: [dockernode01]
ok: [dockernode03]
ok: [dockernode02]

TASK [docker-installation : Install python3-docker] **************************************************************
ok: [dockernode01]
ok: [dockernode02]
ok: [dockernode03]

TASK [docker-installation : Install docker-compose python3 library] **********************************************
changed: [dockernode01]
changed: [dockernode03]
changed: [dockernode02]

PLAY RECAP *******************************************************************************************************
ansible-controller         : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
dockernode01               : ok=10   changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
dockernode02               : ok=10   changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
dockernode03               : ok=10   changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

驗證安裝

使用 SSH 金鑰登入三台主機,並驗證在主機上的安裝。

  • 針對 root 主機
$ docker -v
  • 對於非 root 主機:
$ sudo docker -v

正常情況下,終端返回如下內容:

Docker version 20.10.14, build a224086

檢查容器的執行狀態。

$ docker ps

檢查語法

檢查deploy-milvus.yml 的語法。

$ ansible-playbook deploy-milvus.yml --syntax-check

通常,終端返回如下內容:

playbook: deploy-milvus.yml

創建 Milvus 容器

創建 Milvus 容器的任務定義在deploy-milvus.yml 。

$ ansible-playbook deploy-milvus.yml

終端返回:

PLAY [Create milvus-etcd, minio, pulsar] *****************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [dockernode03]

TASK [etcd] *******************************************************************************************************
changed: [dockernode03]

TASK [pulsar] *****************************************************************************************************
changed: [dockernode03]

TASK [minio] ******************************************************************************************************
changed: [dockernode03]

PLAY [Create milvus nodes] ****************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [dockernode02]

TASK [querynode] **************************************************************************************************
changed: [dockernode02]

TASK [datanode] ***************************************************************************************************
changed: [dockernode02]

TASK [indexnode] **************************************************************************************************
changed: [dockernode02]

PLAY [Create milvus coords] ***************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [dockernode01]

TASK [rootcoord] **************************************************************************************************
changed: [dockernode01]

TASK [datacoord] **************************************************************************************************
changed: [dockernode01]

TASK [querycoord] *************************************************************************************************
changed: [dockernode01]

TASK [indexcoord] *************************************************************************************************
changed: [dockernode01]

TASK [proxy] ******************************************************************************************************
changed: [dockernode01]

PLAY RECAP ********************************************************************************************************
dockernode01               : ok=6    changed=5    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
dockernode02               : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
dockernode03               : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

現在您已經在三台主機上部署了 Milvus。

停止節點

不再需要 Milvus 集群後,您可以停止所有節點。

確保terraform 二進位檔在您的PATH 上可用。
  1. 執行terraform destroy ,並在提示時輸入yes 。

  2. 如果成功,所有節點實例都會停止。

下一步

如果您想學習如何在其他雲端部署 Milvus: