1. 虚拟机技术概述
虚拟机技术允许在物理服务器上运行多个独立的操作系统实例,是学习Linux和测试生产环境的重要工具。常见的虚拟化平台包括VMware Workstation、VirtualBox、KVM等。更多学习教程www.fgedu.net.cn
参考Red Hat Enterprise Linux 10官方文档中的System administration章节
# 检查CPU虚拟化支持
# grep -E ‘vmx|svm’ /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat md_clear arch_capabilities
# 检查KVM模块是否加载
# lsmod | grep kvm
kvm_intel 327680 0
kvm 860160 1 kvm_intel
# 检查虚拟化软件包
# rpm -qa | grep -E ‘virt-manager|qemu-kvm|libvirt’
virt-install-3.2.0-1.el10.noarch
virt-manager-3.2.0-3.el10.noarch
libvirt-7.6.0-1.el10.x86_64
qemu-kvm-6.2.0-5.el10.x86_64
2. VMware虚拟机安装
VMware Workstation是功能强大的桌面虚拟化平台,支持Windows和Linux主机系统。学习交流加群风哥微信: itpux-com
# 下载VMware Workstation安装包
# wget https://download3.vmware.com/software/wkst/file/VMware-Workstation-Full-16.2.3-19376536.x86_64.bundle
# 添加执行权限
# chmod +x VMware-Workstation-Full-16.2.3-19376536.x86_64.bundle
# 安装VMware Workstation
# sudo ./VMware-Workstation-Full-16.2.3-19376536.x86_64.bundle
Extracting VMware Installer…done.
Installing VMware Workstation 16.2.3
Configuring…
[######################################################################] 100%
Installation was successful.
# 验证安装
# vmware –version
VMware Workstation 16.2.3 build-19376536
# 启动VMware Workstation服务
# sudo systemctl start vmware
# sudo systemctl enable vmware
# 检查VMware服务状态
# sudo systemctl status vmware
● vmware.service – LSB: This service starts and stops VMware services
Loaded: loaded (/etc/rc.d/init.d/vmware; generated)
Active: active (exited) since Wed 2026-04-02 10:00:00 CST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 12345 ExecStart=/etc/rc.d/init.d/vmware start (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
Memory: 0B
CGroup: /system.slice/vmware.service
Apr 02 10:00:00 rhel10 systemd[1]: Starting LSB: This service starts and stops VMware services…
Apr 02 10:00:00 rhel10 vmware[12345]: Starting VMware services:
Apr 02 10:00:00 rhel10 vmware[12345]: VMware USB Arbitrator
Apr 02 10:00:00 rhel10 vmware[12345]: VMware Authentication Daemon
Apr 02 10:00:00 rhel10 vmware[12345]: VMware NAT Service
Apr 02 10:00:00 rhel10 vmware[12345]: VMware DHCP Service
Apr 02 10:00:00 rhel10 vmware[12345]: VMware Workstation Server
Apr 02 10:00:00 rhel10 vmware[12345]: Starting VMware services:
Apr 02 10:00:00 rhel10 vmware[12345]: VMware USB Arbitrator
Apr 02 10:00:00 rhel10 vmware[12345]: VMware Authentication Daemon
Apr 02 10:00:00 rhel10 vmware[12345]: VMware NAT Service
Apr 02 10:00:00 rhel10 vmware[12345]: VMware DHCP Service
Apr 02 10:00:00 rhel10 vmware[12345]: VMware Workstation Server
Apr 02 10:00:00 rhel10 systemd[1]: Started LSB: This service starts and stops VMware services.
3. VirtualBox虚拟机安装
VirtualBox是开源免费的虚拟化平台,支持多种主机和客户机操作系统。学习交流加群风哥QQ113257174
# 添加VirtualBox仓库
# sudo dnf config-manager –add-repo=https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
Adding repo from https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch – VirtualBox
baseurl=https://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
# 更新软件包缓存
# sudo dnf makecache
# 安装VirtualBox
# sudo dnf install -y VirtualBox-6.1
Last metadata expiration check: 0:00:01 ago on Wed 02 Apr 2026 10:00:00 AM CST.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
VirtualBox-6.1 x86_64 6.1.34-150696.el10 virtualbox 105 M
Installing dependencies:
dkms noarch 3.0.12-1.el10 ol10_baseos_latest 280 k
libvpx x86_64 1.7.0-3.el10 ol10_baseos_latest 1.1 M
python3 x86_64 3.9.7-1.el10 ol10_baseos_latest 33 k
python3-libs x86_64 3.9.7-1.el10 ol10_baseos_latest 7.8 M
qt5-qtbase x86_64 5.15.2-3.el10 ol10_appstream 7.0 M
qt5-qtbase-gui x86_64 5.15.2-3.el10 ol10_appstream 1.1 M
qt5-qtx11extras x86_64 5.15.2-1.el10 ol10_appstream 44 k
qt5-qtxml x86_64 5.15.2-1.el10 ol10_appstream 246 k
Transaction Summary
================================================================================
Install 9 Packages
Total download size: 123 M
Installed size: 456 M
Is this ok [y/N]: y
Downloading Packages:
[============================] 100% – 105 MB/s | 105 MB 00:00:00 ETA
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/9
Installing : python3-libs-3.9.7-1.el10.x86_64 1/9
Installing : python3-3.9.7-1.el10.x86_64 2/9
Installing : qt5-qtxml-5.15.2-1.el10.x86_64 3/9
Installing : qt5-qtbase-5.15.2-3.el10.x86_64 4/9
Installing : qt5-qtbase-gui-5.15.2-3.el10.x86_64 5/9
Installing : qt5-qtx11extras-5.15.2-1.el10.x86_64 6/9
Installing : libvpx-1.7.0-3.el10.x86_64 7/9
Installing : dkms-3.0.12-1.el10.noarch 8/9
Installing : VirtualBox-6.1-6.1.34-150696.el10.x86_64 9/9
Running scriptlet: VirtualBox-6.1-6.1.34-150696.el10.x86_64 9/9
Verifying : python3-libs-3.9.7-1.el10.x86_64 1/9
Verifying : python3-3.9.7-1.el10.x86_64 2/9
Verifying : qt5-qtxml-5.15.2-1.el10.x86_64 3/9
Verifying : qt5-qtbase-5.15.2-3.el10.x86_64 4/9
Verifying : qt5-qtbase-gui-5.15.2-3.el10.x86_64 5/9
Verifying : qt5-qtx11extras-5.15.2-1.el10.x86_64 6/9
Verifying : libvpx-1.7.0-3.el10.x86_64 7/9
Verifying : dkms-3.0.12-1.el10.noarch 8/9
Verifying : VirtualBox-6.1-6.1.34-150696.el10.x86_64 9/9
Installed:
VirtualBox-6.1-6.1.34-150696.el10.x86_64
dkms-3.0.12-1.el10.noarch
libvpx-1.7.0-3.el10.x86_64
python3-3.9.7-1.el10.x86_64
python3-libs-3.9.7-1.el10.x86_64
qt5-qtbase-5.15.2-3.el10.x86_64
qt5-qtbase-gui-5.15.2-3.el10.x86_64
qt5-qtx11extras-5.15.2-1.el10.x86_64
qt5-qtxml-5.15.2-1.el10.x86_64
Complete!
# 验证安装
# VBoxManage –version
6.1.34r150696
# 将当前用户添加到vboxusers组
# sudo usermod -aG vboxusers $USER
# 重新登录以使组权限生效
# newgrp vboxusers
# 启动VirtualBox服务
# sudo systemctl start vboxdrv
# sudo systemctl enable vboxdrv
# 检查VirtualBox服务状态
# sudo systemctl status vboxdrv
● vboxdrv.service – VirtualBox Linux kernel module
Loaded: loaded (/usr/lib/systemd/system/vboxdrv.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2026-04-02 10:00:00 CST; 5s ago
Docs: https://www.virtualbox.org/manual/UserManual.html
Process: 12345 ExecStart=/sbin/vboxconfig (code=exited, status=0/SUCCESS)
Main PID: 12345 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
Memory: 0B
CGroup: /system.slice/vboxdrv.service
Apr 02 10:00:00 rhel10 systemd[1]: Starting VirtualBox Linux kernel module…
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: Starting VirtualBox services.
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: Building VirtualBox kernel modules.
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: This system is currently not set up to build kernel modules.
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: Please install Linux kernel headers package for your current kernel:
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: sudo dnf install kernel-devel kernel-headers
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: This system is using UEFI Secure Boot technology which requires that vboxdrv kernel module be signed.
Apr 02 10:00:00 rhel10 vboxconfig[12345]: vboxdrv.sh: Please read the file /usr/share/doc/virtualbox/README.linux for more information.
# 安装内核开发包
# sudo dnf install -y kernel-devel kernel-headers
# 重新启动VirtualBox服务
# sudo systemctl restart vboxdrv
4. 虚拟机创建步骤
使用VirtualBox创建虚拟机的详细步骤,包括硬件配置、存储配置和网络配置。 from LinuxDBA视频:www.itpux.com
# 创建虚拟机
# VBoxManage createvm –name “RHEL10-Learning” –register
Virtual machine ‘RHEL10-Learning’ is created and registered.
UUID: 12345678-1234-1234-1234-123456789012
Settings file: ‘/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vbox’
# 设置虚拟机类型和版本
# VBoxManage modifyvm “RHEL10-Learning” –ostype RedHat_64
# 设置内存大小(4GB)
# VBoxManage modifyvm “RHEL10-Learning” –memory 4096
# 设置虚拟CPU数量(2核)
# VBoxManage modifyvm “RHEL10-Learning” –cpus 2
# 启用硬件虚拟化
# VBoxManage modifyvm “RHEL10-Learning” –hwvirtex on
# VBoxManage modifyvm “RHEL10-Learning” –nestedpaging on
# VBoxManage modifyvm “RHEL10-Learning” –largepages on
# 创建虚拟硬盘(50GB动态分配)
# VBoxManage createhd –filename “/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vdi” –size 51200 –format VDI –variant Standard
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium created. UUID: 12345678-1234-1234-1234-123456789012
# 创建SATA控制器
# VBoxManage storagectl “RHEL10-Learning” –name “SATA Controller” –add sata –controller IntelAHCI
# 将虚拟硬盘附加到SATA控制器
# VBoxManage storageattach “RHEL10-Learning” –storagectl “SATA Controller” –port 0 –device 0 –type hdd –medium “/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vdi”
# 创建IDE控制器(用于安装介质)
# VBoxManage storagectl “RHEL10-Learning” –name “IDE Controller” –add ide
# 附加RHEL 10 ISO镜像
# VBoxManage storageattach “RHEL10-Learning” –storagectl “IDE Controller” –port 0 –device 0 –type dvddrive –medium “/path/to/rhel-10.0-x86_64-dvd.iso”
# 启用网络适配器(NAT模式)
# VBoxManage modifyvm “RHEL10-Learning” –nic1 nat
# 设置虚拟机描述
# VBoxManage modifyvm “RHEL10-Learning” –description “RHEL 10 Learning Environment”
# 显示虚拟机信息
# VBoxManage showvminfo “RHEL10-Learning”
Name: RHEL10-Learning
Groups: /
Guest OS: Red Hat (64-bit)
UUID: 12345678-1234-1234-1234-123456789012
Config file: /home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vbox
Memory size: 4096MB
Number of CPUs: 2
Hardware virtualization: enabled
Nested paging: enabled
Large pages: enabled
Storage Controller Name (0): SATA Controller
Storage Controller Type (0): IntelAHCI
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0): 30
Storage Controller Port Count (0): 30
Storage Controller Bootable (0): on
SATA Controller (0, 0): /home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vdi (UUID: 12345678-1234-1234-1234-123456789012)
Storage Controller Name (1): IDE Controller
Storage Controller Type (1): PIIX4
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1): 2
Storage Controller Port Count (1): 2
Storage Controller Bootable (1): on
IDE Controller (1, 0): /path/to/rhel-10.0-x86_64-dvd.iso (UUID: 12345678-1234-1234-1234-123456789012)
NIC 1: MAC: 080027123456, Attachment: NAT, Cable connected: on
NIC 2: disabled
NIC 3: disabled
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
USB: disabled
Audio: disabled
Clipboard: disabled
Drag&Drop: disabled
# VBoxManage startvm “RHEL10-Learning” –type gui
# 以无头模式启动虚拟机(用于服务器环境)
# VBoxManage startvm “RHEL10-Learning” –type headless
# 停止虚拟机
# VBoxManage controlvm “RHEL10-Learning” poweroff
# 暂停虚拟机
# VBoxManage controlvm “RHEL10-Learning” pause
# 恢复虚拟机
# VBoxManage controlvm “RHEL10-Learning” resume
# 重启虚拟机
# VBoxManage controlvm “RHEL10-Learning” reset
# 删除虚拟机
# VBoxManage unregistervm “RHEL10-Learning” –delete
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
5. 硬件配置优化
根据虚拟机的用途和物理主机的资源,合理配置虚拟机硬件可以提高性能和稳定性。
# 设置虚拟CPU数量
# VBoxManage modifyvm “RHEL10-Learning” –cpus 4
# 设置CPU执行上限(100%表示完全使用物理CPU)
# VBoxManage modifyvm “RHEL10-Learning” –cpuexecutioncap 80
# 启用PAE/NX(物理地址扩展)
# VBoxManage modifyvm “RHEL10-Learning” –pae on
# 内存配置优化
# 设置内存大小(建议为物理内存的20-30%)
# VBoxManage modifyvm “RHEL10-Learning” –memory 8192
# 启用嵌套分页(提高内存性能)
# VBoxManage modifyvm “RHEL10-Learning” –nestedpaging on
# 启用大页(提高内存性能)
# VBoxManage modifyvm “RHEL10-Learning” –largepages on
# 图形配置优化
# 设置显存大小
# VBoxManage modifyvm “RHEL10-Learning” –vram 128
# 启用3D加速
# VBoxManage modifyvm “RHEL10-Learning” –accelerate3d on
# 设置图形控制器
# VBoxManage modifyvm “RHEL10-Learning” –graphicscontroller vboxsvga
# 存储配置优化
# 启用I/O APIC(提高存储性能)
# VBoxManage modifyvm “RHEL10-Learning” –ioapic on
# 设置系统主板芯片组
# VBoxManage modifyvm “RHEL10-Learning” –chipset ich9
# 启用EFI固件(替代传统BIOS)
# VBoxManage modifyvm “RHEL10-Learning” –firmware efi
# 时钟配置优化
# 启用UTC时钟
# VBoxManage modifyvm “RHEL10-Learning” –rtcuseutc on
# 网络配置优化
# 启用网络适配器
# VBoxManage modifyvm “RHEL10-Learning” –nic1 bridged
# 设置桥接网络接口
# VBoxManage modifyvm “RHEL10-Learning” –bridgeadapter1 enp0s3
# 启用混杂模式
# VBoxManage modifyvm “RHEL10-Learning” –nicpromisc1 allow-all
# USB配置优化
# 启用USB控制器
# VBoxManage modifyvm “RHEL10-Learning” –usb on
# 启用USB 2.0控制器
# VBoxManage modifyvm “RHEL10-Learning” –usbehci on
# 启用USB 3.0控制器
# VBoxManage modifyvm “RHEL10-Learning” –usbxhci on
# 共享文件夹配置
# 添加共享文件夹
# VBoxManage sharedfolder add “RHEL10-Learning” –name “shared” –hostpath “/home/user/shared” –automount
# 显示共享文件夹列表
# VBoxManage showvminfo “RHEL10-Learning” | grep -i shared
Shared Folders:
Name: ‘shared’, Host path: ‘/home/user/shared’ (machine mapping), Transient: no, Auto-mount: yes
# VBoxManage showvminfo “RHEL10-Learning” –machinereadable
name=”RHEL10-Learning”
groups=”/”
ostype=”RedHat_64″
UUID=”12345678-1234-1234-1234-123456789012″
CfgFile=”/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vbox”
SnapFolder=”/home/user/VirtualBox VMs/RHEL10-Learning/Snapshots”
hardwareuuid=”12345678-1234-1234-1234-123456789012″
memory=8192
vram=128
cpus=4
cpuexecutioncap=80
hpet=off
synthcpu=off
cpu-profile=”host”
hwvirtex=on
nestedpaging=on
largepages=on
vtxvpid=on
vtxux=on
pae=on
longmode=on
triplefaultreset=off
guestmemoryballoon=0
pagefusion=off
accelerate3d=on
accelerate2dvideo=off
firmware=efi
chipset=ich9
bioslogofadein=off
bioslogofadeout=off
bioslogodisplaytime=0
biossystemtimeoffset=0
rtcuseutc=on
monitorcount=1
graphicscontroller=vboxsvga
videocapable=on
nic1=bridged
nictype1=82540EM
nicspeed1=0
cableconnected1=on
nic1bridged=enp0s3
nic2=none
nic3=none
nic4=none
nic5=none
nic6=none
nic7=none
nic8=none
usb=on
usbehci=on
usbxhci=on
6. 存储配置
虚拟机存储配置包括虚拟硬盘创建、存储控制器配置和存储优化等。 更多视频教程www.fgedu.net.cn
# 固定大小虚拟硬盘(性能更好,但占用空间大)
# VBoxManage createhd –filename “/home/user/VirtualBox VMs/RHEL10-Learning/disk_fixed.vdi” –size 51200 –format VDI –variant Fixed
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium created. UUID: 12345678-1234-1234-1234-123456789012
# 动态分配虚拟硬盘(节省空间,但性能略差)
# VBoxManage createhd –filename “/home/user/VirtualBox VMs/RHEL10-Learning/disk_dynamic.vdi” –size 51200 –format VDI –variant Standard
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium created. UUID: 12345678-1234-1234-1234-123456789012
# 创建VMDK格式虚拟硬盘(VMware兼容)
# VBoxManage createhd –filename “/home/user/VirtualBox VMs/RHEL10-Learning/disk.vmdk” –size 51200 –format VMDK –variant Standard
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium created. UUID: 12345678-1234-1234-123456789012
# 创建VHD格式虚拟硬盘(Hyper-V兼容)
# VBoxManage createhd –filename “/home/user/VirtualBox VMs/RHEL10-Learning/disk.vhd” –size 51200 –format VHD –variant Standard
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium created. UUID: 12345678-1234-1234-123456789012
# 查看虚拟硬盘信息
# VBoxManage showmediuminfo disk “/home/user/VirtualBox VMs/RHEL10-Learning/disk_fixed.vdi”
UUID: 12345678-1234-1234-1234-123456789012
Parent UUID: base
State: created
Type: normal (base)
Location: /home/user/VirtualBox VMs/RHEL10-Learning/disk_fixed.vdi
Storage format: VDI
Format variant: fixed
Capacity: 51200 MBytes
Encryption: disabled
# 调整虚拟硬盘大小
# VBoxManage modifymedium disk “/home/user/VirtualBox VMs/RHEL10-Learning/disk_dynamic.vdi” –resize 102400
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Medium has been resized successfully.
# 压缩动态分配的虚拟硬盘
# VBoxManage modifymedium disk “/home/user/VirtualBox VMs/RHEL10-Learning/disk_dynamic.vdi” –compact
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
# 创建SATA控制器(推荐用于数据盘)
# VBoxManage storagectl “RHEL10-Learning” –name “SATA Controller” –add sata –controller IntelAHCI –portcount 30
# 创建SAS控制器(用于企业级存储)
# VBoxManage storagectl “RHEL10-Learning” –name “SAS Controller” –add sas –controller LsiLogicSas
# 创建NVMe控制器(高性能存储)
# VBoxManage storagectl “RHEL10-Learning” –name “NVMe Controller” –add pcie –controller NVMe
# 附加虚拟硬盘到控制器
# VBoxManage storageattach “RHEL10-Learning” –storagectl “SATA Controller” –port 0 –device 0 –type hdd –medium “/home/user/VirtualBox VMs/RHEL10-Learning/disk_fixed.vdi”
# 附加多个虚拟硬盘
# VBoxManage storageattach “RHEL10-Learning” –storagectl “SATA Controller” –port 1 –device 0 –type hdd –medium “/home/user/VirtualBox VMs/RHEL10-Learning/disk_dynamic.vdi”
# VBoxManage storageattach “RHEL10-Learning” –storagectl “SATA Controller” –port 2 –device 0 –type hdd –medium “/home/user/VirtualBox VMs/RHEL10-Learning/disk.vmdk”
# 分离虚拟硬盘
# VBoxManage storageattach “RHEL10-Learning” –storagectl “SATA Controller” –port 2 –device 0 –type hdd –medium none
# 删除虚拟硬盘
# VBoxManage closemedium disk “/home/user/VirtualBox VMs/RHEL10-Learning/disk.vmdk” –delete
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
# 克隆虚拟硬盘
# VBoxManage clonemedium disk “/home/user/VirtualBox VMs/RHEL10-Learning/disk_fixed.vdi” “/home/user/VirtualBox VMs/RHEL10-Learning/disk_clone.vdi”
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Clone medium created in format ‘VDI’. UUID: 12345678-1234-1234-1234-123456789012
7. 网络配置
虚拟机网络配置包括NAT、桥接、仅主机等模式,根据不同的使用场景选择合适的网络模式。
# VBoxManage modifyvm “RHEL10-Learning” –nic1 nat
# 配置NAT端口转发(允许外网访问虚拟机服务)
# VBoxManage modifyvm “RHEL10-Learning” –natpf1 “ssh,tcp,,2222,,22”
# VBoxManage modifyvm “RHEL10-Learning” –natpf1 “http,tcp,,8080,,80”
# VBoxManage modifyvm “RHEL10-Learning” –natpf1 “https,tcp,,8443,,443”
# 查看NAT端口转发规则
# VBoxManage showvminfo “RHEL10-Learning” | grep -i natpf
NIC 1 Rule(0): name = ssh, protocol = tcp, host ip = , host port = 2222, guest ip = , guest port = 22
NIC 1 Rule(1): name = http, protocol = tcp, host ip = , host ip = , host port = 8080, guest ip = , guest port = 80
NIC 1 Rule(2): name = https, protocol = tcp, host ip = , host ip = , host port = 8443, guest ip = , guest port = 443
# 删除NAT端口转发规则
# VBoxManage modifyvm “RHEL10-Learning” –natpf1 delete ssh
# 桥接模式(虚拟机与物理机在同一网络,可以互相访问)
# VBoxManage modifyvm “RHEL10-Learning” –nic1 bridged
# VBoxManage modifyvm “RHEL10-Learning” –bridgeadapter1 enp0s3
# 查看可用的网络接口
# VBoxManage list bridgedifs
Name: enp0s3
GUID: 12345678-1234-1234-1234-123456789012
DHCP: enabled
IPAddress: 192.168.1.100
NetworkMask: 255.255.255.0
IPV6Address: fe80::1234:5678:90ab:cdef
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 00:11:22:33:44:55
MediumType: Ethernet
Status: Up
VBoxNetworkName: HostInterfaceNetworking-enp0s3
# 仅主机模式(虚拟机只能与物理机通信,无法访问外网)
# VBoxManage modifyvm “RHEL10-Learning” –nic1 hostonly
# VBoxManage modifyvm “RHEL10-Learning” –hostonlyadapter1 vboxnet0
# 查看仅主机网络
# VBoxManage list hostonlyifs
Name: vboxnet0
GUID: 12345678-1234-1234-1234-123456789012
DHCP: disabled
IPAddress: 192.168.56.1
NetworkMask: 255.255.255.0
IPV6Address: fe80::1234:5678:90ab:cdef
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 0a:00:27:00:00:00
MediumType: Ethernet
Status: Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
# 创建仅主机网络
# VBoxManage hostonlyif create
Interface ‘vboxnet1’ was successfully created
# 配置仅主机网络
# VBoxManage hostonlyif ipconfig vboxnet1 –ip 192.168.57.1 –netmask 255.255.255.0
# 启用DHCP服务器
# VBoxManage dhcpserver add –ifname vboxnet1 –ip 192.168.57.100 –netmask 255.255.255.0 –lowerip 192.168.57.101 –upperip 192.168.57.200
# 查看DHCP服务器配置
# VBoxManage dhcpserver show –ifname vboxnet1
NetworkName: HostInterfaceNetworking-vboxnet1
IP: 192.168.57.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.57.101
upperIPAddress: 192.168.57.200
Enabled: Yes
# VBoxManage modifyvm “RHEL10-Learning” –nic1 intnet
# VBoxManage modifyvm “RHEL10-Learning” –intnet1 “internal_network”
# 配置第二个网络适配器
# VBoxManage modifyvm “RHEL10-Learning” –nic2 nat
# 配置第三个网络适配器
# VBoxManage modifyvm “RHEL10-Learning” –nic3 bridged
# VBoxManage modifyvm “RHEL10-Learning” –bridgeadapter3 enp0s3
# 查看虚拟机网络配置
# VBoxManage showvminfo “RHEL10-Learning” | grep -i nic
NIC 1: MAC: 080027123456, Attachment: NAT, Cable connected: on
NIC 2: MAC: 080027123457, Attachment: Bridged Interface ‘enp0s3’, Cable connected: on
NIC 3: MAC: 080027123458, Attachment: Bridged Interface ‘enp0s3’, Cable connected: on
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
# 禁用网络适配器
# VBoxManage modifyvm “RHEL10-Learning” –nic3 none
# 启用混杂模式(用于网络监控)
# VBoxManage modifyvm “RHEL10-Learning” –nicpromisc1 allow-all
# 设置网络适配器类型
# VBoxManage modifyvm “RHEL10-Learning” –nictype1 82540EM
# VBoxManage modifyvm “RHEL10-Learning” –nictype1 82543GC
# VBoxManage modifyvm “RHEL10-Learning” –nictype1 82545EM
# VBoxManage modifyvm “RHEL10-Learning” –nictype1 virtio
# 设置网络带宽限制(单位:Kbps)
# VBoxManage modifyvm “RHEL10-Learning” –nicspeed1 100000
8. 操作系统安装
在虚拟机中安装RHEL 10操作系统的详细步骤和注意事项。
# VBoxManage storageattach “RHEL10-Learning” –storagectl “IDE Controller” –port 0 –device 0 –type dvddrive –medium “/path/to/rhel-10.0-x86_64-dvd.iso”
# 启动虚拟机
# VBoxManage startvm “RHEL10-Learning” –type gui
# 在虚拟机中执行以下安装步骤:
# 1. 选择”Install Red Hat Enterprise Linux 10″
# 2. 选择语言(English或简体中文)
# 3. 配置安装摘要:
# – DATE & TIME: Asia/Shanghai
# – KEYBOARD: US English
# – LANGUAGE SUPPORT: English (United States)
# – INSTALLATION SOURCE: Local media (ISO)
# – SOFTWARE SELECTION: Server with GUI
# – INSTALLATION DESTINATION:
# * 选择虚拟硬盘
# * 选择”Automatically configure partitioning”
# * 或选择”I will configure partitioning”进行手动分区
# – NETWORK & HOSTNAME:
# * 启用网络连接
# * 设置主机名为rhel10-learning
# – SECURITY POLICY: Default
# – KDUMP: Enable kdump(可选)
# – ROOT PASSWORD: 设置root密码
# – USER CREATION: 创建普通用户
# 4. 开始安装
# 5. 安装完成后重启系统
# 安装完成后,弹出ISO镜像
# VBoxManage storageattach “RHEL10-Learning” –storagectl “IDE Controller” –port 0 –device 0 –type dvddrive –medium none
# 重启虚拟机
# VBoxManage controlvm “RHEL10-Learning” reset
# 查看虚拟机状态
# VBoxManage showvminfo “RHEL10-Learning” | grep State
State: running (since 2026-04-02T10:00:00.000000000)
# 登录到虚拟机后执行:
# 查看系统版本
# cat /etc/redhat-release
Red Hat Enterprise Linux release 10.0 (Plow)
# 查看内核版本
# uname -r
5.14.0-123.el10.x86_64
# 查看主机名
# hostname
rhel10-learning
# 查看网络配置
# ip addr show
1: lo:
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
2: enp0s3:
link/ether 08:00:27:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 86399sec preferred_lft 86399sec
inet6 fe80::a00:27ff:fe12:3456/64 scope link
valid_lft forever preferred_lft forever
# 查看磁盘分区
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 49.5G 0 part
├─rhel-root 253:0 0 40G 0 lvm /
├─rhel-swap 253:1 0 4G 0 lvm [SWAP]
└─rhel-home 253:2 0 5.5G 0 lvm /home
# 查看内存信息
# free -h
total used free shared buff/cache available
Mem: 7.8Gi 1.2Gi 5.6Gi 123Mi 1.0Gi 6.2Gi
Swap: 4.0Gi 0B 4.0Gi
# 查看CPU信息
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Stepping: 3
CPU MHz: 4000.000
BogoMIPS: 8000.00
Virtualization: VT-x
L1d cache: 32 KiB
L1i cache: 32 KiB
L2 cache: 256 KiB
L3 cache: 8192 KiB
9. 安装后配置
操作系统安装完成后,需要进行一系列配置优化,使虚拟机更适合学习和测试使用。
# 在虚拟机中执行:
# 安装依赖包
# sudo dnf install -y gcc make perl kernel-devel kernel-headers
# 挂载增强工具ISO(在VirtualBox菜单中选择:设备 -> 安装增强功能)
# sudo mkdir -p /mnt/cdrom
# sudo mount /dev/sr0 /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
# 安装增强工具
# cd /mnt/cdrom
# sudo ./VBoxLinuxAdditions.run
Verifying archive integrity… All good.
Uncompressing VirtualBox 6.1.34 Guest Additions for Linux…
VirtualBox Guest Additions installer
Copying additional installer modules …
Installing additional modules …
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for the currently running
kernel, the headers for the running kernel need to be installed.
VirtualBox Guest Additions: Building the modules for kernel 5.14.0-123.el10.x86_64.
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
# 重启虚拟机
# sudo reboot
# 重启后验证增强工具安装
# lsmod | grep vboxguest
vboxguest 327680 2
vboxsf 40960 1
vboxvideo 24576 0
# 配置共享文件夹
# 在VirtualBox菜单中选择:设备 -> 共享文件夹 -> 共享文件夹设置
# 添加共享文件夹:主机路径 /home/user/shared,挂载点 /mnt/shared,自动挂载
# 在虚拟机中挂载共享文件夹
# sudo mkdir -p /mnt/shared
# sudo mount -t vboxsf shared /mnt/shared
# 验证共享文件夹
# ls -la /mnt/shared
total 4
drwxrwxrwx 1 root root 4096 Apr 2 10:00:00 .
drwxr-xr-x 1 root root 4096 Apr 2 10:00:00 ..
-rw-r–r– 1 user user 123 Apr 2 10:00:00 test.txt
# 配置自动挂载共享文件夹
# echo “shared /mnt/shared vboxsf defaults 0 0” | sudo tee -a /etc/fstab
shared /mnt/shared vboxsf defaults 0 0
# 1. 禁用SELinux(学习环境)
# sudo vi /etc/selinux/config
SELINUX=disabled
# 2. 禁用防火墙(学习环境)
# sudo systemctl stop firewalld
# sudo systemctl disable firewalld
# 3. 配置YUM源
# sudo dnf install -y epel-release
# sudo dnf makecache
# 4. 安装常用工具
# sudo dnf install -y vim wget curl git net-tools telnet nc lsof strace tcpdump htop iotop sysstat
# 5. 配置时间同步
# sudo dnf install -y chrony
# sudo systemctl start chronyd
# sudo systemctl enable chronyd
# sudo timedatectl set-timezone Asia/Shanghai
# 6. 配置SSH
# sudo vi /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
# sudo systemctl restart sshd
# sudo systemctl enable sshd
# 7. 配置主机名
# sudo hostnamectl set-hostname rhel10-learning
# 8. 配置hosts文件
# sudo vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.101 rhel10-learning
# 9. 配置DNS
# sudo vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
# 10. 更新系统
# sudo dnf update -y
10. 生产环境最佳实践
在生产环境中使用虚拟机时,需要遵循最佳实践,确保系统的稳定性、安全性和可维护性。
# 创建快照(安装完成后)
# VBoxManage snapshot “RHEL10-Learning” take “base_install” –description “Base installation with RHEL 10”
# 创建快照(配置完成后)
# VBoxManage snapshot “RHEL10-Learning” take “after_config” –description “After system configuration”
# 查看快照列表
# VBoxManage snapshot “RHEL10-Learning” list
Current machine state (as of 2026-04-02 10:00:00 UTC):
Name: after_config (UUID: 12345678-1234-1234-1234-123456789012) *
Description: After system configuration
Name: base_install (UUID: 12345678-1234-1234-1234-123456789013)
Description: Base installation with RHEL 10
# 恢复快照
# VBoxManage snapshot “RHEL10-Learning” restore “base_install”
Restoring snapshot 12345678-1234-1234-1234-123456789013
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
# 删除快照
# VBoxManage snapshot “RHEL10-Learning” delete “after_config”
# 2. 虚拟机克隆
# 完整克隆(创建独立的虚拟机)
# VBoxManage clonevm “RHEL10-Learning” –name “RHEL10-Clone1” –register
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Clone medium created in format ‘VDI’. UUID: 12345678-1234-1234-1234-123456789012
# 链接克隆(节省空间,但依赖原始虚拟机)
# VBoxManage clonevm “RHEL10-Learning” –name “RHEL10-LinkedClone1” –options link –register
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
# 3. 虚拟机导出和导入
# 导出虚拟机(OVA格式)
# VBoxManage export “RHEL10-Learning” –output /backup/RHEL10-Learning.ova
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Successfully exported 1 machine(s) to: /backup/RHEL10-Learning.ova
# 导入虚拟机
# VBoxManage import /backup/RHEL10-Learning.ova
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Successfully imported the appliance.
# 4. 虚拟机备份
# 备份虚拟机配置文件
# cp “/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vbox” /backup/RHEL10-Learning.vbox.backup
# 备份虚拟硬盘
# VBoxManage clonehd “/home/user/VirtualBox VMs/RHEL10-Learning/RHEL10-Learning.vdi” /backup/RHEL10-Learning.vdi
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
# 查看虚拟机性能统计
# VBoxManage metrics collect “RHEL10-Learning”
Name,Value,Unit
CPU/Load/User,12.345,%
CPU/Load/Kernel,1.234,%
CPU/MHz,4000,MHz
RAM/Usage/Used,1234567890,Bytes
RAM/Usage/Free,6789012345,Bytes
Net/Rate/Rx,12345,Bytes/s
Net/Rate/Tx,6789,Bytes/s
Disk/Rate/Read,123456,Bytes/s
Disk/Rate/Write,78901,Bytes/s
# 设置性能监控间隔
# VBoxManage metrics setup –period 5 –samples 60 “RHEL10-Learning”
# 6. 虚拟机自动启动
# 设置虚拟机自动启动
# VBoxManage modifyvm “RHEL10-Learning” –autostart-enabled on
# 查看自动启动虚拟机列表
# VBoxManage list vms | grep -i autostart
# 7. 虚拟机资源限制
# 设置CPU使用上限
# VBoxManage modifyvm “RHEL10-Learning” –cpuexecutioncap 50
# 设置内存上限
# VBoxManage modifyvm “RHEL10-Learning” –memory 4096
# 设置磁盘I/O限制
# VBoxManage bandwidthctl “RHEL10-Learning” add DiskLimit –type disk –limit 50M
# 8. 虚拟机日志配置
# 启用虚拟机日志
# VBoxManage modifyvm “RHEL10-Learning” –loghistorycount 10
# 查看虚拟机日志
# VBoxManage showvminfo “RHEL10-Learning” | grep -i log
Log folder: /home/user/VirtualBox VMs/RHEL10-Learning/Logs
# 9. 虚拟机安全配置
# 启用虚拟机加密
# VBoxManage encryptvm “RHEL10-Learning” –newpassword “strong_password”
Encryption algorithm: AES-XTS256-PLAIN64
Encryption key size: 256
Encryption salt: 1234567890ABCDEF1234567890ABCDEF
# 禁用不必要的设备
# VBoxManage modifyvm “RHEL10-Learning” –usb off
# VBoxManage modifyvm “RHEL10-Learning” –audio none
# 10. 虚拟机维护脚本
# 创建虚拟机维护脚本
# cat > /fgedu/shell/vm_maintenance.sh << 'EOF'
#!/bin/bash
# 虚拟机维护脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
VM_NAME="RHEL10-Learning"
BACKUP_DIR="/backup/vm"
LOG_FILE="/var/log/vm_maintenance.log"
echo "[$(date)] Starting VM maintenance" >> $LOG_FILE
# 创建快照
echo “[$(date)] Creating snapshot” >> $LOG_FILE
VBoxManage snapshot “$VM_NAME” take “maintenance_$(date +%Y%m%d)” –description “Maintenance snapshot” >> $LOG_FILE 2>&1
# 备份配置文件
echo “[$(date)] Backing up configuration” >> $LOG_FILE
cp “/home/user/VirtualBox VMs/$VM_NAME/$VM_NAME.vbox” “$BACKUP_DIR/$VM_NAME.vbox.backup.$(date +%Y%m%d)” >> $LOG_FILE 2>&1
# 清理日志
echo “[$(date)] Cleaning logs” >> $LOG_FILE
find “/home/user/VirtualBox VMs/$VM_NAME/Logs” -name “*.log” -mtime +7 -delete >> $LOG_FILE 2>&1
echo “[$(date)] VM maintenance completed” >> $LOG_FILE
EOF
# 添加执行权限
# chmod +x /fgedu/shell/vm_maintenance.sh
# 定期执行维护
# echo “0 3 * * 0 /fgedu/shell/vm_maintenance.sh” >> /etc/crontab
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
