KVM安装配置

1.安装epel包:

 [root@node124mnt]# rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm  

yum makecache

 

++++++++++++++++++++++++++++++++++++++

查看CPU是否支持虚拟化:(打开vmware CPU虚拟化功能)

vmx似乎是intel的虚拟技术代名词

svm似乎是amd的虚拟技术代名词

如果你在将kvm的模块加载的时候出现如下现象

#cat /proc/cpuinfo | egrep -c '(vmx|svm)'

[root@node123 ~]# cat /proc/cpuinfo | egrep -c'(vmx|svm)'

2

0 表示不支持大于1 表示支持。

#modprobe kvm-intel

正常情况下

[root@node124 opt]# lsmod | grep kvm*

kvm_intel             55624  0

kvm                  341551  1 kvm_intel

不支持的情况

FATAL: Error inserting kvm_intel(/lib/modules/2.6.17-10-generic/extra/kvm-intel.ko): Operation not supported

那么只有两个可能

1:CPU不支持 (是否支持要 more/proc/cpuinfo,找找vmx或者svm)

2:Bios给关了.(去打开吧,如果看到了)

3.vmx文件中没有开启vhv.enable = "TRUE"

workstation上实现嵌套虚拟化需要编辑虚拟机的主机名.vmx 文件

在文件中添加或修改:

vhv.enable = "TRUE"

VMWARE调整如下:

参考KB如下(Additional Information部分)

http://kb.vmware.com/kb/2034803

++++++++++++++++++++++++++++++++++++++++++

2,安装虚拟化工具:

yum install qemu-kvm qemu-kvm-tools  virt-managerlibvirt

        qemu-kvm  qemu-kvm-tools:qemu工具用于管理KVM

        virt-manager:创建虚拟机

        libvirt:      用于创建虚拟机与管理

3.创建虚拟机硬盘:

#qemu-img create -f raw /opt/CentOS-6.7_x86_64.raw 5G

查看创建的硬盘:

#file /opt/CentOS-6.7_x86_64.raw

#qemu-img    info/opt/CentOS-6.7_x86_64.raw

4.创建光盘镜像:

#dd if=/dev/cdrom of=/opt/CentOS-6.7-x86_64.iso

5.创建虚拟机

[root@node124 opt]# virt-install--virt-type=kvm --name CentOS-6.7-x86_64 --ram 512--cdrom=/opt/CentOS-6.7_x86_64.iso --disk path=/opt/CentOS-6.7_x86_64.raw--network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole--os-type=linux --os-variant=rhel6

Starting install...

Creating domain...                                                                                        |    0 B     00:00    

Domain installation still in progress. You canreconnect to

the console to complete the installation process.

6.通过VNC安装虚拟机:

软件:tightvnc2.7.10.exe       ip地址为宿主机网卡接口IP

7.查看已安装虚拟机列表:

#virsh list --all

[root@node124 opt]# virsh list --all

 Id    Name                           State

----------------------------------------------------

 2     CentOS-6.7-x86_64              running

 

8.如果名称被定义,则通过以下命令取消定义:

#virsh undefine CentOS-6.7-x86_64

 

9.查看连接状态(查看VNC端口5900)

[root@node124 opt]# netstat -ntlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp       0      0 0.0.0.0:55687               0.0.0.0:*                   LISTEN     1556/rpc.statd     

tcp       0      0 0.0.0.0:5900                0.0.0.0:*                   LISTEN      2934/qemu-kvm 

10.查看kvm进程

#ps aux | grep kvm

qemu      293443.8 28.9 2128088 552808 ?      Sl   22:28  2:10 /usr/libexec/qemu-kvm -name CentOS-6.7-x86_64 -S -M rhel6.6.0-enable-kvm -m 512 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid326e3810-fd4d-5012-f6f7-cff369870ccd -nodefconfig -nodefaults -chardevsocket,id=charmonitor,path=/var/lib/libvirt/qemu/CentOS-6.7-x86_64.monitor,server,nowait-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-reboot-no-shutdown -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x4.0x7 -deviceich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4 -deviceich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x4.0x1 -deviceich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x4.0x2 -drivefile=/opt/CentOS-6.7_x86_64.raw,if=none,id=drive-virtio-disk0,format=raw,cache=none-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=2-drivefile=/opt/CentOS-6.7_x86_64.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw-device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1-netdev tap,fd=22,id=hostnet0,vhost=on,vhostfd=23 -devicevirtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:37:e2:fa,bus=pci.0,addr=0x3-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0-device usb-tablet,id=input0 -vnc 0.0.0.0:0 -vga cirrus -devicevirtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on

 

启动已停止的虚拟机:

[root@node124 ~]# virsh list

 Id    Name                           State

----------------------------------------------------

 

[root@node124 opt]# virsh list --all

 Id    Name                           State

----------------------------------------------------

 -     CentOS-6.7-x86_64              shut off

 

[root@node124 opt]# virsh start CentOS-6.7-x86_64

Domain CentOS-6.7-x86_64 started

 

查看已安装虚拟机的XML配置文件:路径在:/etc/libvirt/qemu

[root@node124 qemu]# ls

CentOS-6.7-x86_64.xml networks

[root@node124 qemu]# pwd

/etc/libvirt/qemu

[root@node124 qemu]# cat CentOS-6.7-x86_64.xml

<!--

WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO ITARE LIKELY TO BE

OVERWRITTEN AND LOST. Changes to this xmlconfiguration should be made using:

  virsh editCentOS-6.7-x86_64

or other application using the libvirt API.

-->

默认修改这个文件将不会在虚拟机生效,不管重启或不重启

但可以通过以下的方式来使这个配置文件修改后就生效:

1.cp CentOS-6.7-x86_64.xml  /opt/CentOS-6.7-x86_64.xml

2.virsh undefine CentOS-6.7-x86_64

3.virsh define /opt/CentOS-6.7-x86_64.xml           #相当于重新创建一台虚拟机,kvm是通过.xml来管理虚拟机的

 

最好通过virsh edit CentOS-6.7-x86_64 来编辑虚拟机,前题是虚拟机是关闭状态

 

.xml文件是重新的虚拟机文件,如果这个文件不存在,虚拟机也就不存在了

 

 

内存优化

[root@node124 qemu]# cat/sys/kernel/mm/transparent_hugepage/enabled

[always] madvise never

[root@node124 qemu]# ps aux | grep ksm

root        47  0.0 0.0      0     0 ?       SN   22:02   0:00 [ksmd]

root      1914  0.0 0.0 108208   776 ?        S   22:02   0:00 /bin/bash/usr/sbin/ksmtuned

root     4029  0.0  0.0 103312  852 pts/2    S+   23:28  0:00 grep ksm

 

虚拟机的大小不能超过实体机的所有资源的总和

 

 

 

 

 

 

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS