KVM1-KVM虚拟机的自动安装和克隆
环境:RHEL6.4主机及虚拟化软件
1,安装虚拟化软件:
一共有四个软件组:
Virtualization、Virtualization Client、Virtualization Platform、Virtualization Tools
[root@server1 cd]# yum groupinstall -y Virtualization 'Virtualization Client''Virtualization Platform' 'Virtualization Tools'
2,启动虚拟机:
启动之前需要先启动libvirtd服务
[root@server1 cd]# service libvirtd start
Startinglibvirtd daemon: [ OK ]
[root@server1 ~]# virt-manager //打开kvm虚拟机
rhel6里面永久关闭selinux:
[root@server1 ~]# vim /etc/selinux/config
3,配置PXE服务器:
1,配置dhcpd
指定:next-server192.168.3.1;
filename"pxelinux.0";
2,安装ftp
yum install vsftpd
3,mkdir /var/ftp/rhel6
cp -r /misc/cd/* /var/ftp/rhel6
4,yum install tftp-server
//在配置文件/etc/xinetd.d/tftp文件里修改共享目录为/tftp
cp/misc/cd/isolinux/* /tftpboot
mv /tftpboot/isolinux.cfg /tftpboot/pxelinux.cfg/default
指定ks文件的位置:append initrd=initrd.img ks=ftp://192.168.3.1/ks.cfg
chmod 644 default
cp /usr/share/syslinux/pxelinux.0 /tftpboot
5,制作ks.cfg文件,存放到/var/ftp/目录下
//如果有必要,将ks.cfg文件权限修改为766
注:详细的PXE环境部署,可参考:http://murongqingqqq.blog.51cto.com/2902694/1389369
4,GPT分区:
[root@server1 ~]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel align-check cp mkfs mkpart mktable name quit resize select toggle version check help mklabel mkpartfs move print rescue rm set unit (parted) mklabel gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes (parted) mkpart Partition name? []? /dev/sdb1 //输入名字 File system type? [ext2]? ext4 //格式化类型 Start? 1 // 起始位置到结束为止,1到-1代表全部 End? -1 (parted) quit Information: You may need to update /etc/fstab. [root@server1 ~]# fdisk -cul /dev/sdb ... Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sdb1 1 209715199 104857599+ ee GPT [root@server1 ~]# 可通过fdisk -cu /dev/sdb修改为8e类型,之后做成物理卷 |
5,创建虚拟机的脚本:
[root@server1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-{eth0,br0} [root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static BRIDGE=br0 [root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0 TYPE=Bridge ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.3.1 PREFIX=24 [root@server1 ~]# cat bin/install-rhel6 #!/bin/bash /usr/sbin/virt-install \ --vnc \ --noautoconsole \ --name=rhel6test \ --ram=1024 \ --arch=x86_64 \ --vcpus=1 \ --os-type=linux \ --os-variant=rhel6 \ --hvm \ --accelerate \ --disk=/dev/vgtest/lvtest \ -m 52:54:00:00:01:00 \ //指定虚拟机的网卡 -w bridge=br0 \ --location=ftp://192.168.3.1/rhel6 \ //指定安装系统所需包的位置 --extra-args="ks=ftp://192.168.3.1/ks.cfg" //指定ks.cfg文件 [root@server1 ~]# |
6,创建逻辑卷的快照:
[root@server1 ~]# lvcreate-s -n lvtest-1 -L 10G /dev/vgtest/lvtest
COW:Copy OnWrite 写时复制
元数据查看方式:stat
[root@localhost ~]# stat anaconda-ks.cfg
File: `anaconda-ks.cfg'
Size: 929 Blocks:8 IO Block: 4096 regular file
Device:fc03h/64515d Inode: 1050131 Links: 1
Access:(0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access:2014-04-15 07:27:44.318000011 +0000
Modify:2014-04-15 07:27:44.326000010 +0000
Change:2014-04-15 07:27:49.894999985 +0000
[root@localhost ~]#
查看磁盘的uuid:
[root@server1Desktop]# blkid /dev/sdb1
/dev/sdb1:UUID="PKtyYU-Gnpo-0Usq-u2U8-ddmI-mTj2-lrmAbP"TYPE="LVM2_member"
[root@server1Desktop]#
随机生成UUID:
[root@server1Desktop]# uuidgen
cdb3197e-7af5-481b-9708-bee473dadfcb
[root@server1Desktop]#
7,KVM虚拟机克隆基本操作:
[root@server1 Desktop]# virsh dumpxml rhel6base > rhel6base.xml [root@server1 Desktop]# vim rhel6base.xml //修改内容 <name>rhel6basenode1</name> <uuid>8e3e1c12-ed01-492a-b277-399dbbdb1f9d</uuid> <source dev='/dev/vgtest/lvtest1'/> <mac address='52:54:00:00:01:01'/> [root@server1 Desktop]# virsh define rhel6base.xml //使用已经存在的xml文件和磁盘文件定义GUEST主机 [root@server1 Desktop]# virsh list //列出开启的虚拟机 Id Name State ---------------------------------------------------- 7 rhel6base running [root@server1 Desktop]# virsh list --all Id Name State ---------------------------------------------------- 7 rhel6base running - rhel6basenode1 shut off [root@server1 Desktop]# virsh start rhel6basenode1 //运行虚拟机rhel6basenode1 |
附件:LVM虚拟机管理:http://murongqingqqq.blog.51cto.com/2902694/1396079