Prerequisites for installing KVM Virtualization:
First, the CPU must support Virtualization (Intel is vmx and AMD is SVM)
[[Email protected] ~] # Egrep '(vmx | SVM)' -- color/proc/cpuinfo
Make sure that VT is enabled in BIOS
Intel (r) virtualization technology [enabled]
Install virtualization suite
[[Email protected] ~] # Lang = en_US-utf8
[[Email protected] ~] # Yum-y groupinstall "virtualization" "virtualization client" "virtualization platform" "virtualization Tools"
[[Email protected] ~] #/Etc/init. d/lib1_d start
[[Email protected] ~] # Chkconfig libmongod on
[[Email protected] ~] # Virt-Manager
Manually install the system...
Set host network
[[Email protected] ~] # Cd/etc/sysconfig/network-scripts/
[[Email protected] network-Scripts] # cp ifcfg-eth0 ifcfg-br0
[[Email protected] network-Scripts] # Cat ifcfg-br0
Device = br0
Type = Bridge
Onboot = Yes
Nm_controlled = Yes
Bootproto = none
Ipaddr = 172.30.6.149
Prefix = 24
Arpcheck = No
[[Email protected] network-Scripts] # Cat ifcfg-eth0
Device = eth0
Hwaddr = 00: 0C: 29: 7e: DF: 4f
Type = Ethernet
UUID = 743094108ab6c-406d-8238-a8e51be4a515
Onboot = Yes
Nm_controlled = Yes
Bootproto = none
Bridge = br0 // link eth0 to br0
[[Email protected] network-Scripts] #/etc/init. d/NetworkManager stop // close this service
[[Email protected] network-Scripts] # chkconfig NetworkManager off
[[Email protected] network-Scripts] # service network restart
[[Email protected] network-Scripts] # chkconfig network on
[[Email protected] network-Scripts] # reboot
Configure DHCP
[[Email protected] ~] # Yum-y install DHCP
[[Email protected] ~] # Cat/etc/DHCP/DHCPD. conf
Ddns-Update-style interim;
Filename "pxelinux.0 ";
Next-server 172.30.6.149;
Subnet 172.30.6.0 netmask 255.255.255.0 {
Option routers172.30.6.149;
Option domain-name "tarena.com ";
Option domain-name-servers172.30.1.16, 172.30.6.149;
Range dynamic-BOOTP 172.30.6.10 172.30.6.20;
}
[[Email protected] ~] # Service DHCPD start
[[Email protected] ~] # Chkconfig DHCPD on
Configure TFTP
[[Email protected] ~] # Yum-y install TFTP-Server
[[Email protected] ~] # Grep-e "ARGs | disable"/etc/xinetd. d/TFTP
Server_args =-S/tftpboot
Disable = No
[[Email protected] ~] # Service xinetd restart
[[Email protected] ~] # Chkconfig xinetd on
[[Email protected] ~] # Netstat-ln | grep: 69
UDP 0 0 0.0.0.0: 69 0.0.0.0 :*
Configure NFS
[[Email protected] ~] # Cat/etc/exports
/Data/ISO * (RO)
/Var/FTP/pub/ISO/centos/6.5 * (RO)
/Var/FTP/pub/ISO/RedHat/5.10 * (RO)
[[Email protected] ~] # Service rpcbind restart
[[Email protected] ~] # Service NFS restart
[[Email protected] ~] # Chkconfig rpcbind on
[[Email protected] ~] # Chkconfig NFS on
[[Email protected] ~] # Yum-y install syslinux
[[Email protected] ~] # Cd/var/FTP/pub/ISO/RedHat/5.10/isolinux/
[[Email protected] isolinux] # mkdir-P/tftpboot/pxelinux. cfg
[[Email protected] isolinux] # cp initrd. IMG vmlinuz/tftpboot/
[[Email protected] isolinux] # cp isolinux. cfg/tftpboot/pxelinux. cfg/Default
[[Email protected] ~] # Cp/usr/share/syslinux/pxelinux.0/tftpboot/
Unattended rhel5.10 Installation
/Var/lib/libvirt/images // install the default storage location of the KVM Virtual Machine
/Etc/libvirt/qemu // storage location of the KVM virtual machine configuration file
Manage commands
[[Email protected] ~] # Virsh list // view the list of opened virtual machines
[[Email protected] ~] # Virsh list -- all // view the list of all VMS
[[Email protected] ~] # Virsh version // view the version number
[[Email protected] ~] # Virsh start kvm_snap1 // start the kvm_snap1 VM
[[Email protected] ~] # Virsh create/etc/libvirt/qemu/kvm_snap1.xml
[[Email protected] ~] #/Etc/init. d/acpid restart
[[Email protected] ~] # Chkconfig acpid on
[[Email protected] ~] # Virsh shutdown kvm_snap1 // disable the kvm_snap1 VM
[[Email protected] ~] # Virsh destroy kvm_snap1 // force disable the kvm_snap1 VM
[[Email protected] ~] # Virsh autostart kvm_snap1 // set kvm_snap1 to start automatically
[[Email protected] ~] # Virsh dumpxml kvm_snap1> kvm_snap1.xml // export the kvm_snap1 VM configuration file
[[Email protected] ~] # Virsh undefine kvm_snap1 // cancel kvm_snap1 Definition
[[Email protected] ~] # Virsh define kvm_snap1.xml // defines kvm_snap1
[[Email protected] ~] # Virsh dominfo kvm_snap1 // list kvm_snap1 Information
[[Email protected] ~] # Virsh edit kvm_snap1 // edit the kvm_snap1 configuration file
[[Email protected] ~] # Virt-clone-O rhel5.10-N rhel5.10-clone-F/data/images/rhel5.10-clone. IMG // clone the VM
-O specifies the template Host
-N indicates the name of the cloned VM.
-F specifies the storage location of the cloned Virtual Machine
Use LVM to manage VM Disks
1. Create an LV
[[Email protected] ~] # Fdisk-L | grep/dev/sda6
/Dev/sda6 6170 39163 265015296 8e Linux LVM
[[Email protected] ~] # Pvcreate/dev/sda6
[[Email protected] ~] # Vgextend vg_data/dev/sda6
[[Email protected] ~] # Vgdisplay | grep "free PE"
Free PE/size 12799/50 .00 Gib
[[Email protected] ~] # Lvcreate-L 10g-N lv_kvm_node1 vg_data
2. Install guest using the created LV
[[Email protected] ~] # Virt-install \
-- Name kvm_node1 \ // define the Virtual Machine name
-- Noautoconsole \ // use this option to specify that the client console is not automatically connected
-- Ram 1024 \ // specifies the memory size of the VM, in MB
-- Arch = x86_64 // specify the CPU architecture
-- Vcpus = 1 \ // specify the number of virtual CPUs
-- OS-type = Linux \ // specify the installation system type
-- OS-variant = rhel5 \ // specify a specific version
-- Hvm \ // use full virtualization
-- Accelerate \ // use the kernel acceleration function
-- Disk Path =/dev/vg_data/lv_kvm_node1 \
-- Network Bridge = br0 \
-Location NFS: 192.168.194.253:/var/FTP/pub/ISO/RedHat/5.9 \
-- Extra-ARGs = "Ks = http: // 192.168.194.253/rhel-ks.cfg IP = 192.168.194.10 netmask = 255.255.255.0 gateway = 192.168.194.253 DNS = 192.168.194.253 noipv6" // you can write a script
3. Set the template Virtual Machine to remove some personal information (in kvm_node1)
[[Email protected] ~] # Touch/. unconfigured
4. Generate a snapshot
LVM Snapshot
A snapshot records the system information at that time, just like a photo record. If there is any data change in the future, the raw data will be placed in the snapshot area, and the region not changed will be shared by the snapshot area and the file system.
[[Email protected] ~] # Lvcreate-S-l 20g-N lv_node1/dev/vg_data/lv_data
// Specify the snapshot size name
5. Define virt-Manager
[[Email protected] ~] # Virsh dumpxml kvm_node1>/root/kvm_snap1.xml // name of the VM System
[[Email protected] ~] # Uuidgen
D2d8fe52-d244-46e5-97fb-7da9440d785b
Modify the/root/kvm_snap1.xml file (name, UUID, disk location, MAC address)
[[Email protected] ~] # Virsh define/root/kvm_snap1.xml
6. Delete virtual machines
[[Email protected] ~] # Virsh undefine kvm_snap1
Use qcow2 to manage KVM Virtual Machine Disks
Currently, the following formats are used as Virtual Machine images:
Raw default, snapshot not supported
Cow
Qcow
Qcow2qcow2 is similar to raw bare format.
Vmdk VMware format
VDI
This article from the "Zhou min" blog, please be sure to keep this source http://zhmin.blog.51cto.com/5402080/1431362