KVM installation and configuration for Centos 6

Source: Internet
Author: User
Tags svm testdisk


KVM Installation and Configuration

Host Environment: Centos 6.6


Recently playing KVM, a little summary.


1. Check whether the CPU is supported


KVM requires CPU support (Intel VT or AMD SVM) to check if the CPU provides support for virtual technology before installing KVM:

# egrep ' VMX|SVM '/proc/cpuinfo

# Modprobe-ls | grep KVM #查看内核是否开启

Kernel/arch/x86/kvm/kvm.ko

Kernel/arch/x86/kvm/kvm-intel.ko

Kernel/arch/x86/kvm/kvm-amd.ko

#/USR/LIBEXEC/QEMU-KVM-CPU? #查看kvm可以虚拟的CPU


Note: If VMware is installed, you need to turn on the processor Intel VT or AMD SVM, in a way Google


2. Confirm the shutdown of SELinux


# Vi/etc/sysconfig/selinux

Selinux=disabled


3. Installing KVM


# yum-y Install QEMU-KVM libvirt python-virtinst bridge-utils


4. Confirm KVM Installation Success

# Lsmod | grep KVM

# STAT/DEV/KVM


5. Start LIBVIRTD (Virtualization Toolkit Service)


/ETC/INIT.D/LIBVIRTD start


6, create hard disk files (find a lot of online materials do not have this step)


# qemu-img Create-f Qcow2/opt/guest01.qcow2 20G


7. Install the virtual machine


First, modify the qemu.conf configuration, remove the comments from the following places, and then change the value of Dynamic_ownership to 0, prohibit LIBVIRTD dynamic change the attribution of the file, otherwise it will error "Permission denied"

# vi/etc/libvirt/qemu.conf

...

user = "Root"

Group = "Root"

dynamic_ownership = 0

...


Default network mode installation

# virt-install--VIRT-TYPE=KVM--name=guest01--os-type=linux--ram=2048--vcpus=2--disk path=/opt/guest01.qcow2, Format=qcow2--network network=default--graphics vnc,listen=0.0.0.0--cdrom=/root/centos-6.7-x86_64-bin-dvd1.iso-- Noautoconsole


Bridging Network mode installation


Reference connection: https://www.chenyudong.com/archives/libvirt-kvm-bridge-network.html


# virt-install--VIRT-TYPE=KVM--name=guest01--os-type=linux--ram=2048--vcpus=2--disk path=/opt/guest01.qcow2, Format=qcow2--network bridge=br0--graphics vnc,listen=0.0.0.0--cdrom=/root/centos-6.7-x86_64-bin-dvd1.iso-- Noautoconsole


8, VNC client Login server, installation system can


Access: ip:5900 (typically the first virtual machine access port is 5900 and can be viewed through NETSTAT-TNLP)

VNC reference Download Connection: http://www.tightvnc.com/download.php


Attention:

1, the DNS to configure, or can not access the URL

2, disk mount to confirm, and sometimes after the partition started to mount



Add three important commands:

qemu-img Command:

Create a hard disk file

Create [-F hard disk format] [-O options] < path and file name > [Space size]

Example: Advantages of qemu-img create-f raw/tmp/testdisk.raw 10G//raw format:

One, simple addressing, high access efficiency

Second, can be easily converted to other formats through the Format conversion tool

Third, can be conveniently mounted, can directly carry out data transmission disadvantage: compression, snapshot, encryption and cow features are not supported, and is immediately occupied space

Example: Qemu-img create-f qcow2/tmp/testdisk.qcow2 10G

Convert hard Disk File format

convert [-c] [-p] <-f original format > <-o new format > < original file > < new file >//-c Cow class Format use-p to view progress

Example: Qemu-img convert-c-F raw-o qcow2/tmp/testdisk.raw/tmp/testdisk.qcow2

Create VIEW recovery hard disk File snapshot

Snapshot < Parameters > < original file >//Common parameters:-C < snapshot name > (create snapshot)-a < snapshot name > (recover snapshot)-D < snapshot name > (delete snapshot)-L (list snapshot)

Example: qemu-img snapshot-c newkuaizhao/tmp/testdisk.qcow2//Create a snapshot of Newkuaizhao for Testdisk.qcow2

Viewing hard disk File information

info [-F hard drive format] [--OUTPUT=OFMT] < path and file name >

Example: Qemu-img Info/tmp/testdisk.raw

Viewing hard disk files for errors

