Ubuntu22.04安装ovs和配置KVM虚拟化
2024-04-19
1分钟阅读时长
安装OVS
apt install -y openvswitch-switch
验证
ovs-vsctl show
创建名为ovs_br0的网桥
ovs-vsctl add-br ovs_br0
配置网桥ip
这是原有的netplan配置文件
root@master02:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
bonds:
bond0:
addresses:
- 10.11.0.12/24
interfaces:
- ens6f0np0
- ens6f1np1
nameservers:
addresses:
- 114.114.114.114
- 8.8.8.8
search: []
parameters:
lacp-rate: slow
mode: 802.3ad
transmit-hash-policy: layer2
routes:
- to: default
via: 10.11.0.1
ethernets:
ens6f0np0: {}
ens6f1np1: {}
version: 2
我们修改下
network:
version: 2
renderer: networkd
ethernets:
ens6f0np0: {}
ens6f1np1: {}
bonds:
bond0:
interfaces:
- ens6f0np0
- ens6f1np1
parameters:
lacp-rate: slow
mode: 802.3ad
transmit-hash-policy: layer2
bridges:
ovs_br0:
interfaces:
- bond0
addresses:
- 10.11.0.12/24
routes:
- to: default
via: 10.11.0.1
nameservers:
addresses:
- 114.114.114.114
- 8.8.8.8
parameters:
stp: false
forward-delay: 0
然后执行下命令
ovs-vsctl add-port ovs_br0 bond0
netplan apply
执行完第一条命令后会断网,切换至IPMI或物理机 继续执行第二条命令
安装KVM
apt install -y qemu-kvm qemu-system virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils libosinfo-bin libguestfs-tools virt-top virt-viewer
注意,因为jumpserver不能转发X11图形,所以在安装KVM之前,提前安装了ubuntu-desktop 和 xrdp 使用jumpserver支持的RDP协议进行GUI界面的操作
apt install -y ubuntu-desktop xrdp
## 因为桌面版会开启自动休眠模式,所以禁用自动休眠
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
##默认情况下,Xrdp 使用/etc/ssl/private/ssl-cert-snakeoil.key,它仅仅对“ssl-cert” 用户组成语可读。运行下面的命令,将xrdp用户添加到这个用户组:
sudo adduser xrdp ssl-cert
systemctl restart xrdp
启用虚拟化守护进程(libvirtd)
systemctl enable --now libvirtd
systemctl start libvirtd
虚拟机相关配置
新建 /etc/libvirt/qemu/networks/ovs.xml:
<network>
<name>ovs</name>
<forward mode="bridge"/>
<bridge name="ovs_br0"/>
<virtualport type="openvswitch"/>
</network>
将配置文件加到virsh网络中
virsh net-define /etc/libvirt/qemu/networks/ovs.xml
查看
启用ovs虚拟网卡
virsh net-start ovs
虚拟机选择相应网卡
virsh net-list --all