wiki:KVM-OpenNebula

Version 3 (modified by rider, 14 years ago) (diff)

--

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 及其所需要的套件】

  • pcXpcY 須安裝相關套件
    $ 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
    
    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_xen vmm_xen tm_nfs
    # onehost add pcY im_xen vmm_xen 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 上執行
  • 編輯 vm01 的設定檔 (X 和 Y 請自行修改成自己的電腦名稱)
    # cd /home/domains
    # gedit vm01.one
    
     NAME   = vm01
     CPU    = 1
     MEMORY = 128
     OS = [ kernel     = /boot/vmlinuz-2.6.26-2-xen-amd64,
           initrd     = /boot/initrd.img-2.6.26-2-xen-amd64,
           root       = sda2]
     DISK = [ source   = /home/domains/vm01/disk.img,
             clone    = no,
             target   = sda2,
             readonly = no]
     DISK = [  type     = swap,
              size     = 128,
              target   = "sda1",
              readonly = "no" ]
     NIC=[IP="192.168.1.X", MAC="00:16:00:00:00:XX"]
    
  • 使用 ONE 來開啟 vm01
    # onevm create vm01.one ; onevm deploy vm01 pcXXX
    
    # onevm list
      ID     NAME STAT CPU     MEM        HOSTNAME         TIME
       1     vm01 runn   0  131072           pcXXX  00 00:04:21
    
    # onevm show vm01
    
  • 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】

Attachments (17)

Download all attachments as: .zip