一、实验准备
1、准备Redhat-rhel7.6的镜像源
mkdir /iso
2、挂载镜像源
mount /iso/rhel-server-7.6-x86_64-dvd.iso /var/www/html/rhel7
永久挂载:
vim /etc/rc.d/rc.local
mount /iso/rhel-server-7.6-x86_64-dvd.iso /var/www/html/rhel7
二、创建虚拟机
1、创建虚拟母机
virt-manager
2、关闭虚拟机相关设定
systemctl disable firewalld ##关闭防火墙
systemctl disable --now NetworkManager ##关闭网络管理器
vim /etc/sysconfig/selinux ##关闭selinux(disabled)
yum install -y vim lftp bash-* net-tools ##下载常用软件服务
3、配置虚拟机网络
vi /etc/sysconfig/network-scripts/ifcfg-eth0
systemctl restart network ##重启网络配置
4、设置域名解析
vi /etc/hosts
5、配置软件仓库
vi dvd.repo
yum repolist ##检测软件仓库搭建成功(需在真机挂载镜像源)
6、封装虚拟机
yum install libguestfs-tools.noarch libguestfs-tools-c.x86_64 -y ##虚拟机磁盘管理工具
rpm -qf /usr/bin/virt-sysprep ##查看安装包
virt-sysprep -d hush ##清理缓存数据
du -sh hush.qcow2 ##查看虚拟机大小
26G的虚拟机占用空间太大,需要对母盘进行封装,清理和压缩磁盘文件
virt-sparsify --compress hush.qcow2 hush-new.qcow2 ##压缩
用清理和压缩之后得到的磁盘文件创建虚拟机快照文件(可删除占用空间大的虚拟机),之后使用导入的方式添加快照文件,得到三或者多台虚拟机,创建完成后,修改各虚拟机的主机名、网卡配置文件
qemu-img create -f qcow2 -b hush-new.qcow2 vm1 ##创建快照虚拟机