centos 6.5環境利用iscsi搭建SAN網路儲存服務及服務端target和用戶端initiator配置詳解

來源:互聯網
上載者:User

標籤:

一、簡介iSCSI(internet SCSI)技術由IBM公司研究開發,是一個供硬體裝置使用的、可以在IP協議的上層啟動並執行SCSI指令集,這種指令集合可以實現在IP網路上運行SCSI協議,使其能夠在諸如高速千兆乙太網路上進行路由選擇。iSCSI技術是一種新儲存技術,該技術是將現有SCSI介面與乙太網路絡(Ethernet)技術結合,使伺服器可與使用IP網路的儲存裝置互相交換資料。
iSCSI是一種基於TCP/IP 的協議,用來建立和管理IP存放裝置、主機和客戶機等之間的相互串連,並建立存放區域網路(SAN)。SAN 使得SCSI 協議應用於高速資料轉送網路成為可能,這種傳輸以資料區塊層級(block-level)在多個資料存放區網路間進行。SCSI 結構基於C/S模式,其通常應用環境是:裝置互相靠近,並且這些裝置由SCSI 匯流排串連。
iSCSI 的主要功能是在TCP/IP 網路上的主機系統(啟動器 initiator)和存放裝置(目標器 target)之間進行大量資料的封裝和可靠傳輸過程。
完整的iSCSI系統的拓撲結構如下:


iSCSI簡單來說,就是把SCSI指令通過TCP/IP協議封裝起來,在乙太網路中傳輸。iSCSI 可以實現在IP網路上傳遞和運行SCSI協議,使其能夠在諸如高速千兆乙太網路上進行資料存取,實現了資料的網際傳遞和管理。基於iSCSI建立的儲存地區網(SAN)與基於光纖的FC-SAN相比,具有很好的性價比。


iSCSI屬於端到端的會話層協議,它定義的是SCSI到TCP/IP的映射(如),即Initiator將SCSI指令和資料封裝成iSCSI協議資料單元,向下提交給TCP層,最後封裝成IP資料包在IP網路上傳輸,到達Target後通過解鎖裝還原成SCSI指令和資料,再由儲存控制器發送到指定的磁碟機,從而實現SCSI命令和資料在IP網路上的透明傳輸。它整合了現有的儲存協議SCSI和網路通訊協定TCP/IP,實現了儲存與TCP/IP網路的無縫融合。在本文中,將把發起器Initiator稱為用戶端,將目標器Target稱為服務端以方便理解。


二、環境準備

作業系統:CentOS release 6.5


iSCSI Target:192.168.8.42 / scsi-target-utils-1.0.24-12.el6_5.i686


iSCSI Initiator:192.168.8.39 / iscsi-initiator-utils-6.2.0.873-10.el6.i686


防火牆、selinux已關閉
# service iptables status
iptables: Firewall is not running.


# getenforce
Disabled


三、安裝配置iSCSI Target服務端# yum install -y scsi-target-utils


添加一塊硬碟sdb,並建立兩個分區:sdb1、sdb2 類比san儲存,在initiator看來是兩塊硬碟


# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xe714b1f2.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): pDisk /dev/sdb: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe714b1f2   Device Boot      Start         End      Blocks   Id  SystemCommand (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-10443, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +20GCommand (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (2613-10443, default 2613): Using default value 2613Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +30GCommand (m for help): pDisk /dev/sdb: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe714b1f2   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1        2612    20980858+  83  Linux/dev/sdb2            2613        6529    31463302+  83  LinuxCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.


使配置生效
# partx -a /dev/sdbBLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2# cat /proc/partitionsmajor minor  #blocks  name   8        0  125829120 sda   8        1     512000 sda1   8        2  125316096 sda2   8       16   83886080 sdb   8       17   20980858 sdb1   8       18   31463302 sdb2 253        0    4096000 dm-0 253        1   20480000 dm-1 253        2   25600000 dm-2 253        3   30720000 dm-3


啟動target服務,通過ss -tnl可以看到3260連接埠已開啟
# service tgtd start

四、服務端組態管理工具tgtadm的使用1、建立一個target id 為1 name為iqn.2016-04.com.chinasoft.san:1d
# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2016-04.com.chinasoft.san:1


2、顯示所有target
# tgtadm -L iscsi -o show -m target


3、向某ID為1的裝置上添加一個新的LUN,其號碼為1,且此裝置提供給initiator使用。/dev/sdb1是某“塊裝置”的路徑,此塊裝置也可以是raid或lvm裝置。lun0已經被系統預留
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/sdb1


4、定義某target的基於主機的存取控制清單,192.168.8.0/24表示允許訪問此target的initiator用戶端的列表:
如開放給192.168.8.0/24網路中的主機訪問:
# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.8.0/24


再次向ID為1的裝置上添加一個新的LUN,號碼為2
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b /dev/sdb2
# tgtadm -L iscsi -o show -m target


5、解除target的基於主機的存取控制清單許可權


# tgtadm -L iscsi -o unbind -m target -t 1 -I 192.168.8.0/24
# tgtadm -L iscsi -o show -m target


6、刪除target中的LUN
# tgtadm -L iscsi -o delete -m target -t 1
# tgtadm -L iscsi -o show -m target


