1.创建一台虚拟机
验证指令集
- grep -Po "vmx|svm" /proc/cpuinfo
安装虚拟化服务
- dnf install -y qemu-kvm libvirt-daemon libvirt-client libvirt-daemon-driver-qemu libvirt-daemon-driver-network dnsmasq
- systemctl enable --now libvirtd
网桥管理命令
创建虚拟网桥
- vim /etc/libvirt/qemu/networks/vbr.xml
- <network>
- <name>vbr</name>
- <forward mode='nat'/>
- <bridge name='vbr' stp='on' delay='0'/>
- <ip address='192.168.100.254' netmask='255.255.255.0'>
- <dhcp>
- <range start='192.168.100.128' end='192.168.100.200'/>
- </dhcp>
- </ip>
- </network>
创建网桥
- virsh net-define /etc/libvirt/qemu/networks/vbr.xml
设置开机自启动
- virsh net-autostart vbr
启动网桥
- virsh net-start vbr
验证状态
- virsh net-list --all
ifconfig vbr # 验证
克隆磁盘
上传 s4/public 目录下 cirros.qcow2 和 vmbase.xml 到虚拟机中
[root@localhost s4]# rsync -av public/{cirros.qcow2,vmbase.xml} 192.168.88.125:/root/

[root@ecs ~]# cp cirros.qcow2 /var/lib/libvirt/images/
[root@ecs ~]# cd /var/lib/libvirt/images/
[root@ecs ~]# qemu-img create -F qcow2 -f qcow2 -b cirros.qcow2 vmhost.img 20G
[root@ecs ~]# qemu-img info vmhost.img #查看信息
虚拟机配置文件
[root@ecs ~]# vim vmbase.xml
02: <name>vmhost</name> # 必改配置
03: <memory unit="KB">1048576</memory>
04: <currentMemory unit="KB">1048576</currentMemory>
05: <vcpu placement="static">2</vcpu>
25: <source file="/var/lib/libvirt/images/vmhost.img" /> # 必改配置
29: <source bridge="vbr" />
创建虚拟机
[root@ecs ~]# virsh define vmbase.xml
[root@ecs ~]# virsh list --all
Id Name State
----------------------------------------------------
- vmhost shut off
[root@ecs ~]# virsh start vmhost
Domain vmhost started
[root@ecs ~]# virsh console vmhost # 两次回车
Connected to domain vmhost
Escape character is ^]
login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
cirros login:
退出使用 ctrl + ]