Installation and use of Xen virtual machine on Linux

Time:2020-11-16

1. Install Xen

Copy code

The code is as follows:

yum install xen* kernel-xen* virt-manager vnc* xen-lib python-virtinst

Kernel Xen: Linux kernel that can run Xen

Xen: the main Xen suite, including configuration files, startup scripts, and some function libraries

Xen LIBS: function library for Xen

Python virtinst: software for terminal installation

Virt Manager: for graphical interface management Xen

2. Modify grub to boot the system from the Xen kernel

Copy code

The code is as follows:

[[email protected] ~]# more /etc/grub.conf

# 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,1)

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

#          initrd /initrd-version.img

#boot=/dev/sda

default=0

timeout=5

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

hiddenmenu

title CentOS (2.6.18-194.32.1.el5xen)

root (hd0,1)

kernel /xen.gz-2.6.18-194.32.1.el5

module /vmlinuz-2.6.18-194.32.1.el5xen ro root=LABEL=/ rhgb quiet

module /initrd-2.6.18-194.32.1.el5xen.img

title CentOS (2.6.18-194.el5)

root (hd0,1)

kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet

initrd /initrd-2.6.18-194.el5.img

3. Restart the system and verify that you have booted using the Xen kernel

Copy code

The code is as follows:

[[email protected] ~]# uname -ar
Linux test1.aa.com 2.6.18-274.17.1.el5xen #1 SMP Tue Jan 10 18:06:37 EST 2012 x86_64 x86_64 x86_64 GNU/Linux


4. Adjust the memory used by Xen server (dom0)
default=0

timeout=5

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

hiddenmenu

title CentOS (2.6.18-238.9.1.el5xen)

root (hd0,0)

kernel / xen.gz -2.6.18-238.9.1.el5  dom0_ MEM = 2097152 (KB in 2G)

module /vmlinuz-2.6.18-238.9.1.el5xen ro root=LABEL=/

module /initrd-2.6.18-238.9.1.el5xen.img

title CentOS (2.6.18-194.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/

initrd /initrd-2.6.18-194.el5.img
The server needs to be restarted after the adjustment.

5. Set up local Yum source, easy to install the system

modify http.conf :

Add listening port:

Copy code

The code is as follows:

Listen 8000
Listen 8001

Add virtual host:
<VirtualHost *:8001>

DocumentRoot /data/os

<Directory “/data/os”>

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>
Restart httpdd / etc / init.d/httpd reload

6. Create virtual machine

Copy code

The code is as follows:

virt-install -n xen1 -r 256 -f /home/xen1.img -lhttp://192.168.0.110:8001 –network=network:default -s 20 –nographics –vnc –vcpus=8

-n: The name of the virtual machine is followed by the configuration under / etc / Xen

-r: This is followed by the allocated memory size

– vcpus: how many CPUs are allocated

-f: This is followed by a new disk file

– nographics: no graphical installation

-P: semi virtualization

-S: hard disk space of virtual machine

-l: The installation source is connected behind

7. Clone virtual machine

Copy code

The code is as follows:

virt-clone -o xen1 -n xen2 -f /home/xen2.img

8. Common commands

XM info View host information

XM top monitors host and domain machine information

XM create / etc / Xen / xen1 start

XM shutdown xen1

XM reboot xen1 restart

XM pause xen1 pause

XM resume xen1

xm list

XM console xen1 enters the console

CTRL +] exit console

9. Optimization

Copy code

The code is as follows:

[[email protected] ~]# xm list

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

Domain-0                                   0      474     1 r—–   1222.9

xen1                                      10      255     1 -b—-     81.9

Optimization method: XM vcpu pin 301 (the vcpu used by virtual machine is directly processed by physical CPU 1)

Confirm whether a separate physical CPU has been allocated:

Copy code

The code is as follows:

xm vcpu-list 3