1 Commits

Author SHA1 Message Date
zhaoyukun
9f8f641402 add_vlan_monitor 2026-04-27 10:35:33 +08:00
2 changed files with 77 additions and 21 deletions

View File

@@ -20,6 +20,14 @@ YEWU_DNS="192.168.46.44"
YEWU_IFACE="yewu-peer"
YEWU_MAC="02:aa:bb:cc:dd:01"
# monitor VLAN 配置
MONITOR_VLAN_ID=100
MONITOR_PHY_IFACE="eth11"
MONITOR_ALIAS="lsa"
# -------------------
# k3s 配置
# -------------------

View File

@@ -66,15 +66,6 @@ ConfigureWithoutCarrier=yes
RequiredForOnline=no-carrier
EOF
# cloud VLAN 子接口
# cat > /etc/systemd/network/10-monitor.netdev << EOF
# [NetDev]
# Name=cloud-monitor
# Kind=vlan
# [VLAN]
# Id=$MONITOR_VLAN_ID
# EOF
cat > /etc/systemd/network/00-$CLOUD_IFACE.network << EOF
[Match]
@@ -94,17 +85,6 @@ PVID=1
EgressUntagged=1
EOF
# cat > /etc/systemd/network/10-monitor.network << EOF
# # monitor
# [Match]
# Name=cloud-monitor
# [Network]
# ConfigureWithoutCarrier=yes
# [Link]
# RequiredForOnline=no-carrier
# EOF
echo "cloud 网桥配置已完成"
@@ -162,6 +142,74 @@ echo "正在重新加载网络配置..."
networkctl reload
echo "网络配置已生效"
# ===================================================
# 新增部分monitor VLAN 子接口配置
# ===================================================
echo "=== 开始配置 monitor VLAN 子接口 ==="
: "${MONITOR_VLAN_ID:?请在 bushu.conf 中配置 MONITOR_VLAN_ID}"
: "${MONITOR_PHY_IFACE:?请在 bushu.conf 中配置 MONITOR_PHY_IFACE}"
: "${MONITOR_ALIAS:=lsa}"
MONITOR_VLAN_IFACE="${MONITOR_PHY_IFACE}.${MONITOR_VLAN_ID}"
echo "monitor 物理网卡: ${MONITOR_PHY_IFACE}"
echo "monitor VLAN ID: ${MONITOR_VLAN_ID}"
echo "monitor VLAN 子接口: ${MONITOR_VLAN_IFACE}"
echo "monitor VLAN alias: ${MONITOR_ALIAS}"
modprobe 8021q || true
if ip link show "${MONITOR_VLAN_IFACE}" >/dev/null 2>&1; then
echo "VLAN 子接口 ${MONITOR_VLAN_IFACE} 已存在,跳过创建"
else
echo "正在创建 VLAN 子接口 ${MONITOR_VLAN_IFACE} ..."
ip link add link "${MONITOR_PHY_IFACE}" name "${MONITOR_VLAN_IFACE}" type vlan id "${MONITOR_VLAN_ID}"
fi
ip link set dev "${MONITOR_VLAN_IFACE}" alias "${MONITOR_ALIAS}"
ip link set dev "${MONITOR_VLAN_IFACE}" up
echo "monitor VLAN 子接口 ${MONITOR_VLAN_IFACE} 当前已生效"
# -----------------------
# 新增部分:写入 rc.local保证重启后自动创建
# -----------------------
echo "=== 写入 rc.local配置 monitor VLAN 开机自动创建 ==="
if [[ ! -f /etc/rc.local ]]; then
cat > /etc/rc.local << 'EOF'
#!/bin/bash
exit 0
EOF
chmod +x /etc/rc.local
fi
sed -i '/# BEGIN MONITOR VLAN/,/# END MONITOR VLAN/d' /etc/rc.local
sed -i "/^exit 0/i\\
# BEGIN MONITOR VLAN\\
modprobe 8021q || true\\
while ! ip link show ${MONITOR_PHY_IFACE} >/dev/null 2>&1; do\\
sleep 1\\
done\\
ip link show ${MONITOR_VLAN_IFACE} >/dev/null 2>&1 || ip link add link ${MONITOR_PHY_IFACE} name ${MONITOR_VLAN_IFACE} type vlan id ${MONITOR_VLAN_ID}\\
ip link set dev ${MONITOR_VLAN_IFACE} alias ${MONITOR_ALIAS}\\
ip link set dev ${MONITOR_VLAN_IFACE} up\\
# END MONITOR VLAN\\
" /etc/rc.local
chmod +x /etc/rc.local
systemctl enable rc-local 2>/dev/null || true
systemctl enable rc-local.service 2>/dev/null || true
echo "rc.local 已写入 monitor VLAN 配置"
# -----------------------
# k3s 配置部分
# -----------------------