Monday, March 19, 2012

Instalasi Xen di Debian


Xen merupakan salah satu teknologi virtualisasi berbasis opensource, yang memungkinkan beberapa sistem operasi berjalan dalam hardware komputer yang sama secara konkuren.


Instalasi Xen
Install paket-paket Xen dari repositori:
root@local# apt-get install xen-tools xen-linux-system-2.6.32-5-xen-686 xen-utils-4.0 xenstore-utils xen-hypervisor-4.0-i386

edit file /etc/modules seperti berikut:
loop max_loop=256

edit file /etc/xen/xend-config.sxp dan hilangkan tanda “#” pada baris berikut:
…....................................
(network-script network-bridge)
…....................................

(vif-script vif-bridge)
…....................................
edit file konfigurasi xen-tools di /etc/xen-tools/xen-tools.conf:
…................................................
dir = /home/vps
install-method = debootstrap
gateway    = 172.16.130.1
netmask    = 255.255.255.0
broadcast  = 172.16.130.255
nameserver = 172.16.17.3
genpass = 0
#passwd = 1
output    = /etc/xen/vps
extension = .cfg
…..................................................
reboot sistem linux dan pilih kernel XEN pada saat booting.


Membuat Image Virtual Machine XEN
Buat direktori /home/vps dan /etc/xen/vps seperti berikut:
root@local# mkdir /home/vps
root@local# mkdir /etc/xen/vps
Kemudian gunakan perintah xen-create-image seperti berikut:
root@local# xen-create-image --hostname=cosmos --mirror=http://kambing.ui.ac.id --dist=squeeze --ip=172.16.130.56 --password=root
General Information
--------------------
Hostname       :  cosmos
Distribution   :  squeeze
Mirror         :  http://kambing.ui.ac.id
Partitions     :  swap            128Mb (swap)
                 /               2Gb   (ext3)
Image type     :  sparse
Memory size    :  128Mb
Kernel path    :  /boot/vmlinuz-2.6.32-5-xen-686
Initrd path    :  /boot/initrd.img-2.6.32-5-xen-686

Networking Information
----------------------
IP Address 1   : 172.16.130.56 [MAC: 00:16:3E:38:89:C5]
Netmask        : 255.255.255.0
Broadcast      : 172.16.130.255
Gateway        : 172.16.130.1
Nameserver     : 172.16.17.3

Creating partition image: /home/vps/domains/cosmos/swap.img
Done
Creating swap on /home/vps/domains/cosmos/swap.img
Done
Creating partition image: /home/vps/domains/cosmos/disk.img
Done
Creating ext3 filesystem on /home/vps/domains/cosmos/disk.img
Done
Installation method: debootstrap
Done
Running hooks
Done
No role scripts were specified.  Skipping
Creating Xen configuration file
Done
Setting up root password
Generating a password for the new guest.
All done

Logfile produced at:
        /var/log/xen-tools/cosmos.log

Installation Summary
---------------------
Hostname        :  cosmos
Distribution    :  squeeze
IP-Address(es)  :  172.16.130.56
RSA Fingerprint :  da:86:92:4e:dc:c2:3e:70:a2:31:f9:47:38:91:dc:bb
Root Password   :  root

Setelah proses diatas selesai, konfigurasi image ‘cosmos’ akan disimpan di file /etc/xen/vps/cosmos.cfg, berikut isi file konfigurasi tersebut:
# Configuration file for the Xen instance cosmos, created
# by xen-tools 4.2 on Tue May 10 17:23:51 2011.
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.32-5-xen-686'
ramdisk     = '/boot/initrd.img-2.6.32-5-xen-686'

vcpus       = '1'
memory      = '128'

#
#  Disk device(s).
#
root        = '/dev/xvda2 ro'
disk        = [
                 'file:/home/vps/domains/cosmos/disk.img,xvda2,w',
                 'file:/home/vps/domains/cosmos/swap.img,xvda1,w',
             ]
#
#  Physical volumes
#
#  Hostname
#
name        = 'cosmos'
#
#  Networking
#
vif         = [ 'ip=172.16.130.56,mac=00:16:3E:38:89:C5' ]
#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

Untuk menjalankan image virtual machine yang telah dibuat tadi, bisa menggunakan perintah berikut:
root@local# xm create /etc/xen/vps/cosmos.cfg
Using config file "/etc/xen/vps/cosmos.cfg".
Started domain cosmos (id=9)
Gunakan perintah berikut untuk melihat daftar virtual machine yang sedang jalan:

root@local# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1392     2     r-----   5870.6
browse                                       6   128     1     -b----      5.4
chat                                         2   128     1     -b----    138.5
cosmos                                       9   128     1     -b----      3.6
mirror                                       7   128     1     -b----      4.7
repo                                         8   128     1     -b----      5.4

Untuk masuk ke console virtual machine, bisa menggunakan perintah “xm console <nama virtualmachine>”, seperti berikut:
root@local# xm console cosmos
Debian GNU/Linux 6.0 cosmos hvc0

cosmos login:  
Debian GNU/Linux 6.0 cosmos hvc0
Gunakan CTRL + ] untuk keluar dari console virtual machine.
Beberapa perintah yang berguna untuk me-manage virtual machine:xm create -c /path/to/config - menjalankan virtual machine.
xm shutdown <name> - mematikan virtual machine.
xm destroy <name> - mematikan virtual machine secara tiba-tiba, sama halnya ketika kita mematikan komputer dengan menekan tombol power
xm list - meliat daftar virtual machine yang sedang jalan.
xm console <name> - masuk ke console virtual machine, gunakan CTRL + ] untuk keluar dari console virtual machine.
xm help - memohon bantuan :).

No comments: