[[PageOutline]]
{{{
#!html
KVM + OpenNebula = Virtual Cluster Deployment
}}}
----
= 【系統環境】 =
* 硬體資源
|| || '''CPU''' ||'''Memory''' || '''Disk''' ||
|| '''Version''' || Intel(R) Core(TM)2 Quad CPU Q9400 @ 2.66GHz || 8GB || 1TB ||
* 軟體資源
|| Host/dom0 OS || Debian GNU/Linux testing (squeeze) (64bit) ||
|| KVM || 72+dfsg-5+squeeze1 ||
|| VM/Guest/dmoU OS || MS Windows XP & Debian lenny (AMD64) ||
|| !OpenNebula || 1.4.0 ||
----
= 【Step 1: 檢查 KVM 及其所需要環境】 =
* 請先確認 CPU 有支援 (Intel vmx 或 AMD svm 指令集)
{{{
$ egrep '(vmx|svm)' --color=always /proc/cpuinfo
}}}
* kvm-intel 是給 Intel CPU,kvm-amd 是給 AMD CPU
{{{
$ sudo modprobe -l | grep kvm
kernel/arch/x86/kvm/kvm.ko
kernel/arch/x86/kvm/kvm-intel.ko
kernel/arch/x86/kvm/kvm-amd.ko
}}}
----
= 【Step 2: 安裝 KVM 及其所需要的套件並載入模組】 =
* 只需一行指令即可安裝KVM及其所需相關工具
{{{
$ sudo apt-get install kvm qemu-kvm bridge-utils libvirt-bin virtinst vtun virt-manager
}}}
* 載入 KVM module for Intel Chip
{{{
$ sudo modprobe kvm-intel
}}}
----
= 【Step 3: 安裝 OpenNebula 及其所需要的套件】 =
* '''pcX''' 和 '''pcY''' 須安裝相關套件
{{{
$ sudo aptitude install g++ ruby libsqlite3-0 sqlite3 libsqlite3-dev \
libsqlite3-ruby libxmlrpc-c3-dev libxmlrpc-c3 libssl-dev scons
}}}
----
= 【Step 4: 下載並安裝OpenNEbula】 =
* 在 pcX 上執行 (OpenNEbula 只需安裝在 pcX 上)
* 下載 source code
{{{
$ cd
$ wget http://dev.opennebula.org/attachments/download/103/one-1.4.0.tar.gz
$ tar zxvf one-1.4.0.tar.gz
}}}
* 編譯和安裝 OpenNEbula
{{{
$ cd one-1.4
$ sudo scons
$ sudo mkdir /home/one
$ sudo ./install.sh -d /home/one
}}}
* 編輯 OpenNEbula 路徑
{{{
$ sudo su
# echo export ONE_LOCATION=/home/one >> ~/.bashrc
# echo export ONE_XMLRPC="http://localhost:2633/RPC2" >> ~/.bashrc
# echo export PATH='$ONE_LOCATION/bin:$PATH' >> ~/.bashrc
# echo export ONE_AUTH=/home/one/.one/one_auth >> ~/.bashrc
# mkdir /home/one/.one
# echo "root:cloud123" >> /home/one/.one/one_auth
# source ~/.bashrc
# echo $ONE_AUTH
(測試 $ONE_AUTH 路徑是否存在)
# echo $ONE_LOCATION
(測試 $ONE_LOCATION 路徑是否存在)
}}}
----
= 【Step 5: 編輯 ONE 設定檔】 =
* 在 pcX 上編輯,將 151~154 行註解掉,打開 159~162 行
{{{
# cd /home/one
# gedit etc/oned.conf
}}}
{{{
#!sh
21 HOST_MONITORING_INTERVAL = 5
23 VM_POLLING_INTERVAL = 10
62 #IM_MAD = [
63 # name = "im_xen",
64 # executable = "one_im_ssh",
65 # arguments = "im_xen/im_xen.conf" ]
70 IM_MAD = [
71 name = "im_kvm",
72 executable = "one_im_ssh",
73 arguments = "im_kvm/im_kvm.conf" ]
106 #VM_MAD = [
107 # name = "vmm_xen",
108 # executable = "one_vmm_xen",
109 # default = "vmm_xen/vmm_xen.conf",
110 # type = "xen" ]
115 VM_MAD = [
116 name = "vmm_kvm",
117 executable = "one_vmm_kvm",
118 default = "vmm_kvm/vmm_kvm.conf",
119 type = "kvm" ]
151 # TM_MAD = [
152 # name = "tm_ssh",
153 # executable = "one_tm",
154 # arguments = "tm_ssh/tm_ssh.conf" ]
159 TM_MAD = [
160 name = "tm_nfs",
161 executable = "one_tm",
162 arguments = "tm_nfs/tm_nfs.conf" ]
}}}
----
= 【Step 6: 啟動 ONE】 =
* 啟動 ONE 前的小叮嚀:
1. 確認 pcXXX 和 pcYYY 已執行 '''xend start'''
2. 兩台都可讓 '''root 免密碼 ssh 登入'''
{{{
// pcX (Server) 上執行
# ssh-keygen
# cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
# scp -r ~/.ssh pcY:~
//測試 ssh免密碼登入
ssh pcY
[CTRL+D]
}}}
3. 只需在 '''pcX''' 啟動 ONE 即可
* 在 pcX 上執行
{{{
# one start
}}}
----
= 【Step 7: 新增 pcX 和 pcY 到 ONE Pool】 =
* 在 pcX 上執行 (__X 和 Y 請自行修改成自己的電腦名稱__)
{{{
# onehost add pcX im_kvm vmm_kvm tm_nfs
# onehost add pcY im_kvm vmm_kvm tm_nfs
# onehost list
HID NAME RVM TCPU FCPU ACPU TMEM FMEM STAT
1 pcX 0 400 399 400 1313856 0 on
2 pcY 0 400 399 400 1313856 0 on
# onehost show pcX
}}}
* '''''onehost list'''''參數說明
* RVM - Number of running VMs
* TCPU - Total CPU
* FCPU - Free CPU
* ACPU - Available CPU (not allocated by VMs)
* TMEM - Total Memory
* FMEM - Free Memory
----
= 【Step 8: 製作 VM Image - 以 Microsoft Windows XP 為例】 =
* 產生一個 10GB 的 QEMU disk image format 的檔案
{{{
$ sudo qemu-img create -f qcow2 xp.img 10G
}}}
* 讀取光碟檔並開啟虛擬機器來安裝XP (10GB硬碟空間 & 1GB記憶體大小)
{{{
$ sudo qemu-system-x86_64 -cdrom /home/clouder/xp.iso -hda xp.img -boot d -m 1024 -localtime -net nic -net tap
}}}
* 開啟虛擬機器 (10GB硬碟空間 & 1GB記憶體大小)
{{{
$ sudo qemu-system-x86_64 -hda xp.img -m 1024 -net nic -net tap
}}}
== 製作 VM Image - 以 Debian 為例 ==
* 產生一個 10GB 的 QEMU disk image format 的檔案
{{{
$ sudo qemu-img create -f qcow2 deb.img 10G
}}}
* 下載 Debian-5.0 ISO file
{{{
$ wget http://cdimage.debian.org/debian-cd/5.0.6/amd64/iso-cd/debian-506-amd64-CD-1.iso
}}}
* 讀取光碟檔並開啟虛擬機器來安裝Debian (10GB硬碟空間 & 1GB記憶體大小)
{{{
$ sudo qemu-system-x86_64 -cdrom /home/clouder/debian-506-amd64-CD-1.iso -hda deb.img -boot d -m 1024 -localtime -net nic -net tap
}}}
* 開啟虛擬機器 (10GB硬碟空間 & 1GB記憶體大小)
{{{
$ sudo qemu-system-x86_64 -hda deb.img -m 1024 -net nic -net tap
}}}
----
= 【Step 9: 使用 ONE 來開啟 VM】 =
* 在 pcX 上執行
* 編輯 xp 的設定檔 (__X 和 Y 請自行修改成自己的電腦名稱__)
{{{
# cd /home/domains
# gedit xp.one
}}}
{{{
#!sh
NAME = xp
CPU = 1
MEMORY = 1024
OS = [ boot = hd ]
DISK = [ source = /var/lib/libvirt/images/xp.img,
clone = no,
target = hda,
readonly = no ]
GRAPHICS = [ type ="sdl",
listen ="127.0.0.1",
port = "5901" ]
}}}
* 使用 ONE 來開啟虛擬機器 xp
{{{
# onevm create xp.one ; onevm deploy xp pcX
# onevm list
ID NAME STAT CPU MEM HOSTNAME TIME
1 xp runn 0 131072 pcX 00 00:04:21
# onevm show xp
}}}
* onevm list 的資訊
* ID ONE VM identifier
* NAME Name of the ONE
* STAT Status of the VM
* CPU CPU percentage used by the VM
* MEM Memory used by the VM
* HOSTNAME Host where the VM is being or was run
* TIME Time since the submission of the VM (days hours:minutes:seconds
= 【Reference】 =
* [http://www.linux-kvm.org KVM 官網]
* [https://help.ubuntu.com/community/KVM KVM (Ubuntu)]
* 支援
* [http://www.linux-kvm.org/page/Guest_Support_Status KVM Guest 支援狀況]
* [http://www.linux-kvm.org/page/Host_Support_Status KVM Host 支援狀況]
* 安裝
* [http://www.linux-kvm.org/page/HOWTO1 KVM 官網安裝]
* [http://www.howtoforge.com/virtualization-with-kvm-on-a-debian-lenny-server Virtualization With KVM On A Debian Lenny Server]
* 工具
* [http://virt-manager.et.redhat.com/ Virtual Machine Manager]
* Network
* [http://cha.homeip.net/blog/archives/2009/04/fedora_kvm_brid.html Fedora KVM Bridge 備忘]
* [http://blog.bodhizazen.net/linux/kvm_network_scripts/ KVM network scripts]
* [http://www.benjr.tw/?q=node/537 KVM - Network]
* [https://help.ubuntu.com/community/KVM/Networking KVM Networking (Ubuntu)]
* [http://blog.cynapses.org/2007/07/12/qemu-kvm-internal-network-setup/ qemu kvm internal network setup]