五、用戶端initiator配置iscsiadm工具的使用安裝iscsi-initiator-utils工具
# yum install -y iscsi-initiator-utils# echo "InitiatorName=`iscsi-iname -p iqn.2016-04.com.chinasoft`" > /etc/iscsi/initiatorname.iscsi# echo "InitiatorAlias=initiator1" >> /etc/iscsi/initiatorname.iscsi# cat /etc/iscsi/initiatorname.iscsiInitiatorName=iqn.2016-04.com.chinasoft:59b0936b38a3InitiatorAlias=initiator1

# service iscsi start# chkconfig iscsi on# chkconfig --list iscsiiscsi           0:off1:off 2:on3:on 4:on5:on 6:off

iscsiadm是個模式化的工具,其模式可通過-m或--mode選項指定,常見的模式有discovery、node、fw、session、host、iface幾個,如果沒有額外指定其它選項,則discovery和node會顯示其相關的所有記錄;session用於顯示所有的活動會話和串連,fw顯示所有的啟動韌體值,host顯示所有的iSCSI主機,iface顯示/var/lib/iscsi/ifaces目錄中的所有ifaces設定。


iscsiadm -m discovery [ -d debug_level ] [ -P printlevel ] [ -I iface -t type -p ip:port [ -l ] ] iscsiadm -m node [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ [ -T tar-getname -p ip:port -I iface ] [ -l | -u | -R | -s] ] [ [ -o operation ] -d, --debug=debug_level   顯示debug資訊,層級為0-8;-l, --login-t, --type=type  這裡可以使用的類型為sendtargets(可簡寫為st)、slp、fw和 isns,此選項僅用於discovery模式,且目前僅支援st、fw和isns;其中st表示允許每個iSCSI target發送一個可用target列表給initiator;-p, --portal=ip[:port]  指定target服務的IP和連接埠;-m, --mode op  可用的mode有discovery, node, fw, host iface 和 session-T, --targetname=targetname  用於指定target的名字-u, --logout -o, --op=OPEARTION:指定針對discoverydb資料庫的操作,其僅能為new、delete、update、show和nonpersistent其中之一;-I, --interface=[iface]:指定執行操作的iSCSI介面,這些介面定義在/var/lib/iscsi/ifaces中;


發現裝置
# iscsiadm -m discovery -t st -p 192.168.8.42Starting iscsid:                                           [  OK  ]192.168.8.42:3260,1 iqn.2016-04.com.chinasoft.san:1# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -lLogging in to [iface: default, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] (multiple)Login to [iface: default, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] successful.


驗證能否看到服務端裝置
# fdisk -l /dev/sd[a-z]


對裝置sdc分區
# fdisk /dev/sdcDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xe3266877.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-20489, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-20489, default 20489): +3GCommand (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (3074-20489, default 3074): Using default value 3074Last cylinder, +cylinders or +size{K,M,G} (3074-20489, default 20489): +2GCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.


# partx -a /dev/sdcBLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2# cat /proc/partitions major minor  #blocks  name   8        0  125829120 sda   8        1     512000 sda1   8        2  125316096 sda2   8       16   83886080 sdb 253        0   30720000 dm-0 253        1    4096000 dm-1 253        2   25600000 dm-2 253        3   30720000 dm-3 253        4   10240000 dm-4   8       48   31463302 sdd   8       32   20980858 sdc   8       33    3146736 sdc1   8       34    2098176 sdc2


格式化
# mke2fs -t ext4 /dev/sdc1掛載# mount /dev/sdc1 /mnt# cd /mnt# lslost+found# cp /etc/rc.d/rc.sysinit ./# lslost+found  rc.sysinit# vim rc.sysinit


此時通過查看服務端target的分區情況並沒有發生改變



關閉iSCSI伺服器端
關閉iSCSI在開機重啟或重啟iscsi服務時自動對target進行重新串連,就需要在該客戶機徹底將該target條目資訊刪除:
登出target會話:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -u
Logging out of session [sid: 1, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260]
Logout of [sid: 1, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] successful.


刪除target條目的記錄:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -o delete


在用戶端刪除了之前discovery發現的可用的target條目,則重啟或重啟服務後將不會自動進行重串連。
# ls /var/lib/iscsi/send_targets/
192.168.8.42,3260
# ls /var/lib/iscsi/
ifaces  isns  nodes  send_targets  slp  static
# rm -rf /var/lib/iscsi/*
# ls /var/lib/iscsi/


六、通過編輯檔案的方式定義target服務端# cd /etc/tgt/
[# ls
targets.conf
[[email protected] tgt]# vim targets.conf 
添加定義:
<target iqn.2016-04.com.chinasoft.san:2>
    backing-store /dev/sdb2
    initiator-address 192.168.8.0/24
</target>


# service tgtd restart
Stopping SCSI target daemon:                               [  OK  ]
Starting SCSI target daemon:                               [  OK  ]


# tgtadm -L iscsi -o show -m target


至此iscsi服務端target及用戶端initiator工具常用配置已講解完畢


centos 6.5環境利用iscsi搭建SAN網路儲存服務及服務端target和用戶端initiator配置詳解

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.