在SAN存儲系統中,LIO是把儲存設備直接轉化為可用存儲資源的高效工具,它實作了基于檔案/塊裝置/ramdisk甚至回環裝置建立儲存設備的iscsi target接口和CLI。 通過iSCSI initiator通路iSCSI target 的典型應用場景和聯接如下圖所示意:
<a href="http://s1.51cto.com/wyfs02/M00/82/FD/wKiom1dn49KzhEujAAMDcvI2nJE043.png" target="_blank"></a>
上圖非常直覺地顯示了基于ram、/dev/下的裝置以及檔案,建立iSCSI target的資料流。如果更深入地再往下看,可以看到它和底層檔案系統、卷管理的接口如下所示:
<a href="http://s4.51cto.com/wyfs02/M01/82/FC/wKioL1dn5ATD03SZAACig3_OBpg732.png" target="_blank"></a>
厘清了iSCSI的應用模式和軟體層次後,就不難了解如何建立iscsi target 裝置了,并且也會了解為何
在資料傳輸之前,需要iscsi initiator 和iscsi target 裝置建立起連接配接了。
下面通過具體的指令,舉例說明在linux作業系統裡面如何建立iscsi target、建立iscsi連結和使用iscsi資源。首先需要在存儲資源所挂載的機器上用targetcli建立 target:
[root@localhost]# targetcli /backstores/block create my_ssd /dev/disk/by-id/wwn-0x55cd2e404b7b8ced-part5
\Created block storage object my_ssd using /dev/disk/by-id/wwn-0x55cd2e404b7b8ced-part5.
[root@localhost]# targetcli /iscsi create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
[root@localhost]# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120/tpg1/luns create /backstores/block/my_ssd
Created LUN 0.
You have new mail in /var/spool/mail/root
[root@localhost]# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120/tpg1 set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1
Parameter authentication is now '0'.
Parameter demo_mode_write_protect is now '0'.
Parameter generate_node_acls is now '1'.
[root@localhost]# targetcli saveconfig myssd.config
Configuration saved to myssd.config
上面指令還把目前配置儲存到檔案myssd.config當中去,機器重新開機後,還可以從這個檔案
恢複到目前設定,這樣就可以避免需要重新輸入上面的指令:
[root@localhost]# targetcli clearconfig confirm=True
All configuration cleared
如果上面沒有制定檔案名,預設會儲存到/etc/target/saveconfig.json檔案當中去。
[root@localhost]# targetcli restoreconfig myssd.config
接着需要在initiator 端連接配接到target 端,先探測有沒有iscsi能被找到,如果找到自動連接配接上去:
[root@localhost PlxSdk]# iscsiadm -m discovery -t st -p 10.10.2.33 -l
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120, portal: 10.10.2.33,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120, portal: 10.10.2.33,3260] successful.
這時能從/dev裝置下看到多出一個裝置:
lrwxrwxrwx. 1 root root 9 Jun 20 20:19 ip-10.10.2.33:3260-iscsi-iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120-lun-0 -> ../../sdr
這就證明iscsi target已經映射到了initiator /dev/sdr這個裝置上,在initiator端對/dev/sdr進行讀寫通路,就相當于往遠端的10.10.2.33機器上的/dev/disk/by-id/wwn-0x55cd2e404b7b8ced-part5進行讀寫。
當然,使用完了之後,可以用下面的指令斷開連接配接:
[root@localhost PlxSdk]# iscsiadm -m session -u
Logging out of session [sid: 1, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.b5928f6012db, portal: 10.10.2.33,3260]
Logging out of session [sid: 2, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.beb1fd396120, portal: 10.10.2.33,3260]
最後運作測試程式,下面以vdbench 為例,開始測試:
[root@localhost vdbench]# cat ssd_param && ./vdbench -f ssd_param -k -o ssd_vdbench.out
sd=sd2,lun=/dev/sdr,openflags=o_direct,size=500m,threads=24
wd=wd1,xfersize=4k,rdpct=0,seekpct=100
rd=rd1,wd=wd1,sd=*,iorate=max,elapsed=5,interval=1,warmup=5,threads=24
Vdbench distribution: vdbench504
For documentation, see 'vdbench.pdf'.
20:25:40.991 Created output directory '/home/vdbench_qichao/ssd_vdbench.out'
20:25:41.021 input argument scanned: '-fssd_param'
20:25:41.021 input argument scanned: '-k'
20:25:41.021 input argument scanned: '-ossd_vdbench.out'
20:25:41.153 Starting slave: /home/vdbench/vdbench SlaveJvm -m localhost -n localhost-10-160620-20.25.40.968 -l localhost-0 -p 5570
20:25:41.627 All slaves are now connected
20:25:43.001 Starting RD=rd1; I/O rate: Uncontrolled MAX; elapsed=5 warmup=5; For loops: threads=24
20:25:54.068 Vdbench execution completed successfully. Output directory: /home/vdbench/ssd_vdbench.out
參考文檔和連結:
http://linux-iscsi.org/wiki/Targetcli
http://www.linux-iscsi.org/Doc/LIO%20Admin%20Manual.pdf
本文轉自存儲之廚51CTO部落格,原文連結:http://blog.51cto.com/xiamachao/1791157 ,如需轉載請自行聯系原作者