Check [-F hard drive format] < path and file name >

Example: Qemu-img Check/tmp/testdisk.raw

Change the size of the hard disk file space (production environment is not recommended, use must also establish a backup of the original file, need to add the partition tool to use)

Resize < path and filename > <+ | -Space Size >

Example: Qemu-img resize/tmp/testdisk.raw +1g



virt-install Command common options:

What type of virtualization is used by--VIRT-TYPE=KVM: (KVM, QEMU, Xen, ...)

--name= Virtual machine Name

--os-type=linux system type: ' Linux ', ' Unix ', ' windows '

--ram=1024 Memory Size M units

--network bridge=mybr0

--disk Path=/my/existing/disk Specifying disk files

--cdrom=/tmp/centos6.6.iso Specifying system image files

--graphics=graphics Turn on graphical configuration

Configure guest display settings. Ex:

--graphics VNC

--graphics spice,port=5901,tlsport=5902

--graphics None

--graphics Vnc,password=foobar,port=5910,keymap=ja

--noautoconsole The virtual machine console is not automatically connected

Example: Virt-install--virt-type=kvm--name=kvmtest--os-type=linux--ram=1024--disk path=/root/kvmsys02.qcow2,format= Qcow2--network network=default--graphics vnc,listen=0.0.0.0--cdrom=/tmp/centos-6.6-x86_64-bin-dvd1.iso-- Noautoconsole


Virsh Command

Start < virtual machine name > #启动虚拟机

Shutdown < virtual machine name > #关闭虚拟机

Destroy < virtual machines > #强制关闭虚拟机

Reboot < virtual machine name > #重启虚拟机

Suspend < virtual machines > #暂停虚拟机

Resume < virtual machines > #恢复暂停的虚拟机

Save < Virtual machines > < files > #把虚拟机当前状态保存到快照文件中

Restore < snapshot files > #从以前保存的快照中恢复虚拟机

list [options] #列出虚拟机 common options--all

Dumpxml < virtual machines > [>xml file] #导入XML配置文件

Define < virtual machine XML file > #从XML文件创建一个虚拟机如果有相同的需改内容: Virtual machine name, UUID, disk file, Nic Mac.

Undefine < virtual machines > #删除与虚拟机相关的所有文件

Migrate #迁移虚拟机 recommended direct CP hard disk File Dumpxml export XML file

Memory:

Setmem < virtual machines > < memory size > #给虚拟机设置内存大小

Setmaxmem < virtual machines > < memory size > #给虚拟机设置最大使用内存大小

Cpu:

Setvcpus < virtual machines > < qty > #给虚拟机设置虚拟CPU数量

Vcpuinfo < virtual machines > #显示虚拟机虚拟CPU信息

Vcpupin < virtual machines > #控制虚拟机虚拟CPU亲和性

Disk discs, etc.:

Attach-disk < virtual machines > < disk files > < mount device names > [--live] [--config] #添加磁盘设备 mount device name: such as SDA, SDB, etc.--live add disk to a running virtual machine-- Config next reboot also takes effect

Example: Virsh attach-disk kvmtest3/tmp/testdisk3-2.raw sdb--live--config

Detach-disk < virtual machine > < mount device name > [--live] #删除磁盘设备 mount device name: such as SDA, SDB, etc.--live adding disks to a running virtual machine

Domblklist < virtual machines > #显示虚拟机块设备

Change-media < virtual machine > < optical drive device > [< disc file;] #详细操作参看更换光盘

Card:

Attach-interface < virtual machine > < virtual network card mode > < mail Host network card file > [--model nic mode] [--config] #添加网卡设备 Virtual network card mode: such as bridge, network, etc. Network card mode: such as Virtio and other--config the next reboot also takes effect

Detach-interface < virtual machine > < virtual network card mode > [--mac <string>] #卸载网卡设备

Example: Virsh detach-interface kvmtest3--type Bridge--mac 52:54:00:37:d1:8a

Domiflist < virtual machines > #显示虚拟机网卡设备信息

Domif-setlink < virtual machine > < virtual machine Internal network card device name > <up start or Down > [--config] #启动或关闭网卡设备--config next reboot also takes effect

Domif-getlink < virtual machine > < virtual machine nic device name > #查看网卡状态




This article is from the "Hades Blog" blog, please be sure to keep this source http://hades02.blog.51cto.com/9768670/1868235

KVM installation and configuration for Centos 6

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.