Centos 5.5 installation and use of Xen is a mainstream Virtual Machine with minimal performance loss (but does not support windows). It can run on x86 systems and is porting to x86_64, IA64, and PPC. Porting to other platforms is technically feasible and may be implemented in the future.
1. install the Linux kernel supporting Xen and Xen1yum-y install xen kernel-xen-lib virt-manager python-kernel instkernel-xen: the Linux core www.2cto.com Xen that can run xen: The main xen suite, including configuration files, startup scripts, and some function libraries xen-libs: The function library required by Xen python-connector inst: Provides the terminal-installed software virt-manager: used to manage xen in a graphical interface
2. modify the default xen kernel to start 1vi/boot/grub. confdefault = 0 restart system 1reboot check kernel 1 uname-r2 output 2.6.18-238.9.1.el5xen check whether xen starts 1xm list2 output: Domain-0
3. when operating system is installed in xen, three sources are supported: NFS: nfs: Host IP: Directory www.2cto.com WWW: http: // host IP/directory FTP: ftp: // host IP Address/directory we use the WWW method (this method is very convenient. The installation source can be a web environment that contains the installation file that can be accessed ): make the installation source (mount the optical drive to/mnt/cdrom) 1 mkdir-p/mnt/cdrom2mount/dev/cdrom/mnt/cdrom install httpd (if not installed) 1yum-y install httpd modify httpd default directory 1vi/etc/httpd/conf/httpd. conf: Change DocumentRoot "/var/www/html" to DocumentRoot "/mnt/cdrom" and <Directory "/var/www/html"> to <Directory" /Mnt/cdrom "> 1sed-I's # DocumentRoot"/var/www/html "# DocumentRoot"/mnt/cdrom "# '/etc/httpd/conf/httpd. conf2sed-I's # <Directory "/var/www/html"> # <Directory "/mnt/cdrom"> # '/etc/httpd/conf/httpd. conf restart httpd1service httpd restart to create the main disk of the Client 1 mkdir-p/data/vm2dd if =/dev/zero of =/data/vm/web_001.img bs = 2 k seek = 4096 k count = 1 create a client to swap disk 1dd if =/dev/zero of =/data/vm/swap. img bs = 2 k seek = 512 k count = 1 install OS 1 virt -Install-n web_001-r 512 -- vcpus = 1 -- nographic-f/data/vm/web_001.img-l http: // 192.168.9.220 www.2cto.com #-n: name of the backend vm, configure under/etc/xen #-r: the size of the memory allocated next to it. It must be at least 256 MB before the memory can be renewed # -- vcpus: How many CPUs are allocated #-f: followed by the new disk file! # -- Nographics: Do not use graphical installation; #-p: semi-virtualization #-s: hard disk space of the virtual machine #-l: Install the source later. Written as: # NFS: nfs: Host IP: Directory # WWW: http: // host IP/directory # FTP: ftp: // host IP Address/directory. After installing the system according to the system prompt, view the Virtual Machine list on the real machine. The list output by 1xm list contains the newly created web_001 Virtual Machine. 4. attaches the relevant operation command ls/etc/xen # xen configuration file directory xm list # view the status of each domain xm shutdown web_001 # disable the VM xm console web_001 web_001 to connect to the web_001 console, to connect to the VM, you can press ctrl +] to switch to the host. # If an IP address is configured, you can use the ssh-l username IP address to connect to xm create web_001 and start web_0015. how to automatically start the Virtual Machine 1ln-s/etc/xen/web_001/etc/xen/auto/web_001 # copy the configuration file directly to/etc/xen/auto/ 1 www.2cto.com cp-r/etc/xen/web_001/etc/xen/auto/6. XM command: xm create vm1 # Where vm1 is the virtual machine configuration file, located in/etc/xen/vm/vm1 xm create-c vm1 # If you need to start the console, you can run the command xm list # to list all the virtual machines xm console <domid> # To display the console xm reboot | shutdown <domid> # You can restart or close a VM whose id is domid. virtual Machine xm destroy <domid> # You can destroy the Virtual Machine xm console fc5 with the id of domid # log on to the running Virtual Operating System xm save <DomId> <File> # Storage in progress status of the running Virtual Operating System xm restore <File> # Wake up the virtual operating system xm pause <DomId> # Stop the running Virtual Operating System xm unpause <DomId> # activate the stopped Virtual Operating System operating System xm mem-set <DomId> <Mem> # adjust the memory occupied by the virtual platform/Virtual Operating System xm shutdown the Name or DomID of the Virtual Operating System # disable the virtual system xm destroy <DomId> # Stop a virtual system immediately (important ); xm vcpu-set <DomId> <VCPUs> # adjust the number of virtual CPUs of the virtual platform and Virtual Operating System xm top or xentop # view the running status of the virtual system xm save VM1 VM1.chk # stop domain and save its current state into a file called VM1.chk xm restore VM1.chk # resume execution of this domain
7. XEN vm copy close running vm 1xm shutdown web_001 copy vm image file and configuration file 1cp/data/vm/web_001.img/data/vm/web_002.img2cp/etc/xen/web_001/etc/ xen/web_002 modify the configuration file 1vi/etc/xen/web_002 of the newly copied virtual machine as follows: 01 name = "web_001" 02 www.2cto.com uuid = "Courier" 03 maxmem = 51204 memory = 51205 vcpus = 106 bootloader = "/usr/bin/pygrub" 07on_poweroff = "destroy" 08on_reboot = ""restart" 09on_crash = "restart" 10 disk = ["tap: aio:/data/vm/web_001.img, xvda, w "] 11vif = [" mac = 00: 16: 36: 64: 98: f1, bridge = xenbr0, script = vif-bridge "] the modified content is: 01 name = "web_002" 02 uuid = "bytes" 03 maxmem = 51204 memory = 51205 vcpus = 106 bootloader = "/usr/bin/pygrub" 07 www.2cto.com on_poweroff = "destroy" 08on_reboot = "restart" 09on_crash = "restart" 10 disk = ["tap: aio:/data/vm/web_002.img, xvda, w "] 11vif = [" mac = 00: 16: 36: 64: 98: f5, bridge = xenbr0, script = vif-bridge "] * Ensure the uniqueness of name, uuid, mac, and disk path
Start and enter the newly copied VM 1xm create-c web_002 Modify host name 1vi/etc/hosts change web_001 to web_0021vi/etc/sysconfig/network change web_001 to web_002 modify IP01vi/etc/ sysconfig/network-scripts/ifcfg-eth002 # Xen Virtual Ethernet03DEVICE = eth004BOOTPROTO = static05BROADCAST = 192.168.9.25506HWADDR = 00: 16: 36: 64: 98: f507 www.2cto.com IPADDR = 192.168.9.22208NETMASK = 255.255.0000009network = 192.168.9.010ONBOOT = yesQ: bs = 2 k seek = 4096 k count = 1 parameter meaning bs = 2 k: set the size of the read/write block to 2 kseek = 4096 k: Skip 4096 k blocks from the beginning of the output file and then start copying (usually only valid when the output file is a disk or tape) count = 1: copy only one block (the block size is equal to the number of bytes specified by bs) by Snowman