pve/build_backend.sh

80 lines
2.3 KiB
Bash
Raw Normal View History

2023-02-15 15:03:21 +08:00
#!/bin/bash
#from https://github.com/spiritLHLS/pve
2023-02-17 10:31:28 +08:00
# 打印信息
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
# 创建资源池
_green "正在创建资源池 mypool..."
pvesh create /pools --poolid mypool
_green "资源池 mypool 已创建!"
2023-02-15 15:03:21 +08:00
# 创建网桥
2023-02-19 10:01:34 +08:00
#!/bin/bash
# 选择桥接接口的标准
bridge_interface_pattern="eth*"
2023-02-17 10:08:03 +08:00
interfaces=($(ls /sys/class/net))
for interface in ${interfaces[@]}; do
2023-02-19 10:01:34 +08:00
if [[ $interface != "lo" ]] && [[ $interface =~ $bridge_interface_pattern ]]; then
2023-02-17 10:08:03 +08:00
bridge_ports="$interface"
break
fi
done
if [[ -z $bridge_ports ]]; then
2023-02-19 10:01:34 +08:00
echo "错误:找不到可用网络接口"
2023-02-17 10:08:03 +08:00
exit 1
fi
2023-02-19 10:01:34 +08:00
ipv4_address="192.168.1.1"
ipv4_netmask="255.255.255.0"
ipv6_address=$(ip -6 addr show dev $bridge_ports | awk '/inet6/{print $2;exit}' | cut -d'/' -f1)
ipv6_netmask=$(ip -6 addr show dev $bridge_ports | awk '/inet6/{print $4;exit}' | cut -d'/' -f1)
cat <<EOF > /etc/network/interfaces.d/vmbr1.cfg
2023-02-15 15:03:21 +08:00
auto vmbr1
iface vmbr1 inet static
2023-02-19 10:01:34 +08:00
address $ipv4_address
netmask $ipv4_netmask
2023-02-17 10:08:03 +08:00
bridge_ports $bridge_ports
2023-02-15 15:03:21 +08:00
bridge_stp off
bridge_fd 0
2023-02-17 10:08:03 +08:00
iface vmbr1 inet6 static
2023-02-19 10:01:34 +08:00
address $ipv6_address
netmask $ipv6_netmask
2023-02-15 15:03:21 +08:00
EOF
2023-02-17 09:54:10 +08:00
if grep -q "iface vmbr1" /etc/network/interfaces; then
2023-02-19 10:01:34 +08:00
echo "网桥 vmbr1 已经在 Proxmox VE 配置中"
2023-02-17 09:54:10 +08:00
else
2023-02-19 10:01:34 +08:00
# 添加到配置文件
2023-02-17 09:54:10 +08:00
cat <<EOF >> /etc/network/interfaces
# Proxmox VE bridge vmbr1
iface vmbr1 inet manual
2023-02-17 10:08:03 +08:00
bridge-ports $bridge_ports
2023-02-17 09:54:10 +08:00
bridge-stp off
bridge-fd 0
EOF
fi
2023-02-15 15:03:21 +08:00
systemctl restart networking.service
2023-02-19 10:01:34 +08:00
echo "网桥 vmbr1 已创建!"
2023-02-17 10:16:17 +08:00
# 检测AppArmor模块
if ! dpkg -s apparmor > /dev/null 2>&1; then
2023-02-17 10:31:28 +08:00
_green "正在安装 AppArmor..."
2023-02-17 10:16:17 +08:00
apt-get update
apt-get install -y apparmor
fi
if ! systemctl is-active --quiet apparmor.service; then
2023-02-17 10:31:28 +08:00
_green "启动 AppArmor 服务..."
2023-02-17 10:16:17 +08:00
systemctl enable apparmor.service
systemctl start apparmor.service
fi
if ! lsmod | grep -q apparmor; then
2023-02-17 10:31:28 +08:00
_green "正在加载 AppArmor 内核模块..."
2023-02-17 10:16:17 +08:00
modprobe apparmor
fi
if ! lsmod | grep -q apparmor; then
2023-02-19 09:57:08 +08:00
_yellow "AppArmor 仍未加载可能需要重新启动系统加载但你可以在面板尝试创建并启动CT"
2023-02-17 10:16:17 +08:00
fi