xen利用URL的centos镜像文件安装(三)-创新互联
一、Xen的配置文件说明
创新互联专业为企业提供兰坪网站建设、兰坪做网站、兰坪网站设计、兰坪网站制作等企业网站建设、网页设计与制作、兰坪企业网站模板建站服务,10多年兰坪做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。Xen配置文件一般由选项(options)、变量(variables)、CPU、网络、PCI、HVM、计时器(timers)、驱动(drivers)、磁盘设备(disk devices)、动作(behavior),以及图形及声音(Graphics and audio)几个段组成,分别用于定义不同类别的域属性或设备属性。
上面的配置文件中的各选项作用如下。
◇kernel:为当前域指定可用于DomU的内核文件;
◇ramdisk:与kernel指定的内核文件匹配使用的ramdisk映像文件,根据需要指定,此为可选项;
◇name:当前域的独有名称;每个域必须使用全局惟一的名称,否则将产生错误;
◇memory:当前域的可用物理内存空间大小,单位为MB,默认为128;
◇disk:当前域的所有可用磁盘设备列表,格式为disk = [ “disk1”, “disk2”, …],每个
disk都有三个参数进行定义,格式为“backend-dev,front-dev,mode”;
backend-dev主要有两种类型,物理设备或虚拟磁盘映像文件,它们的格式分别为“phy:device”和“file:/path/to/file”;
frontend-dev定义其在DomU中的设备类型,一般为xvd[a-z];
mode则用于定义其访问权限,r为只读,w为读写;
◇vcpus:配置给当前域使用的虚拟CPU的个数;默认为1;
◇root:为当前域指定其根文件系统所在的设备,这个将作为内核参数在内核启动传递给内核;
◇extra:传递给内核的额外参数,其中selinux=0表示禁用selinux,init则用于指定init程序的路径;多个参数之间使用空格隔开;
◇on_reboot:执行xm reboot命令或在当前域内部执行重启操作时由Xen执行的动作;其常用的值为destroy和restart;
◇on_crash:当前域由于各种原因崩溃时由Xen执行的动作;其常用的值为destroy、restart和preserve,preserve可以保存系统崩溃前的状态信息以用于调试;
◇on_shutdown:执行xm shutdown命令或在当前域内部执行关机操作时由Xen执行的动作;
其它常用参数:
◇vif:定义当前域的可用虚拟网络接口列表,每个虚拟网络接口都可以使用“name=value”的格式定义其属性;也可在定义某接口时不指定任何属性,其所有属性将均由系统默认配置;例如:vif = ['ip = "192.168.1.19", bridge=xenbr0']
type:接口设备的类型,默认为netfront;
mac:MAC地址,默认为随机;
bridge:桥接到的物理设备,默认为Dom0中的第一个桥接设备;
ip:ip地址;
script:配置此接口的脚本文件,省略时将使用默认的配置脚本;
vifname:后端设备的设备名称,默认为vifD.N,其中D为当前域的ID,N为此网络接口的ID;
◇vfb:为当前域定义虚拟帧缓冲,其有许多可用属性,可以使用“name=value”的格式进行定义;
vnc或sdl:定义vnc的类型,vnc=1表示启动一个可由外部设备连接的vnc服务器,sdl=1则表示启用一个自有的vncviewer;两者可以同时使用;
vncdisplay:vnc显示号,默认为当前域的ID,当前域的VNC服务器将监听5900+此显示号的端口;
vnclisten:VNC服务器监听的地址,默认为127.0.0.1;
vncunused:如果此属性的值为非零值,则表示vncserver监听大于5900的第一个没被占用的端口;
vncpasswd:指定VNC服务器的认证密码;
display:用于域的自有vncviewer显示,默认为DISPLAY环境变量的值;
◇cpu:指定当前域应该在哪个物理CPU上启动,0表示第一颗CPU,1表示第二颗,依次类推;默认为-1,表示Xen可自行决定启动当前域的CPU;
◇cpus:指定当前域的VCPU可以在哪些物理CPU上运行,如cpus = ”3,5-8,^6”表示当前域的VCPU可以在3,5,7,8号CPU上运行;
◇bootloader:bootloader程序的路径;基于此bootloader,PV DomU的内核也可直接位于其文件系统上而非Dom0的文件系统;
更多的选项请参见xmdomain.cfg的手册页,或参考Xen官方wiki链接http://wiki.xen.org/wiki/XenConfigurationFileOptions中的详细解释。
二、确定硬件是否支持xen的需求
1、半虚拟化的支持
其实只要是64位x_86主机都能够支持半虚化需求,支持PAE,
[root@logicserver vm1]# cat /proc/cpuinfo | grep flags flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer xsave hypervisor lahf_lm arat epb pln pts dtherm fsgsbase erms xsaveopt flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer xsave hypervisor lahf_lm arat epb pln pts dtherm fsgsbase erms xsaveopt
2、完全虚拟化的支持,目前X_86主机中,Intel提供的是VT技术,AMD提供的是SVM技术
什么都没显示,表示不支持
[root@logicserver vm1]# egrep '{vt|svm}' /proc/cpuinfo
3、建立磁盘镜像文件,如果在生产环境上,建议不要使用dd来创建,使用qemu-img来创建,可以弹性调整磁盘空间大小
[root@logicserver ~]# qemu-img create -f raw /xen/vm2/centos6.img500G
[root@logicserver ~]# qemu-img info /xen/vm2/centos6.img
三、安装步聚
1、利用桥接模式
yum -y install bridge-utils
2、从centos6.5镜像文件,两个文件
[root@logicserver vmlinux]# ll 总用量 36644 -r--r--r--. 1 root root 33392971 9月 9 11:15 initrd.img -r-xr-xr-x. 1 root root 4128368 9月 9 11:15 vmlinuz [root@logicserver vmlinux]# pwd /root/vmlinux
3、编辑/etc/xen/centos6的文件,centos6是从xmexample1复制而来例子配置文件,稍作修改
要改的选项有:
kernel = "/root/vmlinux/vmlinuz"
ramdisk="/root/vmlinux/initrd.img"
#ramdisk = "/boot/initrd.gz"
#root = "/dev/xvda ro" 注释
vif = [ 'bridge=br0' ]
on_reboot = 'destroy'
on_crash = 'destroy'
[root@logicserver xen]# vim centos6 # Kernel p_w_picpath file. kernel = "/root/vmlinux/vmlinuz" ramdisk="/root/vmlinux/initrd.img" # Optional ramdisk. #ramdisk = "/boot/initrd.gz" # The domain build function. Default is 'linux'. #builder='linux' # Initial memory allocation (in megabytes) for the new domain. # # WARNING: Creating a domain with insufficient memory may cause out of # memory errors. The domain needs enough memory to boot kernel # and modules. Allocating less than 32MBs is not recommended. memory = 1024 # A name for your domain. All domains must have different names. name = "centos6" # 128-bit UUID for the domain. The default behavior is to generate a new UUID # on each call to 'xm create'. #uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9" # List of which CPUS this domain is allowed to use, default Xen picks #cpus = "" # leave to Xen to pick #cpus = "0" # all vcpus run on CPU0 #cpus = "0-3,5,^1" # all vcpus run on cpus 0,2,3,5 #cpus = ["2", "3"] # VCPU0 runs on CPU2, VCPU1 runs on CPU3 # Number of Virtual CPUS to use, default is 1 #vcpus = 1 vcpus = 2 #---------------------------------------------------------------------------- # Define network interfaces. # By default, no network interfaces are configured. You may have one created # with sensible defaults using an empty vif clause: # # vif = [ '' ] # # or optionally override backend, bridge, ip, mac, script, type, or vifname: # # vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ] # # or more than one interface may be configured: # # vif = [ '', 'bridge=xenbr1' ] vif = [ 'bridge=br0' ] #vif = [ '' ] #---------------------------------------------------------------------------- # Define the disk devices you want the domain to have access to, and # what you want them accessible as. # Each disk entry is of the form phy:UNAME,DEV,MODE # where UNAME is the device, DEV is the device name the domain will see, # and MODE is r for read-only, w for read-write. #disk = [ 'phy:hda1,hda1,w' ] disk = [ 'file:/xen/vm2/centos6.img,xvda,w' ] #---------------------------------------------------------------------------- # Define frame buffer device. # # By default, no frame buffer device is configured. # # To create one using the SDL backend and sensible defaults: # # vfb = [ 'sdl=1' ] # # This uses environment variables XAUTHORITY and DISPLAY. You # can override that: # # vfb = [ 'sdl=1,xauthority=/home/bozo/.Xauthority,display=:1' ] # # To create one using the VNC backend and sensible defaults: # # vfb = [ 'vnc=1' ] # # The backend listens on 127.0.0.1 port 5900+N by default, where N is # the domain ID. You can override both address and N: # # vfb = [ 'vnc=1,vnclisten=127.0.0.1,vncdisplay=1' ] # # Or you can bind the first unused port above 5900: # # vfb = [ 'vnc=1,vnclisten=0.0.0.0,vncunused=1' ] # # You can override the password: # # vfb = [ 'vnc=1,vncpasswd=MYPASSWD' ] # # Empty password disables authentication. Defaults to the vncpasswd # configured in xend-config.sxp. #---------------------------------------------------------------------------- # Set the kernel command line for the new domain. # You only need to define the IP parameters and hostname if the domain's # IP config doesn't, e.g. in ifcfg-eth0 or via DHCP. # You can use 'extra' to set the runlevel and custom environment # variables used by custom rc scripts (e.g. VMID=, usr= ). # Set if you want dhcp to allocate the IP address. #dhcp="dhcp" # Set netmask. #netmask= # Set default gateway. #gateway= # Set the hostname. #hostname= "vm%d" % vmid # Set root device. #root = "/dev/xvda ro" # Root device for nfs. #root = "/dev/nfs" # The nfs server. #nfs_server = '192.0.2.1' # Root directory on the nfs server. #nfs_root = '/full/path/to/root/directory' # Sets runlevel 4. #extra = "3 selinux=0 init=/sbin/init" #---------------------------------------------------------------------------- # Configure the behaviour when a domain exits. There are three 'reasons' # for a domain to stop: poweroff, reboot, and crash. For each of these you # may specify: # # "destroy", meaning that the domain is cleaned up as normal; # "restart", meaning that a new domain is started in place of the old # one; # "preserve", meaning that no clean-up is done until the domain is # manually destroyed (using xm destroy, for example); or # "rename-restart", meaning that the old domain is not cleaned up, but is # renamed and a new domain started in its place. # # In the event a domain stops due to a crash, you have the additional options: # # "coredump-destroy", meaning dump the crashed domain's core and then destroy; # "coredump-restart', meaning dump the crashed domain's core and the restart. # # The default is # # on_poweroff = 'destroy' # on_reboot = 'restart' # on_crash = 'restart' # # For backwards compatibility we also support the deprecated option restart # # restart = 'onreboot' means on_poweroff = 'destroy' # on_reboot = 'restart' # on_crash = 'destroy' # # restart = 'always' means on_poweroff = 'restart' # on_reboot = 'restart' # on_crash = 'restart' # # restart = 'never' means on_poweroff = 'destroy' # on_reboot = 'destroy' # on_crash = 'destroy' #on_poweroff = 'destroy' #on_reboot = 'restart' #on_crash = 'restart' #----------------------------------------------------------------------------- # Configure PVSCSI devices: # #vscsi=[ 'PDEV, VDEV' ] # # PDEV gives physical SCSI device to be attached to specified guest # domain by one of the following identifier format. # - XX:XX:XX:XX (4-tuples with decimal notation which shows # "host:channel:target:lun") # - /dev/sdxx or sdx # - /dev/stxx or stx # - /dev/sgxx or sgx # - result of 'scsi_id -gu -s'. # ex. # scsi_id -gu -s /block/sdb # 36000b5d0006a0000006a0257004c0000 # # VDEV gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as # which the specified guest domain recognize. # #vscsi = [ '/dev/sdx, 0:0:0:0' ] #============================================================================ #on_crash = 'reboot'
4、配置网卡为桥接模式
[root@logicserver xen]# cd /etc/sysconfig/network-scripts/ [root@logicserver network-scripts]# cp ifcfg-eth0 ifcfg-br0 [root@logicserver network-scripts]# vim ifcfg-br0 DEVICE="br0" BOOTPROTO="none" NM_CONTROLLED="no" ONBOOT="yes" TYPE="Bridge" IPADDR=10.1.2.180 GATEWAY=10.1.2.254 NETMASK=255.255.255.0
[root@logicserver network-scripts]# vim ifcfg-eth0 DEVICE="eth0" BOOTPROTO="none" HWADDR="44:8A:5B:59:F9:C0" NM_CONTROLLED="no" ONBOOT="yes" TYPE="Ethernet" BRIDGE=br0 UUID="6edaf36c-d0f4-4e54-a88a-717f589b91c6"
启动stp
[root@logicserver ~]# brctl stp br0 on [root@logicserver ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.549f351d8f36 yes em1
5、在本地主机下挂cento6.5镜像文件,同时安装httpd
[root@logicserver ~]# yum install httpd -y [root@logicserver~]# mkdir /var/www/html/tree [root@logicserver~]# mount -o loop/data/CentOS-6.5-x86_64-bin-DVD1.iso /var/www/html/tree/ [root@logicserver ~]# service httpd restart
[root@hadoop3 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda3 3.9G 3.9G 0 100% / tmpfs 346M 0 346M 0% /dev/shm /dev/sda1 194M 29M 155M 16% /boot /dev/sda5 3.9G 72M 3.6G 2% /home /dev/sda6 3.9G 72M 3.6G 2% /tmp /dev/sda2 6.8G 2.9G 3.6G 46% /usr /dev/sda7 2.9G 267M 2.5G 10% /var /root/data/CentOS-6.5-x86_64-bin-DVD1.iso 4.2G 4.2G 0 100% /var/www/html/tree [root@hadoop3 ~]# cd /root/data/ [root@hadoop3 data]# ll 总用量 3312568 -rw-r--r-- 1 root root 3392065536 9月 9 11:53 CentOS-6.5-x86_64-bin-DVD1.iso
[root@hadoop3 data]# cd /var/www/html/tree [root@hadoop3 tree]# ll 总用量 682 -r--r--r-- 2 root root 14 11月 29 2013 CentOS_BuildTag dr-xr-xr-x 3 root root 2048 11月 29 2013 EFI -r--r--r-- 2 root root 212 11月 28 2013 EULA -r--r--r-- 2 root root 18009 11月 28 2013 GPL dr-xr-xr-x 3 root root 2048 11月 29 2013 p_w_picpaths dr-xr-xr-x 2 root root 2048 11月 29 2013 isolinux dr-xr-xr-x 2 root root 655360 11月 29 2013 Packages -r--r--r-- 2 root root 1354 11月 28 2013 RELEASE-NOTES-en-US.html dr-xr-xr-x 2 root root 4096 11月 29 2013 repodata -r--r--r-- 2 root root 1706 11月 28 2013 RPM-GPG-KEY-CentOS-6 -r--r--r-- 2 root root 1730 11月 28 2013 RPM-GPG-KEY-CentOS-Debug-6 -r--r--r-- 2 root root 1730 11月 28 2013 RPM-GPG-KEY-CentOS-Security-6 -r--r--r-- 2 root root 1734 11月 28 2013 RPM-GPG-KEY-
6、用xm创建虚拟机
输入从另一台主机URL地址:http://10.1.2.180/tree/
[root@logicserver xen]# xm create -c centos6 ┌────────────────────────┤ URL Setup ├───────│─────────────────┐ │ │ Please enter the URL containing the CentOS │ │ installation p_w_picpath on your server. │ │ │ │http://10.1.2.180/tree/______________________________________ │ │ │ │ [ ] Enable HTTP proxy │────│. │ │ Proxy URL ___________________________________ │ │ Username _______________ │ │ │────│ Password.────_______________.┘ │ │ │ │ ┌────┐ ┌──────┐│ │ │ OK │ │ Back │ │ │ └────┘ └──────┘│ │ │────│─────────┘ │ └──────────────────────────────────────────────────────────────┘next screen
Welcome to CentOS for x86_64
────
┌───────────┤ Error ├─────────── │ │
│ Unable to retrieve │ │ http://10.1.2.190/tree//p_w_picpaths │ │ /install.img. │
│ │
│ ┌────┐ │ │ │ OK │ │ │ └────┘ │ │.───────────────.│.───┘
│ │ └────────────────────────────────┘│ ────
───────────────────────────┘
7、创建完成后,一定会出reboot,按ENTER键,然后会自动"destroy"
,在重新连接centos6前,先去/etc/xen/centos6,修改以下选项
#kernel = "/root/vmlinux/vmlinuz"
#ramdisk="/root/vmlinux/initrd.img" 注释
添加
bootloader = "/usr/bin/pygrub"
on_reboot = 'restart'
on_crash = 'destroy
8、连接centos
[root@logicserver xen]# xm create centos6 WARNING: xend/xm is deprecated. Using config file "./centos6". Started domain centos6 (id=11) [root@logicserver xen]# xm list WARNING: xend/xm is deprecated. Name ID Mem VCPUs State Time(s) Domain-0 0 1021 2 r----- 1177.6 centos6 11 1024 2 r----- 4.3
进入centos6虚拟机了
[root@logicserver xen]# xm console centos6 WARNING: xend/xm is deprecated. [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup-lv_root 8563152 752220 7375940 10% / tmpfs 508060 0 508060 0% /dev/shm /dev/xvda1 495844 33477 436767 8% /boot
四、添加一块硬盘
1、
给centos6添加一块硬盘xvdb
[root@logicserver vm3]# xm list WARNING: xend/xm is deprecated. Name ID Mem VCPUs State Time(s) Domain-0 0 1021 2 r----- 1773.5 centos6 1 1024 2 -b---- 32.5 centos601 5 512 2 -b---- 31.7
[root@logicserver vm3]# qemu-img create -f qcow2 -o size=20G /xen/vm1/test.qcow2
[root@logicserver vm3]# xm block-list centos6 WARNING: xend/xm is deprecated. Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 13 8 /local/domain/0/backend/vbd/1/51712
[root@logicserver vm3]# xm block-attach centos6 file:/xen/vm1/test.qcow2 xvdb w WARNING: xend/xm is deprecated. [root@logicserver vm3]# xm block-list centos6 WARNING: xend/xm is deprecated. Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 13 8 /local/domain/0/backend/vbd/1/51712 51728 0 0 4 15 902 /local/domain/0/backend/vbd/1/51728
进到cento6下,查看会多出一块硬盘
[root@localhost ~]# fdisk -l Disk /dev/xvda: 10.5 GB, 10485760000 bytes 255 heads, 63 sectors/track, 1274 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000db375 Device Boot Start End Blocks Id System /dev/xvda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 64 1275 9726976 8e Linux LVM Disk /dev/mapper/VolGroup-lv_root: 8908 MB, 8908701696 bytes 255 heads, 63 sectors/track, 1083 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 1048 MB, 1048576000 bytes 255 heads, 63 sectors/track, 127 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/xvdb: 0 MB, 197120 bytes 255 heads, 63 sectors/track, 0 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
2、移除硬盘
[root@logicserver vm3]# xm block-detach centos6 51728
3、添加网卡,由于只有一个桥br0
root@logicserver ~]# xm network-attach WARNING: xend/xm is deprecated. Error: 'xm network-attach' requires between 1 and 11 arguments. Usage: xm network-attach[type= ] [mac= ] [bridge= ] [ip= ] [script=