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}