Install and configure Xen on CentOS

Source: Internet
Author: User
At present, Masters in the lab are equipped with one PC and one notebook, but Honours is equipped with only one PC and one machine is inconvenient for project development. multi-system is often used for development, for example, some people are working on projects related to mobile phone VoIP, and the mobile client interface should be implemented on Windows platforms, while the VoIP server must use Linux,

At present, Masters in the lab are equipped with one PC and one notebook, but Honours is equipped with only one PC and one machine is inconvenient for project development. multi-system is often used for development, for example, some people are working on projects related to mobile phone VoIP, the mobile client interface should be implemented on Windows platforms, and the VoIP server must use Linux, so virtual machines should be used to virtualize a Linux, it would be slow if all of these were running on a physical machine. Currently, the PC configured for Honours only has 1 GB of memory. if you run Windows + mobile phone simulator + Elipse IDE (Java required) + VMware (another Linux + Asterisk + MySQL running on VMware ), then it is very difficult to open a client to receive emails and open several browsers to view documents.

 

Therefore, VPSee intends to donate a SUN server in use to form an Xen Server, and allocate each Honours a virtual system, saving them time and resources for installing their own virtual machines, VPSee has become a free Xen VPS provider :). 16 Xen virtual system instances run on the SUN server at the same time, each with 256 MB memory, 4 GB hard disk, no GUI. The following installation steps and configuration process are based on CentOS 5.3. for the Ubuntu version, see install and configure Xen on Ubuntu. for the Debian version, see install and configure Xen on Debian. for the OpenSolaris version, see: install and configure Xen on OpenSolaris.

Install Xen
Install the Linux kernel that supports Xen and Xen:

$ Yum install kernel-xen
After the installation is successful, you can see that the xen.gz-2.6.18-128.2.1.el5 kernel has been installed. modify the default value to start the Xen kernel by default.

# Vi/etc/grub. conf

Default = 0
Timeout = 2
Splashimage = (hd0, 0)/grub/splash.xpm.gz
Hiddenmenu
Title CentOS (2.6.18-128.2.1.el5xen)
Root (hd0, 0)
Kernel/xen.gz-2.6.18-128.2.1.el5
Module/vmlinuz-2.6.18-128.2.1.el5xen ro root =/dev/VolGroup00/LogVol00
Module/initrd-2.6.18-128.2.1.el5xen.img
Title CentOS (2.6.18-128.1.16.el5)
Root (hd0, 0)
Kernel/vmlinuz-2.6.18-128.1.16.el5 ro root =/dev/VolGroup00/LogVol00
Initrd/initrd-2.6.18-128.1.16.el5.img

After the system is restarted, check whether the kernel is Xen:

# Uname-r
2.6.18-128.2.1.el5xen
Check whether Xen has been started:

#/Usr/sbin/xm list
Name ID Mem (MiB) VCPUs State Time (s)
Domain-0 0 1220 2 r ----- 3214.1
Create and install guest
If you think of the operating system of the running Xen kernel as the host, the operating system running on the host can be considered as the guest. Create a directory to store the images, vm01.img, and vm02.img of all the guest operating systems. one guest corresponds to one image.

# Mkdir/vm
# Cd/vm

# Virt-install

What is the name of your virtual machine? <-- Vm01
How much RAM shoshould be allocated (in megabytes )? & Lt; -- 256
What wocould you like to use as the disk (path )? <--/Vm/vm01.img
How large wocould you like the disk (/vm/vm01.img) to be (in gigabytes )? <-- 4
Wocould you like to enable graphics support? (Yes or no) <-- no
What is the install location? <-- Http: // 127.0.0.1/centos
You can also simplify the preceding command to one:

