Install and configure KVM virtual machines in CentOS 6.5

Source: Internet
Author: User

Install and configure KVM virtual machines in CentOS 6.5

Note:

KVM can be installed only in 64-bit server versions above RHEL5.5, and Centos is the same. Both the client Version and 32-bit cannot install KVM.

Preparations for installation: because some CPUs do not support kvm virtualization, Need checks whether the virtualization option is enabled for the motherboard (BIOS). In addition, when installing the Centos software package, check virtualization. If not, run the command: yuminstallvirt * to install yuminstallvirt.

0. Configure BIOS

Enables BIOS to support virtualization,

If not configured, an error is returned:

"Error polling connection 'qemu: // system ': internal error Cannot find suitable emulator for x86_64"

1. software required

1.1Kvm Module

After 2.6.29, the kernel mostly contains the kvm module. Slackware13.37 kernel version 2.6.32 already contains the kvm module. Therefore, you do not need to download the kvm-mod module from the Internet. Otherwise, the module cannot be started normally, kvm virtual machines are extremely slow.

1.2 user space components

Release, Version 1.0

1.3yuminstalltunctl component, version 1.5, mainly used to Implement Virtual Machine networking packages is in DVD.

2. Installation Steps

2.1 install qemu-kvm (if yum has qemu-kvn installed, skip this step .)

./Configure -- disable-vnc-tls -- disable-vnc-sasl disable this VNC option; otherwise, an error is returned;

Make

Makeinstall

2.2 install tunctl

Yuminstalltunctl-y

Restart the server and debug the CPU.

3. Host and client networking

Set Nic Bridging Mode

Configuration on a real machine

[Root @ localhost src] # cd/etc/sysconfig/network-scripts/
1. Back up the NIC
Cp-rap ifcfg-eth0 bak. ifcfg-eth0
2/use the eth0 configuration file for the new bridging Nic
Cp-rap ifcfg-eth0 ifcfg-br33
3. edit these two configuration files. Note that editing this file will cause Nic ip address downtime. You can edit the following configuration file first.

Vim ifcfg-eth0.
DEVICE = eth0
BOOTPROTO = none
HWADDR = bc: AE: c5: df: 93: 96
NM_CONTROLLED = yes
ONBOOT = yes
BRIDGE = "br33"
IPV6INIT = no
USERCTL = no

Save launch

Vim/etc/sysconfig/network-scripts/ifcfg-br33
DEVICE = br33
BOOTPROTO = static
HWADDR = bc: AE: c5: df: 93: 96
NM_CONTROLLED = yes
ONBOOT = yes
TYPE = Bridge
IPADDR = 192.168.1.202
NETMASK = 255.255.255.0
GATEWAY = 192.168.1.1
DNS1 = 8.8.8.8
Save launch
Restart Nic

/Etc/init. d/network restart

3. Disable NetworkManager for centos (this step can be left blank)

You must disable this service. Otherwise, the script configuration file of the NIC may not take effect, and the network cannot be accessed.

ServiceNetworkManagerstop

3.4 restart the network service

Servicenetworkrestart

3.5 enable Forwarding (skip this step)

Echo1>/Proc/sys/net/ipv4/ip_forward


3.6 Review network card status:

[Root @ localhost ~] # Ifconfig
Br33 Link encap: Ethernet HWaddr 00: 25: 64: 97: BA: 51
Inet addr: 192.168.120.96 Bcast: 192.168.120.255 Mask: 255.255.255.0
Inet6 addr: fe80: 225: 64ff: fe97: ba51/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 641005 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 4785 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 64019315 (61.0 MiB) TX bytes: 278717 (272.1 KiB)

Eth0 Link encap: Ethernet HWaddr 00: 25: 64: 97: BA: 51
Inet6 addr: fe80: 225: 64ff: fe97: ba51/64 Scope: Link
Up broadcast running promisc multicast mtu: 1500 Metric: 1
RX packets: 1410323 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 465818 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 254264481 (242.4 MiB) TX bytes: 293774426 (280.1 MiB)
Interrupt: 21 Memory: fe6e0000-fe700000

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 468571 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 468571 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 898319692 (856.7 MiB) TX bytes: 898319692 (856.7 MiB)

