How to install and configure kvm qemu Virtual Machine in CentOS

Source: Internet
Author: User
Tags arch linux

How to install and configure kvm qemu Virtual Machine in CentOS

I. What is KVM?

KVM includes many components: first, it is a Linux kernel module (currently included in the main line) used to convert the processor to a new user (guset) mode. The user mode has its own ring state set, but the ring0 command with the privilege falls into the Manager (hypervisor) code. Because this is a new processor execution model, the Code does not need to be modified.

In addition to processor state conversion, this kernel module also handles a small portion of low-level simulations, such as MMU registration (used to manage VMS) and some PCI analog hardware.

In the foreseeable future, the Qemu team will focus on hardware simulation and portability, while the KVM team will focus on Kernel Modules (if some parts do have performance improvements, KVM will move a small part of the simulated code in) and interact with the remaining user space code.

Kvm-qemu executable programs are like normal Qemu: allocating RAM and Loading Code. Unlike re-compiling or calling KQemu, it creates a thread (this is important ); this thread calls the KVM kernel module to switch to the user mode and execute VM code. When a privileged command is run, it switches from the KVM kernel module. When required, the kernel module sends signals like Qemu threads to process most hardware simulation tasks.

One clever part of this architecture is that the customer code is simulated in a posix thread, which allows you to manage it using common Linux tools. If you need a virtual machine with 2 or 4 cores, kvm-qemu creates 2 or 4 threads. Each thread calls the KVM kernel module and starts execution. Concurrency (if you have enough real cores) or scheduling (if you don't care) is a common Linux scheduler, this makes the KVM code very small.

When working together, KVM manages CPU and MEM access, and QEMU simulates hardware resources (hard disks, sound cards, USB, and so on). When QEMU runs separately, QEMU simulates both CPU and hardware.

Ii. install and configure KVM

# Yum-y install kvm python-stronginst libvirt bridge-utils \
Virt-manager qemu-kvm-tools virt-viewer virt-v2v qemu-kvm tunctl

[Root @ localhost ~] # Vim/etc/sysconfig/selinux // disable selinux

SELINUX = disabled

[Root @ localhost ~] # Reboot

[Root @ localhost ~] # Cat/etc/RedHat-release
CentOS release 6.5 (Final) // centos 6.5

3. Start libmongod

[Root @ localhost ~] #/Etc/init. d/libmongod start // start

[Root @ localhost ~] # Ps-e | grep libmongod // you can check whether the instance is started.
19458? 00:00:01 libmongod

4. Check whether the kvm module is correctly loaded.

[Root @ localhost ~] # Lsmod | grep kvm
Kvm_intel 54285 0
Kvm 333172 1 kvm_intel

5. configure network bridging

[Root @ localhost network-scripts] # cat ifcfg-eth0 | awk '{if ($0 !~ /^ $/& Amp; $0 !~ /^ #/) {Print $0 }}'
DEVICE = eth0
TYPE = Ethernet
ONBOOT = yes
BOOTPROTO = none
BRIDGE = br0
IPV6INIT = no
HWADDR = F8: BC: 12: 60: 99: 86

[Root @ localhost network-scripts] # cat ifcfg-br0 | awk '{if ($0 !~ /^ $/& Amp; $0 !~ /^ #/) {Print $0 }}'
DEVICE = br0
TYPE = Bridge
ONBOOT = yes
BOOTPROTO = static
IPADDR = 192.168.10.103
GATEWAY = 192.168.10.1
NETMASK = 255.255.255.0
DNS1 = 192.168.10.1
IPV6INIT = no
DELAY = 0

When you restart the network, the following error is reported:

[Root @ localhost network-scripts] #/etc/init. d/network start
Pop-up loop interface: [OK]
Interface popped up: eth0: Error: failed to activate the connection: Master connection not found or invalid
[Failed]
Br0: Error: Failed to activate connection: Failed to determine connection's virtual interface name
[Failed]
RTNETLINK answers: File exists
RTNETLINK answers: File exists
RTNETLINK answers: File exists

Solution:

[Root @ localhost rules. d] # service NetworkManager stop // just close it.
Stop the NetworkManager daemon: [OK]

[Root @ localhost rules. d] # service network restart
Closing interface br0: [OK]
Closing interface eth0: [OK]
Disable the loop interface: [OK]
Pop-up loop interface: [OK]
Pop-up page eth0: [OK]
Br0: Determining if ip address 192.168.10.103 is already in use for device br0.0...
[OK]

If the following content indicates that the configuration is successful:

[Root @ localhost network-scripts] # ifconfig
Br0 Link encap: Ethernet HWaddr F8: BC: 12: 60: 99: 86 // if you have this, OK
Inet addr: 192.168.10.103 Bcast: 192.168.10.255 Mask: 255.255.255.0
Inet6 addr: fe80: fabc: 12ff: fe60: 9986/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 36416 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 28648 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 13151508 (12.5 MiB) TX bytes: 5962449 (5.6 MiB)

Eth0 Link encap: Ethernet HWaddr F8: BC: 12: 60: 99: 86
Inet6 addr: fe80: fabc: 12ff: fe60: 9986/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 1360857 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 902173 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 1913592871 (1.7 GiB) TX bytes: 72387220 (69.0 MiB)

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: 176842 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 176842 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 880282316 (839.5 MiB) TX bytes: 880282316 (839.5 MiB)

Virbr0 Link encap: Ethernet HWaddr 52: 54: 00: 1A: B6: F1
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: 37 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 4651 (4.5 KiB)

[Root @ localhost network-scripts] # brctl show
Bridge name bridge id STP enabled interfaces
Br0 8000. f8bc12609986 no eth0 // OK
Virbr0 8000.5254001ab6f1 yes virbr0-nic

6. Use virt-install to generate the. imgfile

# Virt-install -- name = Ubuntu1 \
-- Ram 1024 -- vcpus = 1 \
-- Disk path =/root/ubuntu1.img, size = 10 \
-- Accelerate -- cdrom/root/ubuntu-14.04-desktop-amd64.iso \
-- Graphics vnc, port = 5920 -- network bridge = br0

If the following error is reported:

Cocould not open disk image: Permission denied

Solution:

[Root @ localhost ~] # Cat/etc/libvirt/qemu. conf | awk '{if ($0 !~ /^ $/& Amp; $0 !~ /^ #/) {Print $0 }}'
Vnc_listen = "0.0.0.0"
User = "root" // remove comments
Group = "root" // remove comments
Dynamic_ownership = 0 // remove the comment and Change 1 to 0.

Dynamic_ownership = 0 // remove the comment and Change 1 to 0.

After this step is completed, the system file will be ready.

7. Start a virtual machine

If the following error is reported:

[Root @ localhost ~] # Virsh start ubuntu1
Error: The domain is active.

Solution:

[Root @ localhost ~] # Pkill qemu-kvm

[Root @ localhost ~] # Virsh start ubuntu1
Domain ubuntu1 started

[Root @ localhost ~] # Virt-viewer ubuntu1 // enter the GUI

Linux getting started Tutorial: QEMU for Virtual Machine experience

Ubuntu 12.04 cannot find the Qemu command

Install QEMU + efi bios on Arch Linux

QEMU translation framework-debugging tools

QEMU code analysis: BIOS loading process

QEMU details: click here
QEMU: click here

This article permanently updates the link address:

Related Article

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.