Xen ÊÇ¿ÉÓÃÓÚ Linux™ Äں˵ÄÒ»ÖÖÐéÄ⻯¼¼Êõ£¬ÈÃÄú¿ÉÒÔÏñÔÚÏÖÓл·¾³ÖÐÒ»Ñù°²×°²¢²âÊÔеÄÉý¼¶£¬¶ø²»±Øµ£ÐÄÆÆ»µÔÓеÄϵͳ¡£×÷Õß½«ÏòÄú½éÉÜÈçºÎʹÓà Fedora Core °²×° Xen£¬²»¹ý£¬°²×°Ö®ºó£¬ÔÚÈκη¢Ðа汾É쵀 Xen ÖУ¬ËùÓгÌÐòÔËתÆðÀ´¶¼ÊÇÏàͬµÄ¡£Á˽â Linux ÉϵÄÐéÄ⻯£¬ÖªµÀ¾ßÓÐÒ»¸öÓÃÓÚ²âÊÔÐÂÈí¼þµÄɳºÐµÄºÃ´¦£¬²¢Á·Ï°ÔÚͬһ̨ Linux »úÆ÷ÉÏÔËÐжà¸öÐéÄâ»ú¡£
Ëæ×ŶÔÏÖÓÐÈí¼þµÄ¸Ä½øºÍ bug ÐÞ¸´£¬¿ªÔ´ÊÀ½çµÄ±ä»¯ÓÀÎÞÖ¹¾³¡£Òª±£³ÖÈí¼þ×ÜÊÇÉý¼¶µ½×îУ¬Õâ¿ÉÄܵÃ×÷Ϊһ·ÝרְµÄ¹¤×÷¡£Éý¼¶Èí¼þ×îÄÑ´¦ÀíµÄÎÊÌâÖ®Ò»ÊÇ£ºÄúÓÀÔ¶²»»áÕæÕýÖªµÀÉý¼¶Íê³ÉºóÓ¦ÓóÌÐòÊÇ·ñ»¹Äܹ»¹¤×÷¡£´ó²¿·ÖÈí¼þ´ò°üϵͳ¶¼¾ß±¸»Ø¹ö¹¦ÄÜ£¬µ«Í¨³£Ö»ÓÐÕâÏÄÜ»¹²»¹»£»ÀíÏëÇé¿öÏ£¬ÄúÓ¦¸ÃÈ¥²âÊÔÕâЩеÄÉý¼¶£¬²¢ÔÚÒ»¸ö²»»áÆÆ»µÈκζ«Î÷µÄ»·¾³ÖÐÈ¥³¢ÊÔËüÃÇ¡£
¾ÍÏñÍæË£µÄСº¢×ÓÒ»Ñù£¬ÄúÏ£ÍûÓµÓÐÒ»¸öÊôÓÚ×Ô¼ºµÄɳºÐ£¬ÔÚÄÇÀïÄú¿ÉÒÔËæÒâ×öÈκÎÊÂÇé¡£
ͨ³£Í¨¹ý ÐéÄ⻯£¨Virtualization£©£¨»òÕß¡°É³ºÐ£¨sandbox£©¡±£©½«Í¬Ò»Ó²¼þÉϵÄÓ¦ÓóÌÐòºÍϵͳ±Ë´Ë¸ôÀ뿪À´¡£´ÓÓ²¼þÄ£Äâµ½ÍêÈ«Ó²¼þÐéÄ⻯£¬Linux Ö§³ÖºÜ¶àÖÖ²»Í¬ÐÎʽµÄÐéÄ⻯¡£ÔÚ²»¶ÏÔö¼ÓµÄÐéÄ⻯¼¼ÊõÁбíÖУ¬Xen ÊǽüÀ´×îÒýÈËעĿµÄ¼¼ÊõÖ®Ò»£¬ËüÓɽ£ÇÅ´óѧ¿ª·¢¡£Xen ÖµµÃÄú¹Ø×¢£¬ÒòΪËü¾ßÓпÕÇ°µÄÐÔÄÜÓ밲ȫÐÔ¡£
³õʶ Xen
Xen ÊÇÔÚ½£ÇÅ´óѧ×÷Ϊһ¸öÑо¿ÏîÄ¿±»¿ª·¢³öÀ´µÄ£¬ËüÒѾÔÚ¿ªÔ´ÉçÇøÖеõ½Á˼«´óµÄÍƶ¯¡£Xen ÊÇÒ»¿î °ëÐéÄ⻯£¨paravirtualizing£© VMM£¨ÐéÄâ»ú¼àÊÓÆ÷£¬Virtual Machine Monitor£©£¬Õâ±íʾ£¬ÎªÁ˵÷ÓÃϵͳ¹ÜÀí³ÌÐò£¬ÒªÓÐÑ¡ÔñµØÐ޸IJÙ×÷ϵͳ£¬È»¶øÈ´²»ÐèÒªÐ޸IJÙ×÷ϵͳÉÏÔËÐеÄÓ¦ÓóÌÐò¡£ËäÈ» VMWare µÈÆäËûÐéÄ⻯ϵͳʵÏÖÁËÍêÈ«µÄÐéÄ⻯£¨ËüÃDz»±ØÐÞ¸ÄʹÓÃÖеIJÙ×÷ϵͳ£©£¬µ«ËüÃÇÈÔÐèÒª½øÐÐʵʱµÄ»úÆ÷´úÂë·Ò룬Õâ»áÓ°ÏìÐÔÄÜ¡£
ÓÉÓÚ Xen ÐèÒªÐ޸IJÙ×÷ϵͳ£¬ËùÒÔÄú²»ÄÜÖ±½ÓÈõ±Ç°µÄ Linux ÄÚºËÔÚ Xen ϵͳ¹ÜÀí³ÌÐòÖÐÔËÐУ¬³ý·ÇËüÒѾÒÆÖ²µ½ÁË Xen ¼Ü¹¹¡£²»¹ý£¬Èç¹ûµ±Ç°ÏµÍ³¿ÉÒÔʹÓÃеÄÒѾÒÆÖ²µ½ Xen ¼Ü¹¹µÄ Linux Äںˣ¬ÄÇôÄú¾Í¿ÉÒÔ²»¼ÓÐ޸ĵØÔËÐÐÏÖÓеÄϵͳ¡£
ͼ 1. ¼òµ¥µÄ Xen ¼Ü¹¹
»ñµÃ Xen
¿ÉÒÔ´Ó Xen µÄÏîÄ¿Ö÷Ò³ÉÏ»ñµÃËüµÄÔ´´úÂ루Çë²ÎÔÄ ²Î¿¼×ÊÁÏ ²¿·ÖµÄÁ´½Ó£©£¬µ«ÊÇ£¬Èç¹ûÒѾÔÚʹÓÃij¸ö Linux ·¢Ðа汾£¬ÄÇôÄú»òÐíÄܹ»Í¨¹ýÈí¼þ°üÉý¼¶»òÕß°²×°À´»ñµÃ Xen¡£ÕâЩÖ÷Á÷·¢Ðа汾¶¼°üº¬ÁË Xen£º
Fedora Core
SUSE Linux
Debian
¿ÉÒÔ»ñµÃλÓÚ Gentoo's bugzilla µÄʵÑéÓÃµÄ e-builds¡£
¼ì²éÄúµÄ·¢Ðа汾 ---- Èç¹ûËü²»ÔÚÕâ¸öÁбíÖУ¬ÄÇôÄú¿ÉÄÜÖ»ÄÜÖ±½ÓʹÓÃÔ´´úÂë¡£³ýÁË°²×°¹ý³ÌÌض¨ÓÚ·¢Ðа汾֮Í⣬ÔÚÈκη¢Ðа汾ÉÏ£¬Xen ÖеÄËùÓй¤×÷¶¼ÊÇÏàͬµÄ¡£
ʹÓà Fedora Core
ÎÒÓÐÒ»¸ö¿ÉÒÔʹÓÃµÄ Fedora Core 3 °²×°£¬ÎªÁ˱£³Ö±¾Îĵļò½à£¬ÎÒ½«ÌÖÂÛÈçºÎÔÚ Fedora Core ÉÏ°²×°ºÍÔËÐÐϵͳ¡£
¾¡¹ÜÈí¼þ°üÖ»ÊÇÔÚ×î½ü²Å¿ªÊ¼½øÐпª·¢£¬µ« Fedora ÒѾΪ´óÁ¿ Xen Óû§ËùʹÓá£ÓÉÓÚÓкܶàÈ˳¢ÊÔÔÚ Fedora ÉÏʹÓà Xen£¬ËùÒÔÄú¿ÉÄܳɹ¦µØ»ñµÃ´óÁ¿µÄÔÚÏß°ïÖú¡£
°²×° Xen
ΪÁË°ïÖúÄúѸËÙÉÏÊÖºÍʹÓ㬱¾½Ú×ÅÖØÖ¸³öÁË ²Î¿¼×ÊÁÏ ²¿·ÖÖÐ Quick Start Guide µÄÒªµã¡£ÓÉÓÚ Fedora ÖÐÕýÔÚÈÚÈë Xen ¸üУ¬ËùÒÔËæ×Åʱ¼äµÄÍÆÒÆ£¬Quick Start Guide ½«ºÜ¿ÉÄܻᷢÉú±ä»¯£¬Ï£Íû wiki »á±£³Ö¶ÔÕâЩ±ä»¯µÄ¸üС£
Ê×ÏÈ£¬Îª»ù´¡»úÆ÷£¨base machine£©½øÐÐ×î¼ò»¯µÄ·þÎñÆ÷°²×°¡£Õą̂»ù´¡»úÆ÷ÊÇÄúµÄϵͳ¹ÜÀí³ÌÐò£¬½«²»»áÔËÐÐÈκηþÎñÆ÷Ó¦ÓóÌÐò¡£Äú½«¿ÉÒÔÔÚÔËÐÐÓÚ´Ë»úÆ÷Ö®É쵀 Xen ·þÎñÆ÷Öа²×°ËùÐèÒªµÄÈí¼þ°ü£¬ËùÒÔÏÖÔÚ²»ÐèÒª°²×°ÏëÒªÔËÐеÄÓ¦ÓóÌÐò¡£
ϵͳ¿ªÊ¼ÔËÐкó£¬ÄúÓ¦¸Ã½«Æä¸üе½ Fedora µÄ×îпª·¢°æ±¾£¨³ÆΪ rawhide£©¡£ÒªÍê³É´ËÈÎÎñ£¬Çë±éÀú /etc/yum.repos.d/ Ŀ¼ÖеÄÔªËØ£¬½«³ýÁË fedora-devel.repo ÒÔÍâµÄËùÓÐÔªËض¼¸ÄΪ enabled=0£»½« fedora-devel.repo ¸ÄΪ enabled=1¡£
½¨Á¢ÁË yum ´¢´æ¿â£¨repository£©ºó£¬ÐèÒª½«»úÆ÷¸üе½ rawhide£¬ÒÔ±ãÄú¿ÉÒÔ¿ªÊ¼Ê¹ÓÃ×îз¢²¼µÄ Xen¡£
Çåµ¥ 1. ½« FC3 ¸üе½ rawhide ²¢°²×° Xen Èí¼þ°ü
yum update
yum install xen kernel-xen0 kernel-xenU
È»ºó£¬´´½¨Ò»¸ö½«ÒªÊ¹ÓõÄÐéÄâÎļþϵͳ¡£
Çåµ¥ 2. ¸ñʽ»¯²¢½¨Á¢ Xen ·þÎñÆ÷Îļþϵͳ
mkdir -p /xen/base
dd if=/dev/zero of=/root/base.img bs=1M count=1 seek=1024
mkfs.ext3 /root/base.img
mount -o loop /root/base.img /xen/base
¸ñʽ»¯²¢¹ÒÔØ Xen ·þÎñÆ÷Îļþϵͳ֮ºó£¬ÏÂÒ»¸ö²½ÖèÊÇ°²×°±ØÒªµÄÈí¼þ°ü£¬ÒÔ±ãÔÚÕâЩÈí¼þ°üÉÏÔËÐÐijЩ³ÌÐò¡£ÎªÁËÔÚ Xen ·þÎñÆ÷ÉÏÔËÐÐÒ»¸ö Web ·þÎñÆ÷£¬ÄúÓ¦¸Ã°²×°Ò»×é Web-server Èí¼þ°ü¡££¨¾¯¸æ£º Õ⽫ÐèÒªÒ»¶Îʱ¼ä£¡Äú¿ÉÒÔÏÈÔËÐÐ yum£¬È»ºó³öȥɢɢ²½¡££©
Çåµ¥ 3. °²×° Xen ·þÎñÆ÷Èí¼þ°ü
yum --installroot=/xen/base -y groupinstall web-server \
--enablerepo=base --disablerepo=development
£¨ÏÖÔÚÓ¦¸Ãȥɢ²½ÁË¡££©
ÏÖÔÚÒѾ°²×°ÁËËùÓÐÐèÒªµÄÈí¼þ°ü£¬²»¹ýÄúÓ¦¸ÃÈ¥²é¿´Ò»¸ö¼òµ¥µÄ fstab Îļþ£¬Õâ¸öÎļþ»á¸æÖª Xen ·þÎñÆ÷ËüÃǽ«Òª»ñµÃ¸ù£¨root£©É豸 sda1£¬½«¸ÃÉ豸×÷Ϊ¸ù¡£¸ùÉ豸ʵ¼ÊÉÏÊÇÀ´×Ôϵͳ¹ÜÀí³ÌÐòµÄÒ»¸öÐéÄâµÄÉ豸£¬µ«ÄúµÄ·þÎñÆ÷²»»áÖªµÀÕâÒ»µã¡£
Çåµ¥ 4. Xen ·þÎñÆ÷ fstab Îļþ
/dev/sda1 / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
½«Õâ¸öÎļþдÈë /xen/base/etc/fstab¡£Èç¹û²»ÊDZê×¼µÄ Fedora °²×°£¬ÄÇô²»»áΪÄú´´½¨ÈκΠfstab¡£Ô¤¼Æ Fedora µÄδÀ´°æ±¾»á°üº¬´¦Àí´ËÎÊÌâµÄ¹¤¾ß¡£
×îºó£¬ÎªÁËÈÃϵͳÕýÈ·µØÔËÐУ¬ÄúÓ¦¸Ã×öһЩ´¦Àí¡£Ä¿Ç°£¬Xen ʹÓà initrd ʱÈÔÈ»´æÔÚÎÊÌ⣬ËùÒÔ£¬Èç¹ûÏëÒªÆô¶¯ÏµÍ³£¬ÔòÐèҪΪ×Ô¼º´´½¨Ò»Ð©É豸´úÂ롣Ȼºó£¬ÎªÁËÈóÌÐòƽÎÈÔËÐУ¬É¾³ý TLS ³ÌÐò¿â»áÓÐËù°ïÖú£¬ÒòΪĿǰËüÃÇÓë Xen ³åÍ»ºÜÑÏÖØ¡£Íê³ÉÕâ¸ö²½Öèºó£¬¿ÉÒÔжÔØÕâ¸öÎļþϵͳ¡£
Çåµ¥ 5. Ϊ¿ªÊ¼ÔËÐÐËù×öµÄ×îºóµÄ´¦Àí
for i in console null zero ; do MAKEDEV -d /xen/base/dev -x $i ; done
mv /lib/tls /lib/tls.disabled
mv /xen/base/lib/tls /xeb/base/lib/tls.disabled
umount /xen/base/
ÔËÐÐ Xen
¼ÈÈ»ÒѾϸÐĵØÊÖ¹¤½¨Á¢ÆðÁË¿Í»§ÏµÍ³£¬ÄÇôÄúÏÖÔھͿÉÒÔÕæÕýÖØÐÂÆô¶¯»úÆ÷£¬¿ªÊ¼Ê¹Óà Xen Äںˡ£Äú¿ÉÄܽ«»á¿´µ½±Èƽʱ¶àµÃ¶àµÄ´òÓ¡Êä³ö£¬²¢ÇÒÄú»¹»á¿´µ½¹ØÓÚ TLS ³ÌÐò¿â£¨ÉÏÒ»½ÚÖÐÄúɾ³ýµÄÄǸö»á³öÎÊÌâµÄ³ÌÐò¿â£©µÄ¿ÉŵÄÏûÏ¢¡£
Xen ÒªÇóΪÔËÐеÄÿ¸ö·þÎñÆ÷×¼±¸ÅäÖÃÎļþ¡£¾¡¹ÜÄú¿ÉÒÔΪËùÓзþÎñÆ÷´´½¨Ò»¸öΩһµÄ¶¯Ì¬ÅäÖÃÎļþ£¬µ«ÎÒ»¹Êǽ¨ÒéÄú´´½¨Á½¸ö¾²Ì¬µÄÅäÖÃÎļþ£¬¸÷ÓÃÒ»¸ö¡£ÈçÄúËù¼û£¬´ÅÅ̱êÇ©¸æËß·þÎñÆ÷ÄúµÄÎļþÓ³ÏñÊÇ sda1 É豸¡£Ò²Ö¸¶¨ÁËÄúËùʹÓÃµÄ xenU Äںˣ¬ÒÔ¼°·þÎñÆ÷¿Í»§½«Òª»ñµÃµÄÄÚ´æ¡£
Çåµ¥ 6. Xen ·þÎñÆ÷ÅäÖÃÎļþ
/etc/xen/base
kernel ="/boot/vmlinuz-2.6.10-1.1141_FC4xenU"
memory = 64
name = "BaseServer"
nics = 1
disk = ['file:/root/base.img,sda1,w']
root = "/dev/sda1 ro"
/etc/xen/test
kernel ="/boot/vmlinuz-2.6.10-1.1141_FC4xenU"
memory = 64
name = "TestServer"
nics = 1
disk = ['file:/root/test.img,sda1,w']
root = "/dev/sda1 ro"
ÒªÆô¶¯²¢ÔËÐзþÎñÆ÷£¬Ê×ÏÈҪʹÓÃÃüÁî xend start Æô¶¯ Xen ·þÎñ£¬È»ºóʹÓÃÃüÁî xm create base ͨ¹ý»ù±¾ÅäÖÃÎļþ´´½¨ BaseServer¡£Í¨¹ýÕâЩ²½Ö裬Äú½«½øÈë Xen ¿Í»§ÏµÍ³ÖУ¬¿ÉÒÔ¿´µ½¸ÃϵͳÒѾÆô¶¯ÆðÀ´¡£²»ÂÛºÎʱ£¬Èç¹ûÄúÏëÌø³ö¿Í»§ÏµÍ³¿ØÖÆ̨£¬ÄÇô°´Ï Ctrl-] ×éºÏ¼ü¾Í¿ÉÒÔÖ±½Ó·µ»Øµ½ÏµÍ³¹ÜÀí³ÌÐò¿ØÖÆ̨¡£
ʹÓà Xen
ÏÖÔÚÄúÒѾÓÃÁËһЩʱ¼äÀ´±à¼ÅäÖ㬲¢½¨Á¢ÁËÔËÐÐÁ½¸ö Xen ·þÎñÆ÷µÄϵͳ¡£ËùÓÐÕâЩ¼è¿àµÄ¹¤×÷Íê³Éºó£¬½ÓÏÂÀ´×öʲô£¿
ÏÖÔÚÄúÓµÓÐÁËÒ»¸öϵͳµÄÁ½¸ö¸±±¾£¬ËüÃÇÔËÐÐÏàͬÄںˣ¬ÔÚͬһ̨»úÆ÷Éϱ»ÐéÄ⻯¡£Èç¹û BaseServer ´ú±íµÄÊÇÄúÏ£ÍûÕý³£ÔËÐÐ Web ·þÎñµÄÎȶ¨»·¾³£¬ÄÇô TestServer ´ú±íµÄ¾ÍÊÇ Fedora rawhide ËùÌṩµÄ×îÐÂÈí¼þ¸üС£Äú¿ÉÒÔËæÒâ±£³Ö¶Ô TestServer ϵͳµÄÉý¼¶£¬³¢ÊÔËùÓÐа汾µÄÈí¼þ¸üР---- µ±ÄúÈÏΪËü×ã¹»Îȶ¨Ê±£¬¿ÉÒÔ½« TestServer ×÷Ϊ BaseServer À´ÔËÐС£
ÉèÖÃ BaseServer
BaseServer ÔËÐÐʱ£¬ÊÇÐ޸Ľ«ÒªÔËÐÐµÄ httpd ·þÎñµÄÅäÖõĺÃʱ»ú¡£ÄúÓ¦¸Ã½« ssl.conf ÎļþÒƳö /etc/httpd/conf.d/ Ŀ¼£¬ÒÔ´ËÀ´Í£Óà ssl£»·ñÔò£¬Äú½«ÐèҪΪ·þÎñÆ÷Éú³ÉÖ¤Êé¡£ÁíÍ⣬¿ÉÄÜÐèÒªÏòϵͳÌí¼ÓÒ»¸ö apache Óû§¡£
Xen ϵͳ¹ÜÀí³ÌÐòÒѾ×Ô¶¯ÌṩÁËÒ»¸ö¿ÉÒÔʹÓõÄÐéÄâÍøÂçÉ豸¡£Èç¹ûÄú¿ÉÒÔÔÚÕâ¸öÉ豸ÉÏÔËÐÐ dhcp£¬ÄÇôֻÐèÒªÖ´ÐÐ dhclient eth0£¬BaseServer ¾Í»á»ñµÃ IP µØÖ·¡£
ÉèÖÃ TestServer
ÉèÖÃÁË BaseServer µÄÅäÖÃÖ®ºó£¬ÔÚ BaseServer ¿ØÖÆ̨ÖÐÖ´ÐÐ poweroff ÒԹرոÃʵÀý¡£Èç¹ûÄúÒѾ´Ó BaseServer ×¢Ïú£¬ÄÇô¿ÉÒÔʹÓà xm console BaseServer ÖØнøÈëËü¡£
ÏÖÔÚ£¬Í¨¹ý cp /root/base.img /root/test.img ¸´ÖÆ»ù´¡Ó³Ïñ£¬ÒÔ±ã»ñµÃͬһÎļþϵͳµÄ¸±±¾¡£µ±ÔËÐÐ xm create -c test ʱ£¬Ëü»áÔËÐÐÓë BaseServer ÏàͬµÄ·þÎñÆ÷£¬µ«ÊÇËüµÄÃû³ÆÊÇ TestServer¡£µÇ¼µ½ TestServer£¬È»ºóÏñÄúÔÚ °²×° Xen ÄÇÒ»½ÚÖÐËù×öµÄÄÇÑùÆôÓà rawhide Ö§³Ö£¬È»ºóÔËÐÐ yum update¡£
TestServer ʵÀýÓµÓÐÓë BaseServer ÍêÈ«ÏàͬµÄÅäÖ㬵«ÊÇÄúÒѾÉý¼¶µ½ÁË Fedora rawhide Ëù±ØÐë¾ß±¸µÄ×îеÄÈí¼þ°ü¡£ÔÚ´Ë£¬Äú¿ÉÒԲ鿴 Web Õ¾µãÊÇ·ñÈÔÈ»¿ÉÓá£
¹ØÓÚ Xen »¹ÓÐÄÄЩÄÚÈÝ£¿
ÎÒÏ£ÍûÕâЩ¼ò¶ÌµÄ˵Ã÷ºÍ¼òµ¥µÄʾÀýÄܹ»°ïÖúÄú°²×°ºÍÔËÐÐ Xen£¬ÕâÑùÄú¾Í¿ÉÒÔ³¢ÊÔʹÓÃËü¡£ÎªÁËÈÃÄúѸËÙµØÊìϤ Xen£¬ÎÒûÓнéÉÜÈçºÎÀûÓà LVM Óë¿ìÕÕ£¨snapshots£©µÈ¹¦ÄÜ£¬Ò²Ã»ÓнéÉÜÈçºÎÍê³É Xen ·þÎñÆ÷´Óһ̨»úÆ÷µ½Áíһ̨»úÆ÷µÄÍøÂçǨÒÆ¡£µ«ÊÇ£¬¼ÈÈ»ÄúÒѾÁ˽âÁË Xen Ëù¾ß±¸µÄһЩÓÅÊÆ£¬Çëä¯ÀÀÏÂÃæµÄ ²Î¿¼×ÊÁÏ£¬Ñ§Ï°Ò»Ð©ÈçºÎʹÓÃËüµÄ¸üΪ¶à±äµÄ¼¼ÇÉ¡£