为了在一台服务器上虚拟出多个Ubuntu server,用于集群。考虑了几个方案,Vmware因为价格被排除,VirtualBox不错,不过KVM由于是Linux内核层的,性能更好。优先考虑使用。
首先在一台实验机器上安装Ubuntu 12.04 amd64 server。升级系统补丁以及内核。hostname是kvmhost. IP是10.112.18.177. 主板上已经打开了虚拟化功能。
好。现在开始安装kvm。
sudo -s 切换到root权限。
用下面的命令检查cpu是否支持虚拟化:
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 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
现在安装kvm和kvmbuilder脚本。这个脚本用来创建基于Ubuntu的虚拟机。
apt-get install ubuntu-virt-server python-vm-builder kvm-ipxe
adduser `id -un` libvirtd adduser `id -un` kvm
运行下面的命令检查kvm是否安装成功。
root@kvmhost:~# virsh -c qemu:///system list Id Name State ----------------------------------没有错误信息。安装没问题。
下面设置网络,保证网络中的其他主机能够访问到kvm管理的虚拟机。
可能需要安装bridge-utils,我的实验机安装完操作系统的时候已经有了。没有的运行命令:
apt-get install bridge-utils
# 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 auto eth0 iface eth0 inet dhcp
# 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 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
/etc/init.d/networking restart
然后检查一下网络配置
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) 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
重新登录上去。第一部分结束。
文章出处:http://blog.csdn.net/csfreebird/article/details/8010040