一、创建母盘
首先安装虚拟机,创建qcow2镜像封装为母盘。需要新虚拟机时,直接从母盘拷贝,生成的磁盘镜像制作的虚拟机将保留母盘的所有配置。
使用本地镜像装机
1.更改主机名:
vi /etc/sysconfig/network
------------------------------------------------------------------
HOSTNAME=server1
2.修改yum 源
vi /etc/yum.repos.d/rhel-source.repo
------------------------------------------------------------------
baseurl=http://172.25.18.250/rhel6.5 ##物理主机设置的yum源
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
3.删除/etc/udev/rules.d/70-persistent-net.rules
这个文件是包含网卡设备和mac地址等信息,因为新配置虚拟机的网卡信息等不同,所以需要删除。
rm -rf /etc/udev/rules.d/70-*
4.配置网络
vim /etc/sysconfig/network-scripts/ifcfg-eth0
---------------------------------------------------------------
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.18.1
PERFIX=24
---------------------------------------------------------------
##重启网络
/etc/init.d/network restart
5.安装基本服务,软件
##openssh-clients提供scp服务 ##查询所需软件:yum provides */scp
yum install vim lftp openssh-clients httpd -y
6.开启服务,并设定开机自动启动:
/etc/init.d/network start
chkconfig network on
/etc/init.d/sshd startchkconfig sshd on
/etc/init.d/httpd startchkconfig httpd on
7.本地解析
vim /etc/hosts
--------------------------------------------------------
172.25.18.1 server1
172.25.18.2 server2
172.25.18.3 server3
172.25.18.4 server4
8.关闭防火墙iptables -L
cd /etc/sysconfig/
rm -f iptables
chkconfig iptables off
9.删除ssh_host_*
cd /etc/ssh/rm -f ssh_host_*
10.关闭selinuxvim
vi /etc/sysconfig/selinux
------------------------------------------------------------------
SELINUX=disabled
11.重启
reboot
12.再次检查网络是否通畅和yum源是否正常。
13.本地解析:
vim /etc/hosts
------------------------------------------------------------------
172.25.18.1 server1
172.25.18.2 server2
172.25.18.3 server3
172.25.18.4 server4
注意:以上操作关系的后面所有使用这个base作快照而安装的虚拟机。
注意:Linux系统版本一致
14.制作快照
cd /var/lib/libvirt/images/
qemu-img create -f qcow2 -b base.qcow2 server3
注:因为在base上已经完成了一些基本第三方软件的安装和其他一些设定,后期用base作快照而安装的虚拟机则省去很多配置。
接下来就对每一台虚拟机进行主机名和ip的修改
(1)修改主机名
vim /etc/sysconfig/network
HOSTNAME=server1
(2)修改ipvim /etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR=172.25.26.1
PERFIX=24
(3)重启
reboot 检查网络是否通畅和yum是否正常。
qcow2磁盘及预分配策略
off模式:缺省预分配策略,即不使用预分配策略
metadata模式:分配qcow2的元数据(metadata),预分配后的虚拟磁盘仍然属于稀疏映像类型(allocates qcow2 metadata, and it's still a sparse image.)
full模式:分配所有磁盘空间并置零,预分配后的虚拟磁盘属于非稀疏映像类型(allocates zeroes and makes a non-sparse image)
falloc模式:使用posix_fallocate()函数分配文件的块并标示它们的状态为未初始化,相对full模式来说,创建虚拟磁盘的速度要快很多(which uses posix_fallocate() to "allocate blocks and marking them as uninitialized", and is relatively faster than writing out zeroes to a file)
这里采用off模式:
[root@18 images]# ll -h server3
-rw-r--r-- 1 qemu qemu 193k Aug 9 11:18 server3 ##占用内存空间小