Install KVM in CentOS 6.5

Source: Internet
Author: User

Install KVM in CentOS 6.5

1. Install CentOS6.5 with minimal. 2. After installing CentOS, use root to log on and configure the NIC so that the VM can access the Internet.
Vi/etc/sysconifg/network-scripts/ifcfg-eth0
For reference:

After saving, restart the network service.
Service network restart

Then test whether the network can be connected.
Ping www.bkjia.com

3. Disable selinux and clear iptables
Modify selinux configuration file
Sed-I's/SELINUX = enforcing/SELINUX = disabled/'/etc/selinux/config
Set current selinux
Setenforce 0

Clear iptables
Iptables-F
Save iptables rules
Service iptables save

4. Install KVM
Install with yum:
Yum-y install qemu-kvm libvirt python-embedded inst bridge-utils avahi dmidecode
Restart the VM after installation.
Init 6

After restart, test whether the kvm is successfully installed.
Stat/dev/kvm
Execution result:
File: "/dev/kvm"
Size: 0 Blocks: 0 IO Block: special file with 4096 characters
Device: 5 h/5d Inode: 9503 Links: 1 Device type: a, e8
Access: (0666/crw-rw-) Uid: (0/root) Gid: (36/kvm)
Access: 16:56:11. 463134124 + 0800
Modify: 16:56:11. 463134124 + 0800
Change: 16:56:11. 463134124 + 0800

There is no result when you execute this command on vb. I am running this command on a real machine.

Test whether libmongod can be started normally.
Service libmongod start
Service libmongod restart

5. configure network bridging
Check whether NetworkManager is enabled in the system. It is best to disable the service because the service conflicts with the network.
Chkconfig | grep NetworkManager
If NetworkManager exists
Chkconfig NetworkManager off
Service NetworkManager stop

Copy the configuration file for an existing Nic from the ifcfg-eth0 and rename it to the ifcfg-br0:
Cp/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-br0

Modify the ifcfg-br0, pay attention to the two red lines, other parts basically do not need to change.
Vi/etc/sysconfig/network-scripts/ifcfg-br0
DEVICE = br0
HWADDR = 08: 00: 27: 1D: 26: B2
UUID = 251576f1-0ae3-4a52-b0e1-9343a7ad936d
TYPE = Bridge
ONBOOT = yes
NM_CONTROLLED = yes
BOOTPROTO = stataic
IPADDR = 10.0.0.156
NETMASK = 255.255.255.0
GATEWAY = 10.0.0.1
DNS1 = 202.96.64.68
DNS2 = 202.96.69.38

 

Modify the ifcfg-eth0 to save only the following rows.
Vi/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE = eth0
HWADDR = 08: 00: 27: 1D: 26: B2
UUID = 251576f1-0ae3-4a52-b0e1-9343a7ad936d
TYPE = Ethernet
ONBOOT = yes
NM_CONTROLLED = yes
BRIDGE = br0

Restart the network service
Service network restart

Shutting down the eth0: bridge br0 does not exist!
[OK]
Disable the loop interface: [OK]
Pop-up loop interface: [OK]
Pop-up page eth0: [OK]
Br0: Determining if ip address 10.0.0.156 is already in use for device br0.0...
[OK]

Run ifconfig
Br0 Link encap: Ethernet HWaddr 08: 00: 27: 1D: 26: B2
Inet addr: 10.0.0.156 Bcast: 10.0.0.1 Mask: 255.255.255.0
Inet6 addr: fe80: ba97: 5aff: feb7: 98b5/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 1210 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 40 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 74677 (72.9 KiB) TX bytes: 7509 (7.3 KiB)

Eth0 Link encap: Ethernet HWaddr 08: 00: 27: 1D: 26: B2
Inet6 addr: fe80: ba97: 5aff: feb7: 98b5/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 5625 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 359 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 425234 (415.2 KiB) TX bytes: 65054 (63.5 KiB)

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: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)

Virbr0 Link encap: Ethernet HWaddr 52: 54: 00: CA: 22: F4
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: 11 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 2449 (2.3 KiB)

Configure forwarding
Run the following command:
Echo 1>/proc/sys/net/ipv4/ip_forward
This step has only one simple command, but it is critical. If you do not perform this step, all virtual machines will not be able to access the Internet.
In addition, after the bridge is configured in the previous step, restart the network and change ip_forward to 0 automatically. Therefore, do not forget to execute this command after you reconfigure the network. When the VM cannot access the Internet, you can also check the ip_forward value.

Vi. Virtual Machine Installation
Modify qemu. conf configuration
Vi/etc/libvirt/qemu. conf

Vnc_listen = "0.0.0.0"
User = "root"
Group = "root"
Dynamic_ownership = 0

Restart the libmongod Service
Service libmongod restart

Create a directory for storing VM-Related Files
Mkdir/kvm

Use winscp to copy the centos6.5 installation CD image to/kvm

Create a directory for storing virtual machines
Mkdir/kvm/vm

Install Virtual Machine
Virt-install -- name centos -- ram 1024 -- vcpus = 1 -- disk path =/kvm/vm/vm1.img, size = 10 -- network bridge = br0 -- OS-variant = rhel6 -- cdrom/kvm/CentOS-6.5-x86_64-bin-DVD1.iso -- vnclisten = 10.0.0.156 -- vncport = 6900 -- vnc

Parameters:
-- Number of vcpus allocated to virtual machines
-- Disk path: path of the Virtual disk
-- Size: the size of the virtual disk. The unit is GB.
-- Network bridge: Specifies the bridging network card used by the VM.
-- OS-variant virtual machine operating system type
-- Cdrom: Path of the CD image used to install the virtual machine operating system
-- Listening IP address of vnclisten vnc
-- Vncport listener port of vnc
-- Vnc connection using vnc

Then use vnc-viewer to connect to the virtual machine,
If you use vnc viewer to connect to the VM, set ColourLevel = rgb222 of vnc.
Connect 10.0.0.156: 6900 using vnc-viewer to remotely install this virtual machine.

There is no difference between installing the operating system on a kvm virtual machine and other virtual machines.
After the installation is complete, you can use putty for remote connection After configuring the nic in the kvm virtual machine.

Run
Virsh start centos

When kvm is nested in VirtualBox, it is no problem to use vnc to remotely install the system, but it is very slow to start the kvm virtual machine, I waited for 20 minutes and failed to start. and the cpu load is high.
Therefore, if conditions are met, you can use a real machine to perform an experiment.

Virsh syntax reference

Virsh list running VMS
Virsh start centos Virtual Machine
Virsh shutdown centos shut down the centos Virtual Machine
Virsh destroy centos force disable centos Virtual Machine
Virsh autostart centos sets centos to automatically start
Virsh undefine centos Delete centos VM
Virsh suspend centos pause the centos VM
Vrish resume centos restore centos Virtual Machine
Virsh reboot centos restart centos VM
Virsh edit centos Virtual Machine
Virsh vncdisplay centos vnc display

-------------------------------------- Split line --------------------------------------

How to add a hard disk for a Linux Virtual Machine in KVM

Getting started with Linux: KVM for Virtual Machine experience

RHEL6 KVM virtualization creates a bridge NIC-Bridge

RedHat Linux KVM Virtual Machine bridging

Installation/bridging settings of KVM in CentOS 5.6/virtual machine creation and operation

The/bin/qemu-KVM problem cannot be found when the kvm virtual machine is installed with libvirt In Ubuntu.

Install and configure the KVM Virtual Machine in RedHat6.5

Nested virtualization nested for KVM Virtualization

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.