Ubuntu12.04下安裝kvm
為了在一臺服務器上虛擬出多個Ubuntu server,用于集群??紤]了幾個方案,Vmware因為價格被排除,VirtualBox不錯,不過KVM由于是
Linux內核層的,性能更好。優(yōu)先考慮使用。
www.
首先在一臺實驗機器上安裝Ubuntu 12.04 amd64 server。升級系統(tǒng)補丁以及內核。hostname是kvmhost. IP是10.112.18.177. 主板上已經(jīng)打開了虛擬化功能。
好?,F(xiàn)在開始安裝kvm。
sudo -s 切換到root權限。
用下面的命令檢查cpu是否支持虛擬化:
[plain]
root@kvmhost:~# egrep '(vmx|svm)' --color=always /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm dts tpr_shadow vnmi flexpriority ept vpid www.
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm dts tpr_shadow vnmi flexpriority ept vpid
什么都不顯示的話,就不能玩了。還好,我可以繼續(xù)了。
現(xiàn)在安裝kvm和kvmbuilder腳本。這個腳本用來創(chuàng)建基于Ubuntu的
虛擬機。
[plain]
apt-get install ubuntu-virt-server python-vm-builder kvm-ipxe
將當前用戶加入到kvm和libvirtd組
[plain]
adduser `id -un` libvirtd
adduser `id -un` kvm
www.
退出后,再登錄。
運行下面的命令檢查kvm是否安裝成功。
[plain]
root@kvmhost:~# virsh -c qemu:///system list
Id Name State
----------------------------------
沒有錯誤信息。安裝沒問題。
下面設置網(wǎng)絡,保證網(wǎng)絡中的其他主機能夠訪問到kvm管理的虛擬機。
可能需要安裝bridge-utils,我的實驗機安裝完操作系統(tǒng)的時候已經(jīng)有了。沒有的運行命令:
[plain]
apt-get install bridge-utils
編輯/etc/network/interface文件,編輯前我的文件如下:
[plain]
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
www.
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
修改為:
[plain]
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface (disable)
#auto eth0
#iface eth0 inet dhcp
# The primary network interface for kvm
auto eth0
iface eth0 inet manual
www.
auto br0
iface br0 inet static
address 10.112.18.177
network 10.112.18.0
netmask 255.255.255.0
broadcast 10.112.18.255
gateway 10.112.18.1
dns-nameservers 8.8.8.8 8.8.4.4
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
重新啟動網(wǎng)絡服務
/etc/init.d/networking restart
www.
然后檢查一下網(wǎng)絡配置
[plain]
root@kvmhost:/etc/network# ifconfig
br0 Link encap:Ethernet HWaddr d0:67:e5:ef:5a:0a
inet addr:10.112.18.177 Bcast:10.112.18.255 Mask:255.255.255.0
inet6 addr: fe80::d267:e5ff:feef:5a0a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:58 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5961 (5.9 KB) TX bytes:3662 (3.6 KB)
eth0 Link encap:Ethernet HWaddr d0:67:e5:ef:5a:0a
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:67318 errors:0 dropped:0 overruns:0 frame:0
TX packets:33515 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:91560174 (91.5 MB) TX bytes:2626976 (2.6 MB)
Interrupt:17
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: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)
www.
virbr0 Link encap:Ethernet HWaddr 56:21:fd:02:02:35
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST 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)
重新啟動計算機.
reboot