Sanlock 在 RedHat Virtualization 中是如何工作的

在 RHV 中,KVM Host 使用 Sanlock 检测与存储域的连接。
当 Sanlock 使能时,它会打开 wdmd 守护进程(看门狗复用守护进程)并以一定的心跳发送 keepalive。
sanlock IO 到存储没有在固定时间内完成,sanlock 停止向 wdmd 发送 keepalive。
当超时时,控制 /dev/watchdog 的 wdmd 守护进程会记录错误,警告看门狗没有保持活动状态,很快就会过期,然后触发并重置 KVM 主机。

$ systemctl status sanlock
● sanlock.service - Shared Storage Lease Manager
Loaded: loaded (/usr/lib/systemd/system/sanlock.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-07-13 15:03:26 NZST; 1 months 19 days ago
Process: 1041 ExecStart=/usr/sbin/sanlock daemon (code=exited, status=0/SUCCESS)
Main PID: 1044 (sanlock)
Tasks: 7
Memory: 18.6M
CGroup: /system.slice/sanlock.service
├─1044 /usr/sbin/sanlock daemon
└─1045 /usr/sbin/sanlock daemon
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
$ systemctl status wdmd
● wdmd.service - Watchdog Multiplexing Daemon
Loaded: loaded (/usr/lib/systemd/system/wdmd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-07-13 15:03:26 NZST; 1 months 19 days ago
Process: 1131 ExecStart=/usr/sbin/wdmd (code=exited, status=0/SUCCESS)
Process: 1112 ExecStartPre=/lib/systemd/systemd-wdmd watchdog-check (code=exited, status=0/SUCCESS)
Main PID: 1133 (wdmd)
Tasks: 1
Memory: 2.3M
CGroup: /system.slice/wdmd.service
└─1133 /usr/sbin/wdmd
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

sanlock 守护进程以固定的时间间隔不断地写入存储以更新其租约。
Sanlock 会根据 sanlock IO 到存储结果将 KVM 主机标记为 UNKNOWN、FREE、LIVE、FAIL 和 DEAD 状态。

UNKNOWN:

KVM 主机在存储上有租约,但集群锁无法判断主机是活跃还是死机。
通常会持续 10-20 秒,但在 KVM 主机被视为活动或者失败之前,这可能会持续长达 80 秒。

FREE:

此主机 ID 没有租用。

LIVE:

KVM 主机在过去 80 秒内已续订租约。
它现在可能会续订或者不续约,我们只能稍后再检查才能知道。

FAIL:

主机已 80 秒未续订租约。
在宿主被认为死亡之前会持续 60 秒。
当 KVM 主机状态被标记为“失败”时,我们将看到相关日志:

2020-08-31 21:35:01 1665117 [1044]: s1 check_our_lease warning 72 last_success 1665045
2020-08-31 21:35:02 1665118 [1044]: s1 check_our_lease warning 73 last_success 1665045
2020-08-31 21:35:03 1665119 [1044]: s1 check_our_lease warning 74 last_success 1665045
2020-08-31 21:35:04 1665120 [1044]: s1 check_our_lease warning 75 last_success 1665045
2020-08-31 21:35:05 1665121 [1044]: s1 check_our_lease warning 76 last_success 1665045
2020-08-31 21:35:06 1665122 [1044]: s1 check_our_lease warning 77 last_success 1665045
2020-08-31 21:35:07 1665123 [1044]: s1 check_our_lease warning 78 last_success 1665045
2020-08-31 21:35:08 1665124 [1044]: s1 check_our_lease warning 79 last_success 1665045
2020-08-31 21:35:09 1665125 [1044]: s1 check_our_lease failed 80
2020-08-31 21:35:10 1665125 [1044]: s1 all pids clear
2020-08-31 21:35:21 1665137 [3859]: 8d627013 aio timeout RD 0x7f56e00009b0:0x7f56e00009c0:0x7f56f0299000 ioto 10 to_count 4
2020-08-31 21:35:21 1665137 [3859]: s1 delta_renew read timeout 10 sec offset 0 /rhev/data-center/mnt/[mountpoint]/[SD_UUID]/dom_md/ids
2020-08-31 21:35:21 1665137 [3859]: s1 renewal error -202 delta_length 20 last_success 1665045

DEAD:

主机已 140 秒未续订租约。

如果sanlock IO to storage 没有在固定时间内完成,sanlock daemon 将进入recovery。
恢复开始于 sanlock 守护进程尝试使用受影响存储上的租约杀死(SIGTERM)任何 pid。
如果 10 个 SIGTERM 超过 10 秒后任何 pid 没有退出,sanlock 将尝试 kill(SIGKILL)。
如果 pid 在固定时间内仍未退出,则看门狗将触发,重置主机。
如果所有 pid 在必要的时间内退出,则看门狗将被更新并且不会触发。

日期:2020-09-17 00:12:53 来源:oir作者:oir