Ubuntu
Ubuntu 18.04 netplan 應用中斷網路重啟修復它
設置如下:
host1-ip iface: ens192: 10.100.0.11/16 host1-gateway: ens192: 10.100.0.1 host1-ip iface: ens224: 10.0.0.11/16 host1-gateway: ens224: 10.0.0.1 host2-ip iface: ens192: 10.100.0.12/16 host2-gateway: ens192: 10.100.0.1 host2-ip iface: ens224: 10.0.0.12/16 host2-gateway: ens224: 10.0.0.1 keepalived-vip1 on iface: ens192: 10.100.100.1 keepalived-vip2 on iface: ens224: 10.0.100.1 dns1: 10.100.0.21 dns2: 10.100.0.22
/etc/netplan/01-netcfg.yaml:
# This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: ens192: addresses: [ 10.100.0.11/16 ] gateway4: 10.100.0.1 nameservers: search: [ example.com ] addresses: - "10.100.0.21" - "10.100.0.22" ens224: addresses: [ 10.0.0.11/16 ] nameservers: search: [ example.com ] addresses: - "10.100.0.21" - "10.100.0.22"
有了這個配置
keepalived-vip1 on iface: ens192: 10.100.100.1 <-- works keepalived-vip2 on iface: ens224: 10.0.100.1 <-- dead, not pingable
合乎邏輯的是,沒有為 ens224 介面設置網關,因此 networkd-dispatcher 過來並使用以下腳本為我們設置了 iface ens224 的網關和 keepalived 地址:
/usr/lib/networkd-dispatcher/routable.d/00up:
#!/bin/bash ## INITIALISIERUNG #Diese Werte werden vom netword-dispatcher an das Skript übergeben set -x INTERFACE=${IFACE} ACTION=${STATE} case "${INTERFACE}" in ("ens224") case "${ACTION}" in ("routable") /bin/ip route add table 2 default via 10.0.0.1 /bin/ip rule add from 10.0.100.1 table 2 ;; (*) ;; esac (*) ;; esac
可以重新啟動伺服器,一切正常,使用我的兩個地址並重新啟動,它仍然有效:
keepalived-vip1 on iface: ens192: 10.100.100.1 <-- works keepalived-vip2 on iface: ens224: 10.0.100.1 <-- works
現在我做了一些這樣的命令:
netplan apply systemctl restart systemd-networkd
現在地址已經消失了(keepalived healthcheck,仍然成功,所以沒有發生故障轉移,但在這種情況下,這是調試這個網路計劃//網路//重新啟動行為所需的)
keepalived-vip1 on iface: ens192: 10.100.100.1 <-- dead, not pingable keepalived-vip2 on iface: ens224: 10.0.100.1 <-- dead, not pingable
嘗試使用腳本中的手動步驟修復它:
ip route add table 2 default via 10.0.0.1 ip rule add from 10.0.100.1 table 2
仍然:
keepalived-vip1 on iface: ens192: 10.100.100.1 <-- dead, not pingable keepalived-vip2 on iface: ens224: 10.0.100.1 <-- dead, not pingable
重新啟動伺服器:它恢復功能:
keepalived-vip1 on iface: ens192: 10.100.100.1 <-- works keepalived-vip2 on iface: ens224: 10.0.100.1 <-- works
還用 netplan 嘗試過,在Netplan 中有 2 個 NIC,每個 NIC 連接到不同的網關,但是這樣我無法讓第二個 keepalived-vip 工作。
將回答我自己的問題,經過大量調查後,我偶然發現了一個 keepalived 問題:https ://github.com/acassen/keepalived/issues/836
“systemd-networkd 正在刪除不屬於它的地址”,keepalived 無法在 ubuntu 或 rhel 上發布的版本中檢測到,
我的解決方案是建構一個能夠處理這種情況的 2.0.20 版本的 keepalived 容器
(keepalived >= v2 可以處理)
另一種選擇是嘗試將“關鍵”標誌添加到介面:
network: version: 2 renderer: networkd ethernets: ens192: addresses: [ 10.100.0.11/16 ] gateway4: 10.100.0.1 nameservers: search: [ example.com ] addresses: - "10.100.0.21" - "10.100.0.22" critical: true ens224: addresses: [ 10.0.0.11/16 ] nameservers: search: [ example.com ] addresses: - "10.100.0.21" - "10.100.0.22" critical: true