Backup

查看 Keepalived 的目前狀態

  • April 8, 2022

有沒有辦法在伺服器實例中使用命令行查看目前狀態(主/備份)?

乾杯

您可以使用 notify 命令寫出狀態文件。

      # for ANY state transition.
      # "notify" script is called AFTER the
      # notify_* script(s) and is executed
      # with 3 arguments provided by keepalived
      # (ie don’t include parameters in the notify line).
      # arguments
      # $1 = "GROUP"|"INSTANCE"
      # $2 = name of group or instance
      # $3 = target state of transition
      #     ("MASTER"|"BACKUP"|"FAULT")
      notify /path/notify.sh

創建一個通知腳本,如:

#!/bin/bash
# notify.sh

echo $1 $2 is in $3 state > /var/run/keepalive.$1.$2.state

還有一個獲取狀態腳本,例如:

#!/bin/bash
# getstate.sh

cat /var/run/keepalive.*.*.state

引用自:https://serverfault.com/questions/560024