Linux运维——虚拟机的封装及创建母本
一、配置rhel6.5的网络yum源
[[email protected] images]# systemctl start httpd
[[email protected] images]# systemctl enable httpd
[[email protected] images]# systemctl stop firewalld
[[email protected] images]# systemctl disable firewalld
[[email protected] images]# mkdir /var/www/html/rhel6.5
[[email protected] images]# vim /etc/rc.d/rc.local
----> mount /iso/rhel-server-6.5-x86_64-dvd.iso /var/www/html/rhel6.5
[[email protected] images]# chmod +x /etc/rc.d/rc.local
[[email protected] images]# /etc/rc.d/rc.local
二、封装母盘虚拟机
1.安装虚拟机
1)通过物理机http获得镜像
2)虚拟机内存设置512M,cpu1颗,硬盘10G
3)输入虚拟机名称,生成镜像默认目录:/var/lib/libvirt/images/
4)进入安装界面
5)选择英语语言和美式键盘
6)TCP/IP中ipv4中选择手动,关闭ipv6
7)重新初始化所有磁盘设备
8)去掉system clock users UTC前面的*(中国时区是CST)设置上海时区并设定用户密码为westos
9)密码强度不足,选择user anyway忽略
10)Partition Type(分区类型)有三种:
Use entire drive #使用全部的磁盘;
Replace existing Linux system #替换现有的Linux系统;
Use free space #使用剩余空间
由于是全新安装,三种任意均可
11)将存储设置写入磁盘
12)安装完成后会弹出reboot提示,空格确定即可
2.封装虚拟机
1)配置yum源,并安装软件
2)关闭火墙
3)关闭selinux
4)配置网络
5)删除rule
6)配置本地解析
7)更改主机名
8)关闭虚拟机
poweroff
三、对母盘操作
1.清除base缓存
virt-sysprep -d base
#拓展:
没有命令时可以使用:
which virt-sysprep #查看命令的位置
yum provides */virt-sysprep #查看包含/virt-sysprep命令的安装包
du -h base.qcow2 #查看文件大小
virt-sparsify --compress base.qcow2 new.qcow2 #压缩base.qcow2为new.qcow2
2.删除虚拟机管理器中的base
不删除镜像文件
注意:再次打开base虚拟机后,之前的设置会恢复,以base为母本制作的子镜像将会失效
四、快照
[[email protected] images]# qemu-img create -f qcow2 -b base.qcow2 vm1
[[email protected] images]# qemu-img create -f qcow2 -b base.qcow2 vm2
[[email protected] images]# qemu-img create -f qcow2 -b base.qcow2 vm3
[[email protected] images]# qemu-img create -f qcow2 -b base.qcow2 vm4
五、导入并配置子虚拟机
1.导入子虚拟机
2.配置子虚拟机网络及主机名