เทคนิดเด็ด Linux รู้ไว้ใช่ว่า


สร้าง VPS ใน VPS ด้วย xem

Host Installation

 

* ทำการติดตั้ง CentOS 5 บนเครื่อง Host

* ดาวน์โหลด CentOS ได้ที่ http://mirror.in.th หรือ http://mirror1.ku.ac.th

* สำหรับวิธีการติดตั้ง CentOS สามารถหาข้อมูลได้จาก Internet

* ในตัวอย่างกำหนดหมายเลข IP เครื่อง Host เป็น 192.168.99.1

 

[edit] Xen Installation

 

1. ตรวจสอบ Partition ด้วยคำสั่ง df และเลือก Partition ที่จะใช้เก็บ Virtual Machine ในตัวอย่างเลือกเก็บไว้ที่ /home

 

[root@vs ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/md3 20G 6.0G 13G 33% /

/dev/md1 99M 16M 79M 17% /boot

tmpfs 506M 0 506M 0% /dev/shm

/dev/md2 51G 185M 48G 1% /home

 

2. ติดตั้ง xen และ kernel-xen

 

[root@vs ~]# yum install xen kernel-xen

 

3. หลังจากติดตั้งแล้ว จะพบว่ามี Xen kernel (vmlinuz-2.6.<version_number>.el5xen) และ ramdisk (initrd-2.6.<version_number>.el5xen.img) อยู่ที่ /boot

 

[root@vs ~]# ls -l /boot

total 9759

-rw-r--r-- 1 root root 61057 Jun 15 07:58 config-2.6.18-8.1.6.el5xen

-rw-r--r-- 1 root root 62150 Mar 16 07:19 config-2.6.18-8.el5

drwxr-xr-x 2 root root 1024 Jul 13 13:16 grub/

-rw------- 1 root root 1532874 Jul 10 23:40 initrd-2.6.18-8.1.6.el5xen.img

-rw------- 1 root root 1531907 Jun 27 18:24 initrd-2.6.18-8.el5.img

drwx------ 2 root root 12288 Jun 28 01:21 lost+found/

-rw-r--r-- 1 root root 80032 Apr 1 21:49 message

-rw-r--r-- 1 root root 84906 Jun 15 07:59 symvers-2.6.18-8.1.6.el5xen.gz

-rw-r--r-- 1 root root 83542 Mar 16 07:20 symvers-2.6.18-8.el5.gz

-rw-r--r-- 1 root root 868084 Jun 15 07:58 System.map-2.6.18-8.1.6.el5xen

-rw-r--r-- 1 root root 884787 Mar 16 07:19 System.map-2.6.18-8.el5

-rw-r--r-- 1 root root 2076104 Jun 15 07:58 vmlinuz-2.6.18-8.1.6.el5xen

-rw-r--r-- 1 root root 1765428 Mar 16 07:19 vmlinuz-2.6.18-8.el5

-rw-r--r-- 1 root root 274227 Jun 15 04:27 xen.gz-2.6.18-8.1.6.el5

-rwxr-xr-x 1 root root 608568 Jun 15 08:15 xen-syms-2.6.18-8.1.6.el5*

 

4. เพื่อให้ระบบ Boot ด้วย Xen kernel ทำได้โดยแก้ไขไฟล์ /boot/grub/grub.conf กำหนดค่า default ตามลำดับของ title ในตัวอย่าง title CentOS (2.6.<version_number>.el5xen) เป็น title แรก มีค่าเป็น 0

 

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,0)

# kernel /vmlinuz-version ro root=/dev/md3

# initrd /initrd-version.img

#boot=/dev/md1

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.18-8.1.6.el5xen)

root (hd0,0)

kernel /xen.gz-2.6.18-8.1.6.el5

module /vmlinuz-2.6.18-8.1.6.el5xen ro root=/dev/md3

module /initrd-2.6.18-8.1.6.el5xen.img

