注:系统使用Rock8.6
下载链接
通过百度网盘分享的文件:cirros.qcow2,node_base.xml等2个文件
链接:https://pan.baidu.com/s/1hupGQsMjrXMgngCy3lQLhw?pwd= hlr6
提取码:hlr6
[ root@harbor ~]
Rocky Linux release 8.6 ( Green Obsidian)
验证 ecs 是否支持虚拟化
[ root@harbor ~]
vmx
vmx
vmx
vmx
[ root@harbor ~]
kvm_intel 339968 4
kvm 905216 1 kvm_intel
irqbypass 16384 4 kvm
安装虚拟化平台
安装服务
[ root@harbor ~]
[ root@harbor ~]
[ root@harbor ~]
Compiled against library: libvirt 8.0 .0
Using library: libvirt 8.0 .0
Using API: QEMU 8.0 .0
Running hypervisor: QEMU 6.2 .0
创建网桥
命令 描述 virsh net-list [--all] 列出虚拟网络 virsh net-start 启动虚拟交换机 virsh net-destroy 强制停止虚拟交换机 virsh net-define 根据xml文件创建虚拟网络 virsh net-undefine 删除一个虚拟网络设备 virsh net-edit 修改虚拟交换机的配置 virsh net-autostart 设置开机自启动
[ root@harbor ~]
< network>
< name> vbr< /name>
< uuid> 335ef8bf-f349-4194-9b79-687b56df7614 < /uuid>
< forward mode = 'nat' />
< bridge name = 'vbr' stp = 'on' delay = '0' />
< mac address = '52:54:00:14:a2:43' />
< 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>
[ root@harbor ~]
Network vbr defined from /etc/libvirt/qemu/networks/vbr.xml
[ root@harbor ~]
Network vbr marked as autostarted
[ root@harbor ~]
Network vbr started
[ root@harbor ~]
Name State Autostart Persistent
-----------------------------------------
vbr active yes yes
[ root@harbor ~]
vbr: flags = 416 3 < UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168 .100.254 netmask 255.255 .255.0 broadcast 192.168 .100.255
ether 52 :54:00:14:a2:43 txqueuelen 1000 ( Ethernet)
RX packets 27 bytes 2264 ( 2.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15 bytes 1564 ( 1.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Linux 虚拟机
虚拟机的构成
虚拟机配置文件(*.xml)
文件默认路径:/etc/libvirt/qemu/ 用途:定义了虚拟机的设备,如CPU,内存,网卡等资源 存储文件(*.img)
文件默认路径:/var/lib/libvirt/imags/ 用途:仿真虚拟机磁盘,存储所有数据信息
创建虚拟机磁盘
[ root@harbor ~]
[ root@harbor ~]
[ root@harbor ~]
[ root@harbor ~]
虚拟机配置文件
< domain type = ' kvm' >
< name> vmhost</ name>
< memory unit = ' KB' > 1048576</ memory>
< currentMemory unit = ' KB' > 1048576</ currentMemory>
< vcpu placement = ' static' > 2</ vcpu>
< os>
< type arch = ' x86_64' machine = ' pc' > hvm</ type>
< boot dev = ' hd' />
< bootmenu enable = ' yes' />
< bios useserial = ' yes' />
</ os>
< features>
< acpi/>
< apic/>
</ features>
< cpu mode = ' host-passthrough' > </ cpu>
< clock offset = ' localtime' />
< on_poweroff> destroy</ on_poweroff>
< on_reboot> restart</ on_reboot>
< on_crash> restart</ on_crash>
< devices>
< emulator> /usr/libexec/qemu-kvm</ emulator>
< disk type = ' file' device = ' disk' >
< driver name = ' qemu' type = ' qcow2' />
< source file = ' /var/lib/libvirt/images/vmhost.img' />
< target dev = ' vda' bus = ' virtio' />
</ disk>
< interface type = ' bridge' >
< source bridge = ' vbr' />
< model type = ' virtio' />
</ interface>
< channel type = ' unix' >
< target type = ' virtio' name = ' org.qemu.guest_agent.0' />
</ channel>
< serial type = ' pty' > </ serial>
< console type = ' pty' >
< target type = ' serial' />
</ console>
< memballoon model = ' virtio' > </ memballoon>
</ devices>
</ domain>
创建虚拟机
命令 说明 virsh list [--all] 列出虚拟机 virsh start/shutdown 启动/关闭虚拟机 virsh destroy 强制停止虚拟机 virsh define/undefine 创建/删除虚拟机 virsh console 连接虚拟机的 console
[ root@harbor ~]
Domain vmhost defined from /etc/libvirt/qemu/vmhost.xml
[ root@harbor ~]
Id Name State
----------------------------------------------------
- vmhost shut off
[ root@harbor ~]
Domain vmhost started
[ root@harbor ~]
Connected to domain vmhost
Escape character is ^]
login as 'cirros' user. default password: 'gocubsgo' . use 'sudo' for root.
cirros login:
退出使用 ctrl + ]
常用管理命令
命令 说明 virsh edit 修改虚拟机的配置 virsh autostart 设置虚拟机自启动 virsh dominfo 查看虚拟机摘要信息 virsh domiflist 查看虚拟机网卡信息 virsh domblklist 查看虚拟机硬盘信息