Centos6.3 install KVM

Source: Internet
Author: User
Tags svm

Centos6.3 install KVM

1. Install kvm

1. You can choose to install kvm when installing CentOS6.3.

2. If kvm is not installed, install it as follows:

[Create a local yum source]

Mounting iso files
Mount-o loop-t iso9660 CentOS-6.3-x86_64-bin-DVD1.iso/mnt

Set local yum source
Create the "any file name. repo" file in/etc/yum. repos. d/.
Vi file name editing just created
[Localyum] any name with no space.
Name = local yum any name
Baseurl = file: // mnt/Packages. Server is the Server directory in the CD, and Packages and Server are placed in the same directory. Under the/software Directory
Enabled = 1 indicates that 0 is invalid.
Gpgcheck = 1 check that gpgkey 1 takes effect 0 does not take effect
Gpgkey = file: // when this file is not specified in the software installation CD, you may be prompted not to register
Save and exit
Run the command yum clean all
(1) kvm requires CPU support (Intel VT or amd svm)
[[Email protected] ~] # Egrep '^ flags. * (vmx | svm)'/proc/cpuinfo
If a return value exists, the cpu supports virtualization.
(2) install kvm libvirted
Yum install kvm kmod-kvm qemu kvm-qemu-img virt-viewer virt-manager libvirt-python-kernel Inst
(3) start libvirted
Service messagebus start

Service haldaemon start

Service libmongod start

Chkconfig messagebus on

Chkconfig haldaemon on

Chkconfig libmongod on

(4) Check whether kvm is successfully installed
[[Email protected] ~] # Virsh-c qemu: // system list
Id name status
----------------------------------------------------
1 redhat6.3 running

(5) kvm module
[[Email protected] ~] # Lsmod | grep kvm
Kvm_intel 52570 0
Kvm 314739 1 kvm_intel


2. Configure the bridge

Vi/etc/sysconfig/network-scripts/ifcfg-br0
DEVICE = br0
TYPE = Bridge
BOOTPROTO = static
BROADCAST = 10.207.255.255
IPADDR = 10.207.20.200
NETMASK = 255.255.255.0
NETWORK = 10.207.20.0
ONBOOT = yes
B,
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE = eth0
BOOTPROTO = none
ONBOOT = yes
BRIDGE = br0
C,
Restart the network service to take effect
Service network restart
D,
Echo 1>/proc/sys/net/ipv4/ip_forward # VM access

E,
Check bridging network
[[Email protected] ~] # Brctl show
Bridge name bridge id STP enabled interfaces
Br0 8000.842b2b74e1b6 no eth0
Virbr0 8000.000000000000 yes
Br0 is the configured bridging network card, and virbr0 is the NAT network card automatically configured by the system script.

3. Install vnc

Note: CentOS6.3 VNC is named as tiggervnc-server.

(1)
Yum install tiggervnc-server

(2)
Vi/etc/sysconfig/vncservers

# Add a row
VNCSERVERS = "1: root"

(3)
Vncpasswd

Create Password
(4)
/Etc/init. d/vncserver start

(5)
# Netstat-nulpt | grep vnc
Tcp 0 0 0.0.0.0: 5901 0.0.0.0: * LISTEN 29167/Xvnc
Tcp 0 0 0.0.0.0: 6001 0.0.0.0: * LISTEN 29167/Xvnc
Tcp 0 0: 6001: * LISTEN 29167/Xvnc
Indicates that vnc can be used.
Modify qemu. conf configuration, remove the annotations in the following parts, and change the value of dynamic_ownership to 0. Disable lib1_d to dynamically modify the file ownership: # vi/etc/libvirt/qemu. conf...
User = "root"
Group = "root"
Dynamic_ownership = 0
...
Restart the libmongod service and use the above virt-install command to install it. In this case, vnc is bound to 127.0.0.1 by default, if other machines want to use the vnc client to access the ubuntu server that is being installed on this kvm server, bind the vnc to the IP address of the server or bind it to global 0.0.0.0. modify qemu. cancel the comments in the vnc_listen line in the conf file. Remember to restart libvirtd: # vi/etc/libvirt/qemu. conf...
Vnc_listen = "0.0.0.0"

4. Create a kvm VM

Virsh-install
1. Enter the virtual machine name.
2. How much memory is allocated?
3. Number of processors
4. In this step, you can directly enter the iso location or url
5. Virtual Machine KVM
6. Define the virtual machine disk image location
7. Disk size
6. Specify the bridge or multiple bridges.
7. Additional console and KS files
8. Connect to system parameters
     
