我正计划设置一台使用基于NexentaOS / ZFS的SAN通过iSCSI存储虚拟磁盘映像(VDI)的XenServer机器。 我知道我可以在SAN上设置一个大的存储库(SR),让XenServer负责快照并克隆磁盘映像。 但是,我很想深入了解ZFS的function,并将其用于快照/克隆,原因如下:
会让ZFS处理快照/克隆,而不是通过XenServer来实现,如果是的话,最好的办法是什么? 如果我把所有的VDI放在一个大的SR内,并且把整个SR的ZFS快照放在一起,我就不能一次回滚一个单独的VM。 我可以为每个VDI创build一个SR,如果必须回滚VDI,我会小心地分离SR,将其重新放回到SAN上,然后重新连接。 但是,我猜测,如果XenServer检测到重复的SRUUID,则在连接克隆的SR时遇到问题。 有没有更好的方法来处理克隆或从SAN回滚到以前的快照?
正如其他答案所暗示的,理想的方法是每个VDI LUN。 起初看起来似乎不可能做到这一点,但是有一个未公开的“iscsi”SR驱动程序,它将创build一个LUN-per-VDI SR(我在通过/ opt / xensource / sm目录 – 请参阅ISCSISR.py文件)。 您基本上为每个iSCSI目标设置一个SR,XenServer为该目标上的每个LUN创buildVDI。 您只能通过命令行进行设置,包括创buildVBD并将其附加到VM。 VBD和VDI甚至不会在XenCenter中显示。
这里有一个示例命令来设置它:
xe sr-create name-label=san type=iscsi device-config:target=<IP address of target> device-config:targetIQN=<IQN of target> shared=true
这将自动为每个iSCSI LUN创build一个VDI。 如果您最终在SAN上添加新的iSCSI LUN,则执行以下命令后,XenServer将为其添加新的VDI:
xe sr-scan uuid=<UUID of SR>
当为克隆的LUN添加VDI时,这也适用 – 新的VDI被分配一个新的UUID。
另外,如果最终调整LUN的大小,XenServer不会自动启动,因此您必须执行以下操作:
xe vdi-forget uuid=<UUID of VDI that you resized> iscsiadm -m node -R xe sr-scan uuid=<UUID of SR>
并创build一个VBD并将其附加到VM:
xe vbd-create vm-uuid=<UUID of VM> device=<VBD device #, eg 0> vdi-uuid=<VDI of UUID>
我用xenserver做了几个configuration,类似于这个设置
我已经使用了两种方法之一
如果我没有很多虚拟机,我创build系统磁盘与每个虚拟机的VDI和数据磁盘作为直接附加Iscsi伦
如果我有很多vm(20+),我创build一个大的SR,当我需要回滚我可以
A.在连接到XenServer之前重命名VG(在另一台机器上的vgrename – 甚至是虚拟的)
B.您甚至可以将大的SR快照附加到虚拟机,并使用iscsi再次将其导出,
我希望它不要太复杂:)
有趣的configuration..特别针对ZFS。
根据我对XenServer的经验,最好的办法就是让存储系统pipe理磁盘(以及快照和其他pipe理任务)。
我认为你应该让ZFS处理快照和克隆,但是我不确定你能做的最好的是给XenServer一个大SR(我同意你说的回滚)。 这是一个非常复杂的设置,因为如果你有很多虚拟机,你将拥有大量的虚拟桌面,pipe理可能是一团糟,但你将获得回滚的能力。 我会使用每个虚拟机一个VDI。
回答你的问题,如果你再次检查,当你回滚你分离SR时,不会有任何问题时,附加克隆的SR。 我以前做过,不是在XenServer中,而是在XCP( http://goo.gl/4wfE )
我们的客户(Nexenta客户)没有太多的虚拟机(大多数不到1000个),有时会select每个虚拟机执行一次LUN。 这使您可以轻松地从每个虚拟机的NexentaStor快照。 最酷的是你可以创造出一个金色的形象,也叫做clome-master。 然后使用该克隆主服务器启动新的虚拟机,只需克隆即可。 而且额外的好处是你没有使用任何额外的磁盘空间。
这似乎相关。 下面的bash脚本具有附加和分离SR的function,以及重命名现有(例如SAN克隆)SR中的所有UUID。 它可以用来重命名旧克隆的UUID并附加它,而不会与最新版本的卷相冲突。
# returns scsi_id, scsi_lun_id and as a bonus host_uuid probe_sr(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 cmd="ssh root@$xen_host_ip xe sr-probe type=lvmoiscsi device-config:target=$iscsi_device_ip device-config:targetIQN=$iscsi_device_target_iqn:$iscsi_vol_name" echo $cmd probe_out=`$cmd 2>&1` #echo probe_out=$probe_out scsi_id=`echo $probe_out | awk '{for(i=1;i<=NF;i++){if($i=="<SCSIid>"){i+=1;o=o","$i}}}END{print substr(o,2)}'` echo scsi_id=$scsi_id if [ -z $scsi_id ];then exit fi # Only allow one LUN per target. To allow for more, enhance input to specify volume serial number and search probe output for it. if [ `echo $scsi_id | awk -F, '{print NF}'` != 1 ];then echo Only one LUN per iscsi target is supported exit fi scsi_lun_id=`echo $probe_out | awk '{for(i=1;i<=NF;i++){if($i=="<LUNid>"){i+=1;o=o" "$i}}}END{print substr(o,2)}'` echo scsi_lun_id=$scsi_lun_id if [ -z $scsi_lun_id ];then exit fi # This only works if it is a standalone XenServer, not in a Xen pool - so this becomes a requirement host_uuid=`ssh root@$xen_host_ip xe host-list --minimal` if [ -z $host_uuid ];then echo host_uuid=$host_uuid exit fi } # Create SR wipes out contents of previous SR create_sr(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 sr_name=$5 probe_sr $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name cmd="ssh root@$xen_host_ip xe sr-create host-uuid=$host_uuid content-type=user name-label=$sr_name shared=true device-config:target=$iscsi_device_ip device-config:targetIQN=$iscsi_device_target_iqn:$iscsi_vol_name device-config:SCSIid=$scsi_id type=lvmoiscsi" echo $cmd $cmd } # mainly returns sr_uuid, but also pv_device used in uuid_regen_sr get_sr_uuid_from_file_system(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 scsi_lun_id=$5 # Ensure the the VG for the new volume gets created ##iscsiadm -m discovery -t sendtargets -p $iscsi_device_ip echo ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --login ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --login # get the pv_device name # Some iSCSI SAN might need customization here #scsi_id_short=`echo $scsi_id | awk '{print substr($1,1,length("36589cfc000000"))}'` scsi_id_short=$scsi_id echo scsi_id_short=$scsi_id_short unset pv_device_short tries=1 while [ $tries -le 3 ]&&[ -z $pv_device_short ];do echo "ssh root@$xen_host_ip ls -l /dev/disk/by-scsibus/ | egrep \"$scsi_id_short.*-[0-9]+:[0-9]+:[0-9]+:$scsi_lun_id -> \" | awk '{print \$NF}' | awk -F/ '{print \$NF}'" pv_device_short=`ssh root@$xen_host_ip ls -l /dev/disk/by-scsibus/ | egrep "$scsi_id_short.*-[0-9]+:[0-9]+:[0-9]+:$scsi_lun_id -> " | awk '{print $NF}' | awk -F/ '{print $NF}'` pv_device=/dev/$pv_device_short echo pv_device=$pv_device if [ -z "$pv_device_short" ];then sleep 1 fi tries=$(( tries + 1 )) done if [ -z "$pv_device_short" ];then exit fi if [ `echo $pv_device | wc -l` -gt 1 ];then exit fi # pvscan ensure PVs, VGs and LVMs are visible echo ssh root@$xen_host_ip pvscan ssh root@$xen_host_ip pvscan 2>/dev/null # get the VG UUID which is also what Xen uses for the SR UUID sr_uuid=`ssh root@$xen_host_ip "pvs 2>/dev/null" | egrep "$pv_device.*VG_XenStorage-" | awk '{print substr($2,length("VG_XenStorage-")+1)}'` echo sr_uuid=$sr_uuid if [ -z "$sr_uuid" ];then exit fi # Thought this might be good, but think it caused problems. Better and seemingly required place is in detach_sr #echo ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --logout #ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --logout } attach_sr_xen(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 sr_name=$5 # Attach volume as a Xen SR echo ssh root@$xen_host_ip "xe sr-introduce uuid=$sr_uuid name-label=\"$sr_name\" type=lvmoiscsi shared=true" ssh root@$xen_host_ip "xe sr-introduce uuid=$sr_uuid name-label=\"$sr_name\" type=lvmoiscsi shared=true" echo ssh root@$xen_host_ip "xe pbd-create sr-uuid=$sr_uuid host-uuid=$host_uuid type=lvmoiscsi device-config-target=$iscsi_device_ip device-config-targetIQN=$iscsi_device_target_iqn:$iscsi_vol_name device-config-SCSIid=$scsi_id" pbd_uuid=`ssh root@$xen_host_ip "xe pbd-create sr-uuid=$sr_uuid host-uuid=$host_uuid type=lvmoiscsi device-config-target=$iscsi_device_ip device-config-targetIQN=$iscsi_device_target_iqn:$iscsi_vol_name device-config-SCSIid=$scsi_id"` echo pbd_uuid=$pbd_uuid if [ -z $pbd_uuid ];then exit fi echo ssh root@$xen_host_ip "xe pbd-plug uuid=$pbd_uuid" ssh root@$xen_host_ip "xe pbd-plug uuid=$pbd_uuid" } # Attach SR retains prior contents as opposed to create_sr attach_sr(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 sr_name=$5 probe_sr $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name get_sr_uuid_from_file_system $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name $scsi_lun_id attach_sr_xen $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name $sr_name } # Detach/forget SR detach_sr(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 sr_name=$5 echo ssh root@$xen_host_ip "xe sr-list name-label=\"$sr_name\" --minimal" sr_uuid=`ssh root@$xen_host_ip "xe sr-list name-label=\"$sr_name\" --minimal"` echo sr_uuid=$sr_uuid if [ -z $sr_uuid ];then exit fi echo ssh root@$xen_host_ip "xe pbd-list sr-uuid=$sr_uuid --minimal" pbd_uuid=`ssh root@$xen_host_ip "xe pbd-list sr-uuid=$sr_uuid --minimal"` echo pbd_uuid=$pbd_uuid if [ -z $pbd_uuid ];then echo No PBD found, proceeding anyway fi echo ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --logout ssh root@$xen_host_ip iscsiadm -m node -T $iscsi_device_target_iqn:$iscsi_vol_name -p $iscsi_device_ip:3260 --logout if [ ! -z $pbd_uuid ];then echo ssh root@$xen_host_ip "xe pbd-unplug uuid=$pbd_uuid" ssh root@$xen_host_ip "xe pbd-unplug uuid=$pbd_uuid" fi echo ssh root@$xen_host_ip "xe sr-forget uuid=$sr_uuid" ssh root@$xen_host_ip "xe sr-forget uuid=$sr_uuid" echo "It is now ok to remove the volume from the storage array" } # generates new PV, SR (VG) and VDI (LVM) uuids for a cloned and unattached iSCSI SR, leaving it unattached uuid_regen_sr(){ xen_host_ip=$1 iscsi_device_ip=$2 iscsi_device_target_iqn=$3 iscsi_vol_name=$4 sr_name=$5 probe_sr $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name get_sr_uuid_from_file_system $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name $scsi_lun_id # Import the clone giving it a new PV ID and VG UUID new_sr_uuid=`uuidgen` echo ssh root@$xen_host_ip vgimportclone --basevgname VG_XenStorage-$new_sr_uuid --import $pv_device ssh root@$xen_host_ip vgimportclone --basevgname VG_XenStorage-$new_sr_uuid --import $pv_device # get the new VG UUID which is also what Xen uses for the SR UUID sr_uuid=`ssh root@$xen_host_ip "pvs 2>/dev/null" | egrep "$pv_device.*VG_XenStorage-" | awk '{print substr($2,length("VG_XenStorage-")+1)}'` echo sr_uuid=$sr_uuid if [ -z $sr_uuid ]||[ $sr_uuid != $new_sr_uuid ];then echo bad sr_uuid exit fi attach_sr_xen $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name $sr_name # pvscan to get rid of some Linux duplicate dev errors echo ssh root@$xen_host_ip pvscan ssh root@$xen_host_ip pvscan 2>/dev/null echo -n waiting for VDI count to settle : prev_num_vdis=`ssh root@$xen_host_ip "xe vdi-list sr-uuid=$sr_uuid" | grep name-label | wc -l` echo -n $prev_num_vdis" " sleep 5 num_vdis=`ssh root@$xen_host_ip "xe vdi-list sr-uuid=$sr_uuid" | grep name-label | wc -l` echo -n $num_vdis" " while [ $num_vdis != $prev_num_vdis ];do sleep 5 num_vdis=`ssh root@$xen_host_ip "xe vdi-list sr-uuid=$sr_uuid" | grep name-label | wc -l` echo -n $num_vdis" " prev_num_vdis=$num_vdis done echo "" metadata_sr_uuid=`echo $sr_uuid | awk '{for(i=1;i<=length($1);i++){c=substr($1,i,1);if(c=="-"){o=o"--"}else{o=o""c}};print o}'` echo ssh root@$xen_host_ip "cp VG_XenStorage--$metadata_sr_uuid""-MGT ." ssh root@$xen_host_ip "cp /dev/mapper/VG_XenStorage--$metadata_sr_uuid""-MGT ." for vdi_uuid in `ssh root@$xen_host_ip lvs VG_XenStorage-$sr_uuid | grep VHD\- | awk '{print substr($1,length("VHD-")+1)}'`;do new_uuid=`uuidgen` echo ssh root@$xen_host_ip "sed -i \"s/$vdi_uuid/$new_uuid/g\" VG_XenStorage--$metadata_sr_uuid""-MGT" ssh root@$xen_host_ip "sed -i \"s/$vdi_uuid/$new_uuid/g\" VG_XenStorage--$metadata_sr_uuid""-MGT" echo ssh root@$xen_host_ip "lvrename /dev/VG_XenStorage-$sr_uuid/VHD-$vdi_uuid /dev/VG_XenStorage-$sr_uuid/VHD-$new_uuid" ssh root@$xen_host_ip "lvrename /dev/VG_XenStorage-$sr_uuid/VHD-$vdi_uuid /dev/VG_XenStorage-$sr_uuid/VHD-$new_uuid" done echo ssh root@$xen_host_ip "cp VG_XenStorage--$metadata_sr_uuid""-MGT /dev/mapper/VG_XenStorage--$metadata_sr_uuid""-MGT" ssh root@$xen_host_ip "cp VG_XenStorage--$metadata_sr_uuid""-MGT /dev/mapper/VG_XenStorage--$metadata_sr_uuid""-MGT" echo ssh root@$xen_host_ip "rm -f VG_XenStorage--$metadata_sr_uuid""-MGT" ssh root@$xen_host_ip "rm -f VG_XenStorage--$metadata_sr_uuid""-MGT" echo ssh root@$xen_host_ip "xe sr-scan uuid=$sr_uuid" ssh root@$xen_host_ip "xe sr-scan uuid=$sr_uuid" detach_sr $xen_host_ip $iscsi_device_ip $iscsi_device_target_iqn $iscsi_vol_name $sr_name }