Virbr0 Link encap: Ethernet HWaddr 52: 54: 00: B3: 44: 41
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 4293 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 205669 (200.8 KiB)

Vnet0 Link encap: Ethernet HWaddr FE: 54: 00: 11: CE: 91
Inet6 addr: fe80: fc54: ff: fe11: ce91/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 182999 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 911932 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 500
RX bytes: 266186182 (253.8 MiB) TX bytes: 110334183 (105.2 MiB)

Vnet1 Link encap: Ethernet HWaddr FE: 54: 00: A5: 0F: 52
Inet6 addr: fe80: fc54: ff: fea5: f52/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 161319 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 783482 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 500
RX bytes: 20856924 (19.8 MiB) TX bytes: 97247791 (92.7 MiB)

[Root @ localhost ~] #
Summary: eth0 don't have IP address, only br33 has valid IP. That is to say, br33 IP address is server's IP address.

Conclusion: The host cannot access the Internet and the virtual machine can access the Internet. Possible: 1. instead of writing the bridge configuration file, refer to the KVM official website and use commands to add bridges and bind NICs. Therefore, no gateway is configured for bridges. when NetworkManager is enabled, the ifconfig command is used to configure network failure. DNS is not properly configured

######### Do not use the default hard disk type after creating a VM. Delete the default hard disk and add another hard disk, the hard disk type must be vda, the hard disk format must be raw, and the cache mode should be none. #########
Using the default hard disk type will lead to crashes and the old scalpers-slow !!!

########## Select the architecture and virtual machine type. You must select kvm. The architecture conforms to the actual situation of your virtual machine. For my virtual machine, choose kvm and i686, otherwise, the VM is very slow and cannot be used. ################################

4.0 create a KVM VM

When installing a virtual machine, select Advanced-nic-br33.

Switch to the root user: su-l

Install the kvm module modprobekvm & modprobe kvm_intel

View module installation; lsmod | grepkvm

To create a VM:

1. type the command on the server: (because you want to select the image format qcow2 for snapshot, you cannot use the default format of the graphic interface)

[Root @ PLASPACSHCN14 ~] # Cd/var/lib/libvirt/images/

[Root @ PLASPACSHCN14 images] # qemu-img create-f qcow2 test. img 10G

Formatting 'test1. img ', fmt = qcow2 size = 10737418240 encryption = off cluster_size = 65536

The size is 10 Gb. You can define the size as needed. The image name is test. img.

2. Open the graphic interface:

[Root @ PLASPACSHCN14 images] # virt-manager
Xlib: extension "randroid" missing on display "localhost: 10.0 ".

Select new to create a new virtual machine:

Enter the Virtual Machine name here, and note that you must select "import existing disk image" to select the image you just created.

Select "Forward"

Enter the path of the image you just created.

Select next.

All the way to the next step. After the settings are complete, you will find that no optical drive is selected.

Select the Details Option

Select "Add Hardware"

Next, you need to modify the path of the CD file to point to the operating system image file.

Device type: Select "IDE cdrom" here.

Next, click finish. After restarting, continue to install the system!

Kvm commands:

Enable virtual machine:

Virt-manager

4.1 create a hard disk image for the client

Qemu-img create-fqcow2vdisk.img50G

4.2 install the client operating system:

CD boot:

Qemu-system-x86_64-hdavdisk.img-cdrom/dev/cdrom-bootd-m512

. Iso file startup:

Qemu-system-x86_64-hdavdisk.img-cdrom/Centos6.0.iso (here is the iso file path)-bootd-m512

4.3 start the operating system:

Qemu-system-x86_64-hadvdisk.img-netnic, macaddr = custom physical address-nettap-m512

After the client is started, it can be used in general operating systems. If you want to connect to the Internet with the ip address and gateway of the client, you can access the Internet.

Problems encountered during the process, such as: the KVM Virtual Machine flat screen crashes under Centos6.2 and VNC errors. For more information, see other blog articles. If you have any other questions, please leave a message to discuss them, in addition, the preceding commands can be written as scripts to simplify installation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.