Parameter description note: each line must contain spaces.
-N VM name
-R: VM memory size allocated
-- Vcpus: number of virtual CPUs allocated
-C image file location
-- Vnc -- vncport = 5901 -- vnclisten = 0.0.0.0
-- Virt-type virtual machine mode
-F virtual machine system file storage directory
-S: disk size allocated (GB)
-W networking mode (birdge bridge: br0/nat bridge: virbr0)
-- OS-type = 'windows' -- OS-variant = win2k3 it is best to add this to install windows. Otherwise, an error is reported.
After the virtual machine is installed using the virt-install tool, the xml configuration file is generated under the/etc/libvirt/qemu/directory.
-S is used to specify the size unit of the virtual disk as GB.
-M: specifies the hardware address of the virtual network card. virt-install is automatically generated by default.
-P: create a virtual machine in semi-virtualization mode
-L specify the installation source
-X EXTRA, -- extra-args = EXTRA attaches the kernel command line parameters to the installer when you execute the client installation from the specified location of the "-- location" option.
-V, -- hvm sets full virtualization

Virt-install -- name = centos6.3 -- ram 1024 -- vcpus = 2 -- disk path =/data0/centos-6.3.x86_64.img.img, size = 20 -- accelerate -- cdrom/data0/CentOS-6.3-x86_64-bin-DVD1.iso -- graphics vnc, listen = 0.0.0.0, port = 5920, -- network bridge = br0 -- force -- autostart

After Execution, netstat-nulpt | grep 5920 check whether the port is enabled

5. Use vnc connection 5920 to complete installation

IP: 5920

VI. Management of kvm virtual machines

Virsh -- connect qemu: // system
A. If you modify the xml file of a client (in the/etc/libvirt/qemu/directory), you must redefine the client:
Define/etc/libvirt/qemu/vm10.xml
B. Start and stop the client and run:
Start vm10
C. Stop a client and run
Shutdown vm10
D. Immediately interrupt a client (similar to power off) and run
Destroy vm10
E. Suspend a client:
Suspend vm10
F. Restore the client:
Resume vm10

VII. Clone

Virt-clone -- connect = qemu: // system \
-O original VM-n new VM-f/data0/centos5.4/new VM image

Note the following when creating a new virtual machine configuration file: After cloning the virtual machine, you must modify the vnc port and the MAC address.

8. Attach disk space

# Qemu-img create-f qcow2 disk1.img 50G
# Vi/etc/libvirt/qemu/centos1.xml

The added part is:
<Disk type = 'file' device = 'disk'>
<Driver name = 'qemu' type = 'qcow2 '/>
<Source file = '/root/disk3.img'/>
<Target dev = 'hdb' bus = 'ide '/>
<Address type = 'drive 'Controller = '0' bus = '0' target = '0' unit = '1'/>
</Disk>

Make the configuration file take effect
Virsh -- connect qemu: // system

Virsh # define/etc/libvirt/qemu/winxp. xml


Restart the VM to take effect

Virsh # shutdown centos1

Virsh # start centos1

Enter the VM:
Mkfs. ext3/dev/hdb
Mkdir/data
Mount/dev/hdb/data
Virt-install -- name xp1 -- hvm -- ram 512 -- vcpus 1 -- disk path =/root/xp1.img, size = 20 -- network: default -- accelerate -- vnc -- vncport = 5901 -- cdrom/root/xp. iso-d
Virt-install -- name = wintest01 -- ram 512 -- vcpus = 2 -- disk path =/data/wintest01.img, size = 8 -- accelerate -- cdrom/data/iso/Windows2003.iso -- vnc -- vncport = 5911 -- vnclisten = 0.0.0.0 -- network bridge = br0 -- force -- autostart
# Iso image file change
[[Email protected] ~] # Virsh change-media win3test hdc/home/iso/virtio-win-0.1-52.iso
Succeeded to complete action update on media
# Image file pop-up
[[Email protected] ~] # Virsh change-media win3test hdc -- eject
Format conversion
Qemu-img convert-f raw-O qcow2 disk2.img disk2.qcow2
-F source Image format
-O target Image format

This article from "Life is an attitude" blog, please be sure to keep this source http://sangh.blog.51cto.com/6892345/1573960

Centos6.3 install KVM

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.