# Virt-install-n vm01-r 256-f/vm/vm01.img-s 4 -- nographics-p
-L http: // 127.0.0.1/centos
Note that if it is-p (paravirtualized), it cannot be directly installed from the iso file. you must extract the iso file and put it on an http/ftp server for installation, only fully virtualized can be installed from iso files, CD-ROM, etc. Note that the Windows kernel must be modified for paravirtualized. Therefore, Windows cannot be installed. fully receivalized can be used to install Windows as long as the CPU supports Virtualization (Intel VT or amd v ). Therefore, you need to install and configure a web server, and then extract the iso file to the directory accessible to the web server (http: // 127.0.0.1/centos ). If the network speed is fast enough, you can install directly from the Internet, change http: // 127.0.0.1/centos to http://mirrors.kernel.org/centos/5.3/ OS /i386

After installing the CentOS Operating System (guest) according to the CentOS installation program, check the guest configuration file:

# Cat/etc/xen/vm01
Name = "vm01"
Uuid = "b4910b6d-b205-6f86-c145-3c0895cb20c5"
Maxmem = 256
Memory = 256
Vcpus = 1
Bootloader = "/usr/bin/pygrub"
On_poweroff = "destroy"
On_reboot = "restart"
On_crash = "restart"
Vfb = []
Disk = ["tap: aio:/vm/vm01.img, xvda, w"]
Vif = ["mac = 00: 16: d2: 0a: 66: 6d, bridge = xenbr0"]
Check whether guest is started:

#/Usr/sbin/xm list
Name ID Mem (MiB) VCPUs State Time (s)
Domain-0 0 1220 2 r ----- 4691.3
Vm01 9 255 1-B ---- 16.9
Go to guest
After the installation is successful, you can log on to guest,

#/Usr/sbin/xm console vm01
If you want to exit guest, press Ctrl +] to return to the host.

If you want to automatically start guest each time you start the host:

# Ln-s/etc/xen/vm01/etc/xen/auto
Lazy approach
If you think it is too troublesome to install the guest operating system, you can go to the http://stacklet.com/download an installed image file, and then start the guest image under the host. Download and start an image of Ubuntu 9.04:
#/Usr/sbin/xm list
#/Usr/sbin/xm console Ubuntu.9-04
The initial user name and password for the image file downloaded from the http://stacklet.com/are: root/password

Add swap
If it is an operating system image downloaded from the http://stacklet.com/, you may not have set up swap, you need to add your own swap partition, you can make a swap image file as a swap partition. Compared with OpenVZ, Xen has the advantage that Xen can have its own swap partition, and even guest can set its own swap. create a 512 MB (524288B, 1 GB = 1048576B) file and convert it to the swap format:

# Dd if =/dev/zero of = Ubuntu.9-04. swap bs = 1024 count = 524288

#/Sbin/mkswap Ubuntu.9-04. swap
Modify/etc/xen/Ubuntu.9-04 and the disk line:

# Vi/etc/xen/Ubuntu.9-04.cfg
Disk = [file:/vm/Ubuntu.9-04.img, sda1, w, file:/vm/ubuntu.9-04. swap, sda2, w]
Start the guest system, log on to/etc/fstab, and use top to check whether the Swap partition is activated:

# Vi/etc/fstab
/Dev/sda2 swap defaults, noatime 0 0

# Shutdown-r now

# Top
...
Mem: 262284 k total, 46480 k used, 215804 k free, 3176 k buffers
Swap: 524280 k total, 0 k used, 524280 k free, 17196 k cached
Common Xen commands
Xm create-c/path/to/config-Start a virtual machine.
Xm shutdown-Stop a virtual machine.
Xm destroy-Stop a virtual machine immediately without shutting it down. Its as if you switch off the power button.
Xm list-List all running systems.
Xm console-Log in on a virtual machine.
Xm help-List of all commands.
 
# Wget http://stacklet.com/sites/default/files/Ubuntu/
Ubuntu.9-04.x86.20090514.img.tar.bz2

# Tar jxvf Ubuntu.9-04.x86.20090514.img.tar.bz2
# Mv Ubuntu.9-04. x86.xen3. pygrub. cfg/etc/xen/ubuntu.9-04.cfg
# Mv Ubuntu.9-04. x86.img/vm/ubuntu.9-04.img

#/Usr/sbin/xm create-f Ubuntu.9-04.cfg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.