本文最后更新于 683 天前,其中的信息可能已经有所发展或是发生改变。
闲来无事,就来研究一下各种关于虚拟化的知识。目前虚拟化大概可以分为三个种类:半虚拟化、硬件辅助的全虚拟化、OS容器级别的虚拟化。其中:
半虚拟化
硬件辅助的全虚拟化
OS容器级别的虚拟化:
平时我们用来建立虚拟化环境的工具主要有 VMware Workstation, VirtualBox 等,但在服务器这些没有图形化界面的系统上,我们选择使用 Proxmox VE 来建立虚拟化环境,同样的产品还有 VMware ESXi,本文就不再赘述。
https://www.proxmox.com/en/downloads
镜像文件下载后,使用 Rufus 或 UltraISO 将其写入USB驱动。重新启动电脑,在BIOS中选择从USB驱动器启动,按照引导安装即可。具体步骤相关网站有详细图文,本文具体介绍直接安装的方法。
使用此种方式安装需要目标机器上已经预装了64位的 Debian 10 或 Debian 11 系统。
除此之外,还需要在/etc/hosts
中添加本机的ip地址及hostname,例如:
192.168.15.77 server.proxmox.com server
echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list
wget http://download.proxmox.com/debian/proxmox-ve-release-6.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg
对于国内用户,可以使用中科大提供的镜像:
echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list
wget http://mirrors.ustc.edu.cn/proxmox/debian/proxmox-ve-release-6.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg
apt update && apt dist-upgrade
apt install proxmox-ve postfix open-iscsi
apt remove os-prober
安装时可能会跳出类似 A new version of configuration file /etc/*** is available
的问题,我们只需要选择 keep the local version currently installed
保留当前配置文件即可。
在安装 postfix 时,会出现选择框,同理,只需选择local only
即可。
在上面的命令都运行完后,若没有报错,那么说明 Proxmox VE 已经安装完成,但我们还需在此基础上另外配置一下。
我们安装的 Proxmox VE 不需要集群功能,所以可以禁用来节省一部分空间。
systemctl disable pve-ha-lrm pve-ha-crm
注:以下命令均假定物理网卡为 eth0
,eth1
,eth2
...
https://PVE服务器地址:8006/
,使用root账户及密码登陆,语言可以选择中文。对于有多个网卡的情况,我们可以在系统
>网络
>创建
>Linux Bridge
中创建多个虚拟网卡并与物理网卡桥接。
对于只有单个网卡的情况,我们无法为虚拟机分配独立的IP地址,只能使用 NAT 模式:
编辑/etc/network/interfaces
,添加如下代码并保存
auto vmbr0
iface vmbr0 inet static
address 10.0.0.254
netmask 255.255.255.0
bridge-ports none
bridge-stp off
bridge-fd 0
post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth0 -j MASQUERAD
post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o eth0 -j MASQUERADE
其中表示10.0.0.254
为虚拟机的网关地址,10.0.0.1-10.0.0.253
为可分配的IP地址。
运行 systemctl restart networking
使配置生效
在此之后,我们新创建的虚拟机只需要手动为其分配一个范围内的IP地址,并将其网卡桥接到vmbr0
上即可连接网络。
时间有限,后续进阶配置会逐步更新