title CentOS (2.6.18-8.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/md3

initrd /initrd-2.6.18-8.el5.img

 

5. Restart ระบบ

 

[root@vs ~]# shutdown -r now

 

6. หลังจาก restart แล้ว ตรวจสอบ kernel ด้วยคำสั่ง uname พบว่า boot โดยใช้ xen kernel แล้ว

 

[root@vs ~]# uname -r

2.6.18-8.1.6.el5xen

 

7. ตรวจสอบด้วยคำสั่ง xm list หากพบ Domain-0 แสดงว่า Xen ได้ Start แล้ว

 

[root@vs ~]# xm list

Name ID Mem(MiB) VCPUs State Time(s)

Domain-0 0 939 2 r----- 22.9

 

[edit] Guest OS Installation

 

1. เตรียม FTP Server สำหรับการติดตั้ง Guest OS ผ่าน Network

 

[root@vs ~]# yum install vsftpd

[root@vs ~]# service vsftpd start

Starting vsftpd for vsftpd: [ OK ]

 

2. ดาวน์โหลด DVD image file ของ CentOS 5 ไปวางใน path ที่อยู่ใน /var/ftp/pub

 

[root@vs ~]# mkdir -p /var/ftp/pub/centos/5/iso

[root@vs ~]# cd /var/ftp/pub/centos/5/iso

[root@vs iso]# wget http://mirror1.ku.ac.th/centos/5/isos/i386/CentOS-5.3-i386-bin-DVD.iso

[root@vs iso]# ls -lh

total 3.7G

-rw-r--r-- 1 root root 3.7G Apr 11 05:15 CentOS-5.3-i386-bin-DVD.iso

-rw-r--r-- 1 root root 501 Jul 10 05:43 md5sum.txt

 

3. Mount ไฟล์ CentOS-5.3-i386-bin-DVD.iso ที่ได้ดาวน์โหลดมา

 

[root@vs ~]# cd /var/ftp/pub/centos/5

[root@vs 5]# mkdir os

[root@vs 5]# mount -o loop iso/CentOS-5.3-i386-bin-DVD.iso os

[root@vs 5]# ls -l os

total 1046

drwxr-xr-x 2 root root 376832 Apr 11 02:58 CentOS/

-rw-r--r-- 7 root root 212 Mar 30 08:50 EULA

-rw-r--r-- 7 root root 18009 Mar 10 12:01 GPL

drwxr-xr-x 4 root root 2048 Apr 11 02:58 images/

drwxr-xr-x 2 root root 2048 Apr 11 02:51 isolinux/

drwxr-xr-x 2 root root 4096 Apr 6 17:17 NOTES/

-rw-r--r-- 2 root root 24220 Apr 6 17:17 RELEASE-NOTES-cz

-rw-r--r-- 2 root root 27400 Apr 6 17:17 RELEASE-NOTES-cz.html

...

...

...

 

4. Address สำหรับติดตั้ง CentOS ผ่าน Network คือ ftp://192.168.99.1/pub/centos/5/os

 

5. ติดตั้ง Guest OS โดยใช้เครื่องมือ virt-install

 

[root@vs ~]# virt-install -h

usage: virt-install [options]

 

options:

-h, --help show this help message and exit

-n NAME, --name=NAME Name of the guest instance

-r MEMORY, --ram=MEMORY

Memory to allocate for guest instance in megabytes

-u UUID, --uuid=UUID UUID for the guest; if none is given a random UUID

will be generated

--vcpus=VCPUS Number of vcpus to configure for your guest

-f DISKFILE, --file=DISKFILE

File to use as the disk image

-s DISKSIZE, --file-size=DISKSIZE

Size of the disk image (if it doesn't exist) in

gigabytes

--nonsparse Don't use sparse files for disks. Note that this will

be significantly slower for guest creation

-m MAC, --mac=MAC Fixed MAC address for the guest; if none or RANDOM is

given a random address will be used

-b BRIDGE, --bridge=BRIDGE

Bridge to connect guest NIC to; if none given, will

try to determine the default

--vnc Use VNC for graphics support

--vncport=VNCPORT Port to use for VNC

--sdl Use SDL for graphics support

--nographics Don't set up a graphical console for the guest.

--noautoconsole Don't automatically try to connect to the guest

console

-p, --paravirt This guest should be a paravirtualized guest

-l LOCATION, --location=LOCATION

Installation source for paravirtualized guest (eg,

nfs:host:/path, http://host/path, ftp://host/path)

-x EXTRA, --extra-args=EXTRA

Additional arguments to pass to the installer with

paravirt guests

-d, --debug Print debugging information

 

6. ตั้งชื่อ Virtual Machine ว่า monitor กำหนดขนาดของ RAM 256 เก็บไฟล์ image ไว้ที่ /home/xen/monitor.img มีขนาดของ disk 16 GB เมื่อกำหนดข้อมูลเสร็จแล้วระบบจะทำการ Boot เครื่อง Virtual Machine และเริ่มการติดตั้ง

 

[root@vs ~]# mkdir -p /home/xen

[root@vs ~]# virt-install

What is the name of your virtual machine? monitor

How much RAM should be allocated (in megabytes)? 256

What would you like to use as the disk (path)? /home/xen/monitor.img

How large would you like the disk (/home/xen/monitor.img) to be (in gigabytes)? 16

Would you like to enable graphics support? (yes or no) no

What is the install location? ftp://192.168.99.1/pub/centos/5/os

 

 

Starting install...

Linux version 2.6.18-8.el5xen ([email protected]) (gcc version 4.1.1

20070105 (Red Hat 4.1.1-52)) #1 SMP Thu Mar 15 21:02:53 EDT 2007

BIOS-provided physical RAM map:

Xen: 0000000000000000 - 0000000010800000 (usable)

0MB HIGHMEM available.

264MB LOWMEM available.

...

...

...

 

 

7. ขั้นตอนการติดตั้ง ให้ทำเหมือนกับติดตั้งบนเครื่องปกติ

 

Welcome to CentOS

 

+---------+ Choose a Language +---------+

| |

| What language would you like to use |

| during the installation process? |

| |

| Catalan ^ |

| Chinese(Simplified) : |

| Chinese(Traditional) # |

| Croatian : |

| Czech : |

| Danish : |

| Dutch : |

| English v |

| |

| +----+ |

| | OK | |

| +----+ |

| |

| |

+---------------------------------------+

 

<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen

 

8. ในตัวอย่างเป็นการติดตั้งเครื่อง monitor กำหนด IP Address เป็น 192.168.99.2

 

Welcome to CentOS

 

 

+--------------+ Manual TCP/IP Configuration +---------------+

| |

| Enter the IPv4 and/or the IPv6 address and prefix |

| (address / prefix). For IPv4, the dotted-quad netmask |

| or the CIDR-style prefix are acceptable. The gateway and |

| name server fields must be valid IPv4 or IPv6 addresses. |

| |

| IPv4 address: 192.168.99.2___ / 255.255.255.0__________ |

| Gateway: 192.168.99.254___________________________ |

| Name Server: 202.44.204.67____________________________ |

| |

| +----+ +------+ |

| | OK | | Back | |

| +----+ +------+ |

| |

| |

+------------------------------------------------------------+

 

 

 

<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen

 

9. หลังจากติดตั้ง Guest OS (เครื่อง monitor) เสร็จแล้ว virt-install สร้างไฟล์ config สำหรับ Virtual Machine อยู่ที่ directory /etc/xen

 

[root@vs ~]# cat /etc/xen/monitor

# Automatically generated xen config file

name = "monitor"

memory = "256"

disk = [ 'tap:aio:/home/xen/monitor.img,xvda,w', ]

vif = [ 'mac=00:16:3e:44:6f:a7, bridge=xenbr1', ]

 

uuid = "149a7fd6-87b2-97e3-b287-b14dbdb912bc"

bootloader="/usr/bin/pygrub"

vcpus=1

on_reboot = 'restart'

on_crash = 'restart'

 

10. ระบบจะทำการ Restart เหมือนกับติดตั้ง OS จริง หลังจากที่ cursor มาอยู่ที่ shell prompt ให้ใช้คำสั่ง xm list เพื่อตรวจสอบว่า Guest กำลังทำงานอยู่หรือไม่ สังเกตได้จากชื่อ VM ที่อยู่ใต้ Domain-0 ถ้าไม่มี ให้ทำการ Start VM ด้วยคำสั่ง xm create -c <path/to/config/file>

 

[root@vs ~]# xm create -c /etc/xen/monitor

 

11. หากต้องการออกจาก Virtual Machine (Guest OS) ให้กด Ctrl+] และหากต้องการเข้าใช้งาน Virtual Machine ที่เปิดไว้แล้ว ใช้คำสั่ง xm console

 

[root@vs ~]# xm console monitor

 

[root@monitor ~]#

 

12. ดู list รายชื่อ Virtual Machine จะพบว่ามี monitor อยู่ในรายชื่อ สังเกตค่าหน่วยความจำ ของ Host (Domain-0) จะลดลงเนื่องจากถูก monitor ใช้ไป

 

[root@vs ~]# xm list

Name ID Mem(MiB) VCPUs State Time(s)

Domain-0 0 747 2 r----- 161.4

monitor 1 255 1 -b---- 841.3

 

13. หากต้องการให้เปิดเครื่อง Guest OS พร้อมกับ Host OS ทุกครั้งที่มีการ Restart Host (Domain-0) ให้ copy หรือทำ symbolic link ไฟล์ config ของ Guest OS ไปไว้ที่ /etc/xen/auto

 

[root@vs ~]# ln -s /etc/xen/monitor /etc/xen/auto

[root@vs ~]# ls -l /etc/xen/auto

total 0

lrwxrwxrwx 1 root root 16 Jul 14 01:35 monitor -> /etc/xen/monitor

 

14. คำสั่งที่จำเป็นต้องใช้จัดการกับ Virtual Machine

 

xm create -c /etc/xen/configfile เปิดเครื่อง Virtual Machine

xm shutdown <name> ปิดเครื่อง Virtual Machine (Shutdown)

xm destroy <name> ปิดเครื่อง Virtual Machine (เหมือนกดปุ่มปิดสวิตช์)

xm list ดูรายชื่อระบบทั้งหมด ที่ทำงานอยู่

xm console <name> เข้าใช้งานเครื่อง Virtual Machine ที่เปิดไว้แล้ว

xm help ดูวิธีใช้คำสั่ง xm

 

เดี๋ยวมาเพิ่มเติมจ้า...................

เครดิด:http://www.lsr.nectec.or.th/index.php/Howto_Install_and_Setup_Xen_Virtualization_on_CentOS_Linux

คำสำคัญ (Tags): #xem
หมายเลขบันทึก: 401860เขียนเมื่อ 10 ตุลาคม 2010 12:07 น. ()แก้ไขเมื่อ 13 พฤษภาคม 2012 02:50 น. ()สัญญาอนุญาต: สงวนสิทธิ์ทุกประการจำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (0)

ไม่มีความเห็น

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท