I am very interested in virtualization recently. I tried centos6 to start learning from xen and haven't made it out for the moment -- |. it seems that kernel 6 does not support xen, but kvm is also good, I have written some study notes, most of which are the experiences of online experts. 1. download the 163 source profile http://mirrors.163.com/.help/CentOS6-Base-163.repo#cd/etc/yum.repos after installing centos6.2
Recently, I was very interested in virtualization. I tried centos 6 to start learning from xen, but I haven't figured it out yet--|. it seems that kernel 6 does not support xen, but kvm is also good, I have written some study notes, most of which are the experiences of online experts.
1. download the 6.2 source profile http://mirrors.163.com/.help/CentOS6-Base-163.repo after installing centos 163
# Cd/etc/yum. repos. d/# enter the source directory
# Cp CentOS-Base.repo CentOS-Base.repo.bak # backup source files
Replace CentOS-Base.repo file content with the downloaded 163 source profile
# Yum update system upgrade
If no error is prompted, in the CentOS-Base.repo file
Gpgcheck = 0
2. check whether the hardware supports virtualization.
1. KVM requires the CPU to support virtualization. run the following command to check whether virtualization is supported:
# Egrep 'vmx | svm '/proc/cpuinfo
If vmx or svm is included, CPU virtualization is supported. Intel is vmx and AMD is svm.
Otherwise, modify the bios and set the CPU to support virtualization.
2. check whether KVM is successfully loaded.
# Lsmod | grep kvm
The following result indicates that the kvm module has been loaded. If no output information is displayed, it indicates that the kvm module has not been loaded successfully:
Kvm_amd 50452 0
Kvm 109264 1 kvm_amd
3. configure network bridging
1. install tunctl:
# Yum install-y tunctl
2. disable the network manager.
# Chkconfig NetworkManager off conflicts with the bridge. disable it.
# Service NetworkManager stop
3. create a virtual Nic for bridging. you can configure different NICs for multiple virtual machines.
# Cd/etc/sysconfig/network-scripts
# Cp ifcfg-eth0 ifcfg-br0
Edit ifcfg-br0
# Vi ifcfg-br0
DEVICE = "br0"
TYPE = "Bridge"
ONBOOT = "yes"
BOOTPROTO = static
IPADDR = 192.168.1.17
PREFIX = 24
GATEWAY = 192.168.1.1
DNS1 = 202.106.46.151
DELAY = 0
Edit ifcfg-eth0
# Vi ifcfg-eth0
DEVICE = "eth0"
NM_CONTROLLED = "yes"
ONBOOT = yes
TYPE = Ethernet
BRIDGE = "br0"
BOOTPROTO = none
IPADDR = 192.168.1.17
PREFIX = 24
GATEWAY = 192.168.1.1
DEFROUTE = yes
20174_failure_fatal = yes
IPV6INIT = no
NAME = "System eth0"
UUID = 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
DNS1 = 202.106.46.151
HWADDR = 00: 1E: 67: 07: EC: 30
Restart the network
# Service network restart
4. configure virtual machines
1. graphical configuration
Start from the menu, or run virt-manager to enter the graphic management interface. this is simple and not detailed here. However, you need to configure the img location. after kvm is installed, there will be a default location, if you do not pay attention to it, it is easy to fill up space. Or separate/var into one partition when partitioning hard disk directly.
2. command line configuration
First, define the variable, and then execute virt-install for installation. you can also do it without defining the variable, but the command will be long.
Name = vm1
Port = 6900
Img =/vms/vm1/vm1.img
Ostype = linux
Osvariant = rhel5
Ram = 800
Cpu = 1
SizeG = 10
Eth = br0
Iso =/software/CentOS/CentOS-5.5-x86_64-bin-DVD-1of2.iso
Virt-install -- name $ name -- ram $ ram -- vcpus = $ cpu \
-- Disk path = $ img, size = $ sizeG -- network bridge = $ eth \ -- OS-type = $ ostype -- OS-variant = $ osvariant -- cdrom $ iso -- vncport = $ port -- vnc
After the preceding commands are executed, the virtual system installation interface will be opened if there is no error.
V. Other command lines and tools
View the running virtual machine:
Virsh-c qemu: // system list
The main management command of the virtual machine virsh, after the virsh management shell:
6. Other problems
1. reconfigure the virtual machine
The virtual machine configuration file is saved in the/etc/libvirt/qemu directory, and the extension is xml.
Modify the corresponding file to reconfigure the virtual machine.
2. Virtual Machine backup and recovery
Backup: Copy the xml configuration file under the/etc/libvirt/qemu directory and the imgfile set in the xml.
Restore: go to virsh and execute the xml file path under the define directory.
3. automatically start the VM upon startup
Command line: Virtual Machine name in the autostart directory.