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"; }
|
|
|
|
|
|
|
|
# 创建资源池
|
2023-02-24 14:09:08 +08:00
|
|
|
POOL_ID="mypool"
|
|
|
|
if pvesh get /pools/$POOL_ID > /dev/null 2>&1 ; then
|
2023-02-24 14:09:37 +08:00
|
|
|
_green "资源池 $POOL_ID 已经存在!"
|
2023-02-24 14:00:22 +08:00
|
|
|
else
|
2023-02-24 14:09:08 +08:00
|
|
|
# 如果不存在则创建
|
|
|
|
_green "正在创建资源池 $POOL_ID..."
|
|
|
|
pvesh create /pools --poolid $POOL_ID
|
|
|
|
_green "资源池 $POOL_ID 已创建!"
|
2023-02-24 14:00:22 +08:00
|
|
|
fi
|
2023-02-24 10:39:40 +08:00
|
|
|
|
2023-02-25 21:11:17 +08:00
|
|
|
# 安装必备模块并替换apt源中的无效订阅
|
|
|
|
cp /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak
|
|
|
|
echo "deb http://download.proxmox.com/debian/pve $(lsb_release -sc) pve-no-subscription" > /etc/apt/sources.list.d/pve-enterprise.list
|
2023-02-24 14:11:43 +08:00
|
|
|
apt-get update
|
2023-02-24 14:09:08 +08:00
|
|
|
install_required_modules() {
|
2023-02-24 14:18:44 +08:00
|
|
|
modules=("sudo" "ifupdown2" "lshw" "iproute2" "net-tools" "cloud-init" "novnc" "isc-dhcp-server")
|
2023-02-24 14:09:08 +08:00
|
|
|
for module in "${modules[@]}"
|
|
|
|
do
|
|
|
|
if dpkg -s $module > /dev/null 2>&1 ; then
|
2023-02-24 14:09:37 +08:00
|
|
|
_green "$module 已经安装!"
|
2023-02-24 14:09:08 +08:00
|
|
|
else
|
|
|
|
apt-get install -y $module
|
2023-02-24 14:09:37 +08:00
|
|
|
_green "$module 已成功安装!"
|
2023-02-24 14:09:08 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
install_required_modules
|
2023-02-23 22:41:11 +08:00
|
|
|
|
2023-02-25 21:49:19 +08:00
|
|
|
# 更新内核
|
|
|
|
# apt-get install -y pve-kernel-5.4.98-1-pve
|
|
|
|
update-grub
|
|
|
|
apt-get remove -y linux-image*
|
|
|
|
|
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-25 21:49:19 +08:00
|
|
|
_yellow "AppArmor 仍未加载,需要重新启动系统加载"
|
2023-02-17 10:16:17 +08:00
|
|
|
fi
|