iSCSI(Internet SCSI):支持從客戶端通過IP向遠程服務器上的SCSI存儲設備發送SCSI命令
SCSI 結構基於客戶/服務器模式,其通常應用環境是:設備互相靠近,並且這些設備由 SCSI 總線連接。iSCSI 的主要功能是在 TCP/IP 網絡上的主機系統(啓動器 initiator)和存儲設備(目標器 target)之間進行大量數據的封裝和可靠傳輸過程。此外,iSCSI 提供了在 IP 網絡封裝 SCSI 命令,且運行在 TCP 上。
限定名稱格式:iqn.yyyy-mm.{reverse domain}:label
一、服務器端配置如下:
1.安裝並啓動服務
[root@localhost Desktop]# yum install targetcli -y #安裝iSCSI目標軟件包 [root@localhost Desktop]# systemctl start target #啓動target服務 [root@localhost Desktop]# systemctl enable target #設置服務開機自啓動
2.進入iSCSI交互式配置模式
[root@localhost Desktop]# targetcli #輸入targetcli命令 targetcli shell version 2.1.fb34 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> ls o- / ..................................................................... [...] o- backstores .......................................................... [...] | o- block .............................................. [Storage Objects: 0] | o- fileio ............................................. [Storage Objects: 0] | o- pscsi .............................................. [Storage Objects: 0] | o- ramdisk ............................................ [Storage Objects: 0] o- iscsi ........................................................ [Targets: 0] o- loopback ..................................................... [Targets: 0] /> /backstores/block create pt.example.disk1 /dev/sda4 #使用/dev/sda4創建ISCSI遠程存儲塊pt.example.disk1 Created block storage object pt.example.disk1 using /dev/sda4. /> /iscsi create iqn.2016-03.pt.example1:storage #創建要分享的ISCSI文件名(格式必須是iqn.yyyy-mm.{reverse domain}:label) Created target iqn.2016-03.pt.example1:storage. Created TPG 1. /> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/acls create iqn.2016-03.pt.example2:desktop #指定訪問ISCSI設備塊的ACL權限(即允許initiator name爲iqn.2016-03.pt.example2:desktop的客戶端可以訪問) Created Node ACL for iqn.2016-03.pt.example2:desktop /> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/luns create /backstores/block/pt.example.disk1 #將創建的ISCSI遠程存儲塊加入進來 Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2016-03.pt.example2:desktop /> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/portals create 172.25.254.209 #打開訪問所使用的端口 Using default IP port 3260 Created network portal 172.25.254.209:3260. /> ls #完成後如下所示 o- / ..................................................................... [...] o- backstores .......................................................... [...] | o- block .............................................. [Storage Objects: 1] | | o- pt.example.disk1 ............ [/dev/sda4 (1.0GiB) write-thru activated] | o- fileio ............................................. [Storage Objects: 0] | o- pscsi .............................................. [Storage Objects: 0] | o- ramdisk ............................................ [Storage Objects: 0] o- iscsi ........................................................ [Targets: 1] | o- iqn.2016-03.pt.example1:storage ............................... [TPGs: 1] | o- tpg1 ........................................... [no-gen-acls, no-auth] | o- acls ...................................................... [ACLs: 1] | | o- iqn.2016-03.pt.example2:desktop .................. [Mapped LUNs: 1] | | o- mapped_lun0 .................. [lun0 block/pt.example.disk1 (rw)] | o- luns ...................................................... [LUNs: 1] | | o- lun0 ......................... [block/pt.example.disk1 (/dev/sda4)] | o- portals ................................................ [Portals: 1] | o- 172.25.254.209:3260 .......................................... [OK] o- loopback ..................................................... [Targets: 0] /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json
設置防火牆
[root@localhost Desktop]# firewall-cmd --permanent --add-port=3260/tcp #將要使用的端口加入到防火牆允許之中 success [root@localhost Desktop]# firewall-cmd --reload #重載防火牆的設置 success
二、客戶端配置如下:
[root@localhost Desktop]# yum install iscsi-initiator-utils -y #安裝iSCSI發起端軟件包 [root@localhost Desktop]# vim /etc/iscsi/initiatorname.iscsi #設置發起端的IQN InitiatorName=iqn.2016-03.pt.example2:desktop [root@localhost Desktop]# iscsiadm -m discovery -t st -p 172.25.254.209 #獲得可以訪問共享的塊 172.25.254.209:3260,1 iqn.2016-03.pt.example1:storage [root@localhost Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -l #連接服務端的ISCSI目標塊到本機 Logging in to [iface: default, target: iqn.2016-03.pt.example1:storage, portal: 172.25.254.209,3260] (multiple) Login to [iface: default, target: iqn.2016-03.pt.example1:storage, portal: 172.25.254.209,3260] successful. [root@localhost Desktop]# fdisk -l #查看磁盤,多了/dev/sdb Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c235a Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris /dev/sda3 4605952 35796991 15595520 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes Disk label type: dos Disk identifier: 0x00000000 Device Boot Start End Blocks Id System
然後就可以正常使用所得到的ISCSI資源,正常格式化,並掛載。
########中斷使用ISCSI目標#########
先將掛載進行卸載,確保沒有使用目標所提供的任何設備
[root@localhost Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -u #退出ISCSI目標,以暫時斷開連接 [root@localhost Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -o -delete #刪除本地連接ISCSI目標的本地記錄,以永久斷開連接