debian 11 vps 安装 pve7

发布于 2023-09-27
1 基础环境配置 1.1 配置 hosts 1.1.1 检查是否启用了 manage_etc_hosts 先 cat /etc/hosts 文件,查看下默认配置,看看有没有一些注释说明该文件是自动设置的(一般 cloud-init 方式安装的系统会有这个),如 vultr 的该文件开头注释:

1 基础环境配置

1.1 配置 hosts

1.1.1 检查是否启用了 manage_etc_hosts

cat /etc/hosts 文件,查看下默认配置,看看有没有一些注释说明该文件是自动设置的(一般 cloud-init 方式安装的系统会有这个),如 vultr 的该文件开头注释:

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#

注释的意思是,你的系统开启了 manage_etc_hosts 功能,如果你想修改 /etc/hosts 内容,有两种办法:

  1. 编辑模板文件 /etc/cloud/templates/hosts.debian.tmpl,这种重启后 /etc/hosts 会自动重置为该模板的内容。
  2. 修改 /etc/cloud/cloud.cfg 文件,关闭掉 manage_etc_hosts 功能,然后再修改 /etc/hosts。 推荐使用第一种方式。

1.1.2 修改 hosts 文件

需保证 /etc/hosts 文件为下面的内容,第二行要修改为你服务器的 ip 地址和 hostname,如我的 ip45.76.157.191hostnamevultr

127.0.0.1       localhost
45.76.157.191   vultr.proxmox.com vultr

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

如果你检查到你机器启用了 manage_etc_hosts 功能,不要直接修改 /etc/hosts,而是按照上一步的方式修改,且改完要重启后重新查看 /etc/hosts 确认已经修改成功了噢。

1.2 验证 hosts

然后执行 hostname --ip-address 来查看 hosts 是否配置正确,正常应该返回你机器的 ip,如我 ip45.76.157.191

root@vultr:~# hostname --ip-address
45.76.157.191

1.3 网络配置

先通过 ifconfig 查看你机器的主要网卡:

