KVM虚拟化环境安装

发布 : 2016-09-08 分类 : kvm

KVM虚拟化环境安装

1.操作系统平台

[root@SZ-P-L-KVM-18 ~]# cat /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m

2.服务器硬件信息

2.1.CPU型号

[root@SZ-P-L-KVM-18 ~]# cat /proc/cpuinfo | grep name | cut -d: -f2 | uniq -c
24 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz

2.2.物理CPU颗数

[root@SZ-P-L-KVM-18 ~]# cat /proc/cpuinfo | grep physical | sort -n | uniq -c
24 address sizes : 46 bits physical, 48 bits virtual
12 physical id : 0
12 physical id : 1

2.3.内存

[root@SZ-P-L-KVM-18 ~]# dmidecode|grep -A5 "Memory Device"|grep Size | cut -d: -f2|sort -n |uniq -c
16 No Module Installed
8 8192 MB

[root@SZ-P-L-KVM-18 ~]# free -m
total used free shared buffers cached
Mem: 64377 660 63716 0 12 66
-/+ buffers/cache: 581 63795
Swap: 65535 0 65535

3.关闭Selinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config  
setenforce 0

4.添加主机名到host文件

[root@SZ-P-L-KVM-18 ~]# echo "127.0.0.1 SZ-P-L-KVM-18" >> /etc/hosts

5.查看服务器是否支持虚拟化


[root@SZ-P-L-KVM-18 ~]# grep -E -o 'vmx|svm' /proc/cpuinfo | head -n 1
vmx

6.安装kvm软件包

yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer  virt-v2v

7.安装kvm虚拟化管理工具包

yum  -y install  libguestfs-tools

8.查看版本

[root@SZ-P-L-KVM-18 ~]# virsh --version 
0.10.2

[root@SZ-P-L-KVM-18 ~]# virt-install --version
0.600.0

[root@SZ-P-L-KVM-18 ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@SZ-P-L-KVM-18 ~]# qemu-kvm -version
QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2-2.503.el6_9.5), Copyright (c) 2003-2008 Fabrice Bellard

9.查看kvm模块

[root@SZ-P-L-KVM-18 ~]# lsmod | grep kvm
kvm_intel 55432 0
kvm 346318 1 kvm_intel

10.启用libvirtd服务

[root@SZ-P-L-KVM-18 ~]# chkconfig libvirtd on

[root@SZ-P-L-KVM-18 ~]# /etc/init.d/libvirtd restart
Stopping libvirtd daemon: [ FAILED ]
Starting libvirtd daemon: [ OK ]

10.配置虚拟网卡

新建虚拟网卡: /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPV6INIT=no
ONBOOT=yes
IPADDR=192.168.100.18
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
DNS1=114.114.114.114
DELAY=0

11.本机网卡配置

/etc/sysconfig/network-scripts/ifcfg-em1
增加 BRIDGE=br0

DEVICE=em1
HWADDR=F0:1F:AF:D1:36:0E
TYPE=Ethernet
UUID=112c1a6b-3a42-43c1-a75f-77566c7af8e0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.100.18
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
DNS1=114.114.114.114
BRIDGE=br0

12.重启网卡

/etc/init.d/network restart

查看网卡信息

[root@SZ-P-L-KVM-18 ~]# ifconfig 
br0 Link encap:Ethernet HWaddr F0:1F:AF:D1:36:0E
inet addr:192.168.100.18 Bcast:192.168.6.255 Mask:255.255.255.0
inet6 addr: fe80::f21f:afff:fed1:360e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:245 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26130 (25.5 KiB) TX bytes:3508 (3.4 KiB)

em1 Link encap:Ethernet HWaddr F0:1F:AF:D1:36:0E
inet6 addr: fe80::f21f:afff:fed1:360e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:238 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:29658 (28.9 KiB) TX bytes:3254 (3.1 KiB)
Interrupt:35

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:65536 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:33:9A:C1
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: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)

13.查看桥接网络

[root@SZ-P-L-KVM-18 ~]# brctl show 
bridge name bridge id STP enabled interfaces
br0 8000.f01fafd1360e no em1
virbr0 8000.525400339ac1 yes virbr0-nic

14.查看虚拟主机

[root@SZ-P-L-KVM-18 ~]# virsh list --all (或使用 virsh -c qemu:///system list )
Id Name State
----------------------------------------------------
*还没安装虚拟机,所以现在列表是空的。

15.使用virt-manager图形界面管理安装虚拟机

15.1.安装X-window

yum -y install libXdmcp libXmu libxkbfile xkeyboard-config xorg-x11-xauth xorg-x11-xkb-utils

15.2.解决乱码问题

yum -y install dejavu-sans-mono-fonts

15.3.开启sshd的X11转发

[root@SZ-P-L-KVM-18 ~]# grep "X11Forwarding yes" /etc/ssh/sshd_config 
X11Forwarding yes

15.4.进入图形界面

[root@SZ-P-L-KVM-18 ~]# virt-manager
本文作者 : 泽泽
原文链接 : http://www.linuxhub.cn/2016/09/08/install-kvm.html
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