如何使克隆资源在 Pacemaker 中特定资源启动后启动?

如何使克隆资源在 Pacemaker 中特定资源启动后启动?

我有一个主/主配置,它有 2 个公共 IP(1.1.1.66、1.1.1.70),由 2 个节点共享。这个想法是两个节点各有一个公共 IP。如果其中一个节点发生故障,另一个节点将采用它的公共 IP 并开始从两个 IP 提供服务。

该配置还具有一个克隆的网关(ocf:heartbeat:Route)资源,该资源应该在公共 IP 之后启动。

我遇到了这个问题:

  1. 第一个节点处于活动状态。
  2. 第二个节点已死。
  3. 第一个节点附加有 2 个公共 IP。
  4. 第二个节点重新启动。
  5. 尽管公共 IP 在第一个节点上仍处于活动状态,克隆网关 (ocf:heartbeat:Route) 仍尝试在第二个节点上启动。这会导致失败。

失败的操作:haproxy-02 上的 default_gw_start_0'未知错误'(1):call=32、status=complete、exitreason='default_gw 无法添加网络路由:通过 1.1.1.65 添加到 0.0.0.0/0 dev eth0',last-rc-change='Thu Dec 26 01:03:36 2019',queued=0ms,exec=38ms

如何让第二个节点等待公共 IP 返回后再尝试启动克隆路由资源?

我的配置:

pcs resource create ip_1 ocf:heartbeat:IPaddr2 ip=1.1.1.66 cidr_netmask=29 nic="eth0" op monitor interval=30s
pcs resource create ip_2 ocf:heartbeat:IPaddr2 ip=1.1.1.70 cidr_netmask=29 nic="eth0" op monitor interval=30s

pcs resource create default_gw ocf:heartbeat:Route destination="0.0.0.0/0" device="eth0" gateway="1.1.1.65" family=""
pcs resource clone default_gw globally-unique="true"

pcs constraint order ip_1 then default_gw-clone
pcs constraint order ip_2 then default_gw-clone

pcs constraint colocation add ip_1 ip_2 -1

** 更新:临时解决方案是避免完全克隆路由资源并为每个主机创建单独的路由资源(我将它们称为 default_gw_1 和 default_gw_2):**

pcs resource delete default_gw
pcs resource create default_gw_1 ocf:heartbeat:Route destination="0.0.0.0/0" device="eth0" gateway="1.1.1.65" family="ip4" --force
pcs resource create default_gw_2 ocf:heartbeat:Route destination="0.0.0.0/0" device="eth0" gateway="1.1.1.65" family="ip4" --force

# start ips first, then start routes
pcs constraint order ip_1 then default_gw_1
pcs constraint order ip_2 then default_gw_2

# otherwise routes try to start on nodes without the ip attached (and fail)
pcs constraint colocation add default_gw_1 with ip_1 INFINITY 
pcs constraint colocation add default_gw_2 with ip_2 INFINITY 

# lock routes to start on their specific nodes only
pcs constraint location add gateway_1 default_gw_1 haproxy-01 INFINITY resource-discovery=exclusive
pcs constraint location add gateway_2 default_gw_2 haproxy-02 INFINITY resource-discovery=exclusive

# this will fight with stickiness 
pcs constraint location ip_1 prefers haproxy-01=50
pcs constraint location ip_2 prefers haproxy-02=50 
pcs resource defaults resource-stickiness=100

相关内容