root@vultr:~# ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 45.76.157.191  netmask 255.255.254.0  broadcast 45.76.157.255
        inet6 fe80::5400:4ff:fe94:96a9  prefixlen 64  scopeid 0x20<link>
        inet6 2001:19f0:4400:49aa:5400:4ff:fe94:96a9  prefixlen 64  scopeid 0x0<global>
        ether 56:00:04:94:96:a9  txqueuelen 1000  (Ethernet)
        RX packets 829  bytes 129892 (126.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 853  bytes 274794 (268.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

从返回的信息中看到我的网卡名称是 enp1s0,先查看 vim /etc/network/interfaces 文件,原内容为:

# network interface settings; autogenerated
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto enp0s2
iface enp0s2 inet dhcp

在最后新增两行,其中 enp1s0 为你的网卡地址,注意检查下,如果你这个配置文件已经默认有该配置了,就不用配了:

auto enp1s0
iface enp1s0 inet dhcp

1.4 禁用 cloud-init 网络配置(可选)

如果你的服务器网络不是使用 cloud-init 设置的,请跳过此部分。如果你不清楚,可以通过检查您的服务器上是否存在 /etc/network/interfaces.d/50-cloud-init 文件来验证这一点,有则说明你需要这一步操作。 先执行 vim /etc/cloud/cloud.cfg.d/99-custom-networking.cfg 编辑文件,内容为:

network: {config: disabled}

保存上面的文件后,执行命令 rm -f /etc/network/interfaces.d/50-cloud-init 删除 cloud-init 网络配置文件。

然后 reboot 重启服务器,重启后请再次执行 hostname --ip-address 来查看 hosts 是否配置正确,正常应该返回你机器的 ip

2 安装 PVE

2.1 配置 debian 11 国内镜像源 (可选)

debian 11 默认的镜像源可能是国外的,为了加速软件安装,可配置为国内的,如果你不需要,可跳过这一步。 执行命令 vim /etc/apt/sources.list 编辑文件内容为:

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

2.2 添加 Proxmox VE 存储库

国外环境用:

echo "deb [arch=amd64] http://download.proxmox.com/debian/pve bullseye pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list

国内可用清华源:

echo "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bullseye pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list

2.3 添加 Proxmox VE 存储库密钥

wget https://enterprise.proxmox.com/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg 

然后校验下密钥文件是否正确:

sha512sum /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg 

正常应该返回:

7fb03ec8a1675723d2853b84aa4fdb49a46a3bb72b9951361488bfd19b29aab0a789a4f8c7406e71a69aabbc727c936d3549731c4659ffa1a08f44db8fdcebfa  /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg 

2.4 更新镜像源

apt update -y && apt full-upgrade -y

2.5 安装 Proxmox VE 包

apt install proxmox-ve postfix open-iscsi -y

安装过程如果弹出一个 Postfix Configuration 弹窗,选择 Local Only 回车,然后还有个弹窗会显示你 domain,也直接回车。 安装完后,执行 reboot 重启服务器。重启完就可以通过 https://youripaddress:8006 访问了。 如果访问不了,检查下是不是自带的 ufw 防火墙处于开启状态,需关闭防火墙或开通 8006 端口:

关闭防火墙并禁止开机自启:

systemctl stop ufw
systemctl disable ufw

放行 8006 端口:

ufw allow 8006

3 扩展工作

3.1 移除 os-prober (可选)

pve 官方建议删除 os-prober 软件包: 该 os-prober 软件包会扫描主机的所有分区以创建双引导 GRUB 条目。但扫描的分区还可以包括分配给虚拟机的分区,而虚拟机不希望将其添加为启动项。

简而言之,如果你不需要在服务器上安装双系统,如一个 pve,一个其他系统,您可以安全地删除该 os-prober 软件包 (这不影响在 pve 上开其他系统的 vmlxc):

apt remove os-prober -y;

3.2 配置 CT Template 为清华源 (可选)

如果你需要加速 Proxmox 网页端下载 CT Templates,可以替换 CT Templates 的源。

具体方法:将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com 替换为

https://mirrors.tuna.tsinghua.edu.cn/proxmox

可以使用以下命令一键修改:

cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back
sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm

重启后生效。

3.3 禁用企业源

企业源是要收费的,不禁用掉的话,你 apt update 时会报错:

Err:7 https://enterprise.proxmox.com/debian/pve bullseye InRelease
  401  Unauthorized [IP: 2407:6180:1:a:70dc:f0ff:fe97:4cbb 443]
Reading package lists... Done
E: Failed to fetch https://enterprise.proxmox.com/debian/pve/dists/bullseye/InRelease  401  Unauthorized [IP: 2407:6180:1:a:70dc:f0ff:fe97:4cbb 443]
E: The repository 'https://enterprise.proxmox.com/debian/pve bullseye InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

禁用方式为编辑 /etc/apt/sources.list.d/pve-enterprise.list 文件,注释掉第一行(即在第一行最前面加个 #),修改完执行 apt update 验证下没有上面的那个报错就是禁用成功了。

3.4 屏蔽登录后弹窗

由于我们不是付费的订阅用户,所以 pve 会在登录后弹窗提示:

You do not have a valid subscription for this server. Please visit [www.proxmox.com](https://www.proxmox.com/proxmox-ve/pricing) to get a list of available options.

可通过以下命令屏蔽:

sed -i.bak "s/data.status.toLowerCase() !== 'active'/false/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy

命令含义是编辑 /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 文件替换文件中内容 data.status !== 'Active'false,并将原文件备份为 .bak 后缀,然后重启 pve 服务。

修改完可以重新登录 pve 验证是否还有弹窗,如果还有检查下是不是浏览器缓存,如果还是不行,可能你用的版本不适用这个修改方式,请重新在搜索引擎搜索你所用 pve 版本的去除弹窗方式。

4 开 lxc 容器

4.1 下载 LXC 模板

点击左侧磁盘图标的 local(机器hostname),然后选 CT 模板,点 模板,选择要下载的系统模板,然后下载即可。

4.2 创建 LXC 容器

点击 pve 网页右上角的 创建 CT,按照提示填写即可,网络中:

  • 桥接 选择 vmbr0 网卡
  • IPv4 选择静态
  • IPv4/CIDR:写 10.10.10.100/24,其中 10.10.10.100 是容器 IP 地址。
  • 网关(IPv4):写 10.10.10.1
  • 其他的保持默认即可。

添加完,启动即可。

4.3 添加 ssh 服务并允许 root 登录

启动 lxc 容器后,先使用宿主机 ping 一下,确保可以 ping 通,然后就可以通过控制台连接了,如果控制台连接不上,可点击右上方的选项,使用其他方式的控制台访问,进入到服务器 shell 命令行后输入账号密码登录,接下来执行命令安装 ssh 服务,可远程连接:

如果是 centos,则需要安装 ssh 服务:

yum install openssh-server
systemctl start sshd.service
systemctl enable sshd.service

如果是 debian/ubuntu,默认已安装 ssh,但禁止了 root 用户登录,需开启:

sed -i '/PermitRootLogin /c PermitRootLogin yes' /etc/ssh/sshd_config
systemctl restart sshd