快建新虚拟机的基本思路: 提前准备好一台模板虚拟机(镜像磁盘+xml配置文件) 基于qcow2磁盘复用技术快建新虚拟机的磁盘 通过调整模板机的配置快建新虚拟机的xml配置文件 导入新虚拟机
Copy On Write,写时复制技术原理: 直接映射原始盘的数据内容 当原始盘有修改时,在修改之前将旧数据存入前端盘 对前端盘的修改不会回写到原始盘
找一台已经装好RHEL7系统、配置好本地yum源、关闭SELinux的虚拟机,提取模板虚拟机磁盘、xml配置文件备用。
1.准备磁盘目录、模板虚拟机磁盘文件
[root@kvmsvr ~]# qemu-img info /data/images/rhel7_muban.qcow2
image:
/data/images/rhel7_muban.qcow2
file format: qcow2
virtual size:
300G
(322122547200 bytes)
//虚拟机磁盘容量
disk size:
3.2G
2.准备模板虚拟机配置文件
root@kvmsvr ~]# cat /data/images/rhel7_muban.xml
<domain type='kvm'>
<name>rhel7.2</name>
<uuid>a1992150-5cc7-e19d-20df-cd5cea7d8aa2</uuid>
<memory unit='KiB'>2097152</memory>
..
..
1.为虚拟机svr7快速建立前端盘(复用模板机的磁盘数据)
[root@kvmsvr ~]# qemu-img create -f qcow2 -b /data/images/rhel7_muban.qcow2 /data/images/svr7.qcow2Formatting '/data/images/svr7.qcow2', fmt=qcow2 size=322122547200 backing_file='/data/images/rhel7_muban.qcow2' encryption=off cluster_size=65536
2.为虚拟机svr7准备xml配置
[root@kvmsvr ~]# cp /data/images/rhel7_muban.xml /tmp/svr7.xml //拷贝配置
[root@kvmsvr ~]# vim /tmp/svr7.xml //修改配置
<domain type='kvm'>
<name>svr7</name> //新名称
<uuid>b20a1a1c-a2de-4b2f-bb03-91a3e36257c7</uuid> //新UUID值
.. ..
<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/t
arget/domain-rhel-7/org.qemu.guest_agent.0'/> //改套接字路径
.. ..
</channel>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/svr7.qcow2'/> //新磁盘路径
.. ..
</disk>
.. ..
<interface type='network'>
<mac address='52:54:00:11:00:07'/> //新MAC地址
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03
' function='0x0'/>
</interface>
.. ..
3.定义新虚拟机svr7
[root@room9pc00 ~]# virsh define /tmp/svr7.xml
定义域 svr7(从 /tmp/svr7.xml)
4.为虚拟机svr7配置主机名、IP地址,开启虚拟机svr7,使用root用户登入系统。
[root@svr7 ~]# vim /etc/hostname //配置主机名
svr7.tedu.cn
[root@svr7 ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.4.7/24 connection.autoconnect yes //配置IP地址
[root@svr7 ~]# nmcli connection up eth0 //激活连接
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@svr7 ~]# ifconfig eth0 //确认配置结果
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.4.7 netmask 255.255.255.0 broadcast 192.168.4.255
inet6 fe80::20c:29ff:fe5e:f686 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:11:00:07 txqueuelen 1000 (Ethernet)
RX packets 112143 bytes 9388455 (8.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 507844 bytes 771354289 (735.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。