您好,登錄后才能下訂單哦!
一、Xen的配置文件說明
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 │ │ │ └────┘ └──────┘│ │ │────│─────────┘ │ └──────────────────────────────────────────────────────────────┘<F12> next screen
Welcome to CentOS for x86_64
────
┌───────────┤ Error ├─────────── │ │
│ Unable to retrieve │ │ http://10.1.2.190/tree//p_w_picpaths │ │ /install.img. │
│ │
│ ┌────┐ │ │ │ OK │ │ │ └────┘ │ │.───────────────.│.───┘
│ │ └────────────────────────────────┘│ ────
───────────────────────────┘<F12> next screen
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 <Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] [ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] [rate=<rate>] [model=<model>][accel=<accel>]
[root@logicserver ~]# xm network-attach centos6 bridge=br0
[root@logicserver ~]# xm network-list centos6 WARNING: xend/xm is deprecated. Idx BE MAC Addr. handle state evt-ch tx-/rx-ring-ref BE-path 0 0 00:16:3e:47:ec:15 0 4 14 768 /769 /local/domain/0/backend/vif/1/0 1 0 00:16:3e:6b:b4:d5 1 4 15 1280 /1281 /local/domain/0
到centos6下去查看,多了一個eth2
root@centos6 ~]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:16:3E:47:EC:15 inet addr:10.1.2.181 Bcast:10.1.2.255 Mask:255.255.255.0 inet6 addr: fe80::216:3eff:fe47:ec15/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:106273 errors:0 dropped:0 overruns:0 frame:0 TX packets:14782 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:47692920 (45.4 MiB) TX bytes:1088040 (1.0 MiB) Interrupt:18 eth2 Link encap:Ethernet HWaddr 00:16:3E:6B:B4:D5 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:17 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
移除網卡
[root@logicserver ~]# xm network-detach centos6 1
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。