Gateway Keepalived 分組

新建 Keepalived 分組

簡介

建立新的 Keepalived 分組,對應 Keepalived 中的 VRRP Instance。 每個 Keepalived 分組有一個唯一的虛擬 IP 對外服務,多個節點組成一主多備的叢集。

URI

POST /admin-api/gateway/{gateway_id}/virtual_groups

JSON body

  • name

    type: string

    required: yes

    description: 新建 Keepalived 叢集的名稱

  • virtual_ip

    type: string

    required: yes

    description: 當前 Keepalived 分組的虛擬 IP 地址

  • virtual_ipv6

    type: string

    required: yes

    description: 當前 Keepalived 分組的虛擬 IPv6 地址

  • status

    type: number

    required: no

    description: 0 代表開啟 DNS 並對外提供服務,1 DNS 解析關閉但可以對外服務,2 代表下線。預設值為 2

  • is_healthy

    type: boolean

    required: no

    description: 虛擬 IP 的健康檢查狀態,true 代表健康,false 代表不健康

  • router_id

    type: number

    required: no

    description: 自動生成的數字 ID,對應 VRRP 協議中的 virtual_router_id,每個虛擬組唯一

  • real_nodes

    type: array

    required: no

    description: Keepalived 組中的真實節點

  • real_nodes[*].node

    type: number

    required: yes

    description: Keepalived 組中真實節點的 ID,對應叢集分組中的節點 ID

  • real_nodes[*].status

    type: number

    required: no

    description: 當前節點的狀態,1 代表 Master,2 代表 BACKUP

  • real_nodes[*].keepalived_managed

    type: bool

    required: no

    description: 該節點是否由 Keepalived 接管。當值為 true 時,該節點本身不再直接對外服務,而是透過 Virtual IP 對外服務(或者作為備節點)

  • real_nodes[*].interface

    type: string

    required: yes

    description: 該節點的網絡卡名,如 eth1 / ens34 等,用於繫結虛擬 IP

  • real_nodes[*].interval

    type: number

    required: no

    description: VRRP 傳送多播 / 單播包的間隔時間,單位為 s 。預設值為 1s

  • real_nodes[*].priority

    type: number

    required: yes

    description: Keepalived 的優先值,0-255 之間,值最大的選舉時會被選為 Master

  • real_nodes[*].detail

    type: string

    required: no

    description: 當前節點的其他資訊,由節點本身上報,不需使用者填寫

請求示例

Shell

curl \
  -X POST \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://admin-site/admin-api/gateway/1/virtual_groups \
  -d '{
      "name": "VG1",
      "virtual_ip": "10.0.0.100",
      "status": 0,
      "real_nodes": [
          {"node": 1, "interface": "eth0", "priority": 254, "status": 2}
      ]
  }'

響應示例

Status: 200 OK
{
    "data":{
        "id":3
    },
    "status":0
}

修改 Keepalived 分組

URI

PUT /admin-api/gateway/{gateway_id}/virtual_groups/{virtual_group_id}

JSON body

  • name

    type: string

    required: yes

    description: 新建 Keepalived 叢集的名稱

  • virtual_ip

    type: string

    required: yes

    description: 當前 Keepalived 分組的虛擬 IP 地址

  • virtual_ipv6

    type: string

    required: yes

    description: 當前 Keepalived 分組的虛擬 IPv6 地址

  • status

    type: number

    required: no

    description: 0 代表開啟 DNS 並對外提供服務,1 DNS 解析關閉但可以對外服務,2 代表下線。預設值為 2

請求示例

Shell

curl \
  -X PUT \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://admin-site/admin-api/gateway/1/virtual_groups/1 \
  -d '{
      "name": "VG1",
      "virtual_ip": "10.0.0.100",
      "status": 1
  }'

響應示例

Status: 200 OK
{
    "status":0
}

獲取 Keepalived 分組

URI

GET /admin-api/gateway/{gateway_id}/virtual_groups

請求示例

Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://admin-site/admin-api/gateway/1/virtual_groups/1

響應示例

Status: 200 OK
{
  "data": {
    "data": [
      {
        "name": "VG1",
        "status": 1,
        "virtual_ip": "1.2.3.4",
        "id": 1,
        "online_status": true,
        "router_id": 1
      }
    ],
    "meta": {
      "count": 1
    }
  },
  "status": 0
}

刪除 Keepalived 分組

URI

DELETE /admin-api/gateway/{gateway_id}/virtual_groups/{virtual_group_id}

請求示例

curl \
  -X DELETE \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://admin-site/admin-api/gateway/1/virtual_groups/1

響應示例

Status: 200 OK
{"status": 0}