在安装虚拟化环境的时候,首先查看下该服务器的硬件配置和环境,具体操作如下:
(一)检查硬件的相关情况:
1,查看cpu型号,物理cpu颗数,
1
2
3
4
5
|
[root@KVM ~]
# cat /proc/cpuinfo | grep name | cut -d: -f2 | uniq -c
2 Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
[root@KVM ~]
# cat /proc/cpuinfo | grep physical | sort -n | uniq -c
2 address sizes : 42 bits physical, 48 bits virtual
16 physical
id
: 0
###说明有一颗cpu,颗数是从0开始的
|
2,查看内存
1
2
3
4
5
|
[root@KVM ~]
# dmidecode|grep -A5 "Memory Device"|grep Size | cut -d: -f2 | sort -n | uniq -c
63 No Module Installed
63 1 kB
1 8 GB
1 8192 MB
###接了一根内存,每根内存的大小为8G
|
3,查看其它的相关参数:
1
2
3
4
5
|
[root@KVM ~]
# dmidecode | grep -A16 "Memory Device" | grep Speed | sort -n | uniq -c
64 Speed: Unknown
[root@KVM ~]
# dmidecode|grep 'Maximum Capacity'
Maximum Capacity: 1 TB
[root@KVM ~]
#
|
(二)安装kvm
1,查看服务器是否支持虚拟化
[root@KVM ~]# grep -E -o 'vmx|svm' /proc/cpuinfo
vmx
2,安装kvm软件包
1
|
[root@KVM ~]
# yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v
|
3,安装kvm虚拟化管理工具包
1
|
[root@KVM ~]
# yum install libguestfs-tools -y
|
4,查看虚拟机的相关环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@KVM ~]
# /etc/init.d/libvirtd restart
Stopping libvirtd daemon: [ OK ]
Starting libvirtd daemon: [ OK ]
[root@KVM ~]
# virsh -c qemu:///system list
Id Name State
----------------------------------------------------
1 hadoop4 running
[root@KVM ~]
# virsh --version ###查看虚拟机的版本
0.10.2
[root@KVM ~]
# virt-install --version ###查看虚拟机工具的版本
0.600.0
[root@KVM ~]
# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@KVM ~]
# qemu-kvm -version
QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2-2.479.el6_7.3), Copyright (c) 2003-2008 Fabrice Bellard
[root@KVM ~]
#
|
5,手动创建虚拟网桥:
a,首先NetworkManager服务:
[root@KVM network-scripts]# /etc/init.d/NetworkManager status
NetworkManager (pid 1132) is running...
[root@KVM network-scripts]# /etc/init.d/NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@KVM network-scripts]# /etc/init.d/NetworkManager status
NetworkManager is stopped
[root@KVM network-scripts]# chkconfig NetworkManager off
b,创建br0网桥:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@KVM network-scripts]
# cp ifcfg-eth0 ifcfg-br0
[root@KVM network-scripts]
# vi ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
NM_CONTROLLED=
"no"
ONBOOT=
yes
TYPE=Ethernet
BRIDGE=br0
IPADDR=10.1.156.201
PREFIX=24
GATEWAY=10.1.156.1
DNS1=10.1.156.1
DNS2=114.114.114.114
DEFROUTE=
yes
IPV4_FAILURE_FATAL=
yes
IPV6INIT=no
NAME=Systemeth0
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@KVM network-scripts]
# vi ifcfg-br0
DEVICE=br0
HWADDR=00:0C:29:75:92:CF
TYPE=Bridge
ONBOOT=
yes
BOOTPROTO=static
IPADDR=10.1.156.200
NETMASK=255.255.255.0
GATEWAY=10.1.156.1
DNS1=10.1.156.1
DNS2=114.114.114.114
|
c,关闭了networkmanager服务之后,才能通过service networkrestart管理网络
1
2
3
4
5
6
7
8
|
[root@KVM ~]
# /etc/init.d/network restart
Shutting down interface br0: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface br0: Determining
if
ip address 10.1.156.200 is already
in
use
for
device br0...
[ OK ]
|
d,查看网桥br0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
[root@KVM ~]
# ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:75:92:CF
inet addr:10.1.156.200 Bcast:10.1.156.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe75:92cf
/64
Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:181 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:17908 (17.4 KiB) TX bytes:3068 (2.9 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:75:92:CF
inet6 addr: fe80::20c:29ff:fe75:92cf
/64
Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:183 errors:0 dropped:0 overruns:0 frame:0
TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20562 (20.0 KiB) TX bytes:3396 (3.3 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:1033 errors:0 dropped:0 overruns:0 frame:0
TX packets:1033 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:62322 (60.8 KiB) TX bytes:62322 (60.8 KiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:F1:6D:D1
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)
vnet0 Link encap:Ethernet HWaddr FE:54:00:FE:F5:A3
inet6 addr: fe80::fc54:ff:fefe:f5a3
/64
Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:31517 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 b) TX bytes:1639040 (1.5 MiB)
|
e,查看网桥
1
2
3
4
5
|
[root@KVM ~]
# brctl show
bridge name bridge
id
STP enabled interfaces
br0 8000.000c297592cf no eth0
virbr0 8000.525400f16dd1
yes
virbr0-nic
vnet0
|
kvm环境安装完成。
本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1740516