可以把创建的vm node及network的xml文件导出来存放,以后可以使用命令创建:
# sudo apt-get install qemu-kvm
# virsh define vm0.xml //导入虚拟机配置
# virsh start vm0 //开启vm0
# virsh list --all // 显示所有虚拟机状态
# virsh destroy vm0 //销毁虚拟机
# virsh undefine vm1 //删除虚拟机配置
# virsh dumpxml vm0 //显示虚拟机xml配置
使用MobaXterm Terminal, 输入virt-manager,会弹出来图形界面
sudo apt-get install virt-manager
virt-manager
如没有权限错误,把用户填进组里:
sudo usermod -aG libvirt $USER sudo usermod -aG kvm $USER
再启动virt-manager
$ sudo apt install net-tools
$ sudo apt-get install openssh-server
$ ifconfig
查看vm
通过ssh连接
ssh [email protected]
ssh [email protected]
(13条消息) 为KVM虚拟机添加网卡,并配置IP_尚先生的博客的博客-CSDN博客_kvm添加网卡
(13条消息) 在virt-manager中桥接虚拟机_岚匀的博客-CSDN博客
创建bridge --- 方法改成创建虚拟网络,会自动创建出bridge: TaskNATSetupVirtManager - Libvirt Wiki
会出来网桥virbr2:
jingh@worker-node53:~$ brctl show
bridge name bridge id STP enabled interfaces
virbr1 8000.525400550801 no virbr1-nic
virbr2 8000.525400e5dd86 yes virbr2-nic
改stp为off:
$ sudo brctl stp virbr2 off
再查看网桥,下挂2个网卡:
jingh@worker-node53:~$ brctl show
bridge name bridge id STP enabled interfaces
virbr2 8000.52540070b876 no virbr2-nic
vnet1
vnet9
但是网卡却没有分ip,不知道为啥?
(14条消息) kvm Libvirt qemu-kvm虚拟主机指定固定IP_风.foxwho的博客-CSDN博客_kvm 指定ip
查看net-jh的bridge:
jingh@worker-node53:~$ sudo cat /etc/libvirt/qemu/networks/net-virbr.xml
net-jh
490610e0-07af-4309-bbc1-a324174f195f
修改此文件,把stp改为off,添加固定的mac-address和ip地址:
virsh --connect qemu:///system dumpxml ubuntu20.04-jingh-dpu | grep 'mac address'
virsh --connect qemu:///system net-edit net-virbr
加入
保存,重启网络
virsh --connect qemu:///system net-destroy net-virbr
virsh --connect qemu:///system net-start net-virbr
最后,重启虚拟机后生效
virsh reboot ubuntu20.04-jingh-dpu
在两个 vm上,DHCP自动分126的ip没生效,不知道为啥。
dpu-node上
sudo ifconfig enp6s0 192.168.126.133 netmask 255.255.255.0
sudo ip link set enp6s0 up
sudo ifconfig enp6s0 promisc
sudo route add default gw 192.168.126.1 dev enp6s0
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:e8:ae:5b brd ff:ff:ff:ff:ff:ff
inet 192.168.122.104/24 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 2487sec preferred_lft 2487sec
inet6 fe80::5054:ff:fee8:ae5b/64 scope link
valid_lft forever preferred_lft forever
3: enp6s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:52:c7:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.126.133/24 brd 192.168.126.255 scope global enp6s0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe52:c76f/64 scope link
valid_lft forever preferred_lft forever
host-node上
sudo ip add add 192.168.126.130/24 dev enp6s0
sudo ip link set enp6s0 up
sudo ifconfig enp6s0 promisc
sudo route add default gw 192.168.126.1 dev enp6s0
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:19:9d:d8 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.224/24 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 2806sec preferred_lft 2806sec
inet6 fe80::5054:ff:fe19:9dd8/64 scope link
valid_lft forever preferred_lft forever
3: enp6s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:e2:18:70 brd ff:ff:ff:ff:ff:ff
inet 192.168.126.130/24 brd 192.168.126.255 scope global enp6s0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee2:1870/64 scope link
valid_lft forever preferred_lft forever
可以ping通
jingh@dpu-node:~$ ping 192.168.126.130
PING 192.168.126.130 (192.168.126.130) 56(84) bytes of data.
64 bytes from 192.168.126.130: icmp_seq=1 ttl=64 time=0.684 ms
64 bytes from 192.168.126.130: icmp_seq=2 ttl=64 time=0.389 ms