測驗環境
centos 7.2
服務端:192.168.184.139
客戶端:192.168.184.133
iscsi簡介
iSCSI(internet SCSI)技術由IBM公司研究開發,是一個供硬體設備使用的、可以在IP協議的上層運行的SCSI指令集,這種指令集合可以實作在IP網路上運行SCSI協議,使其能夠在諸如高速千兆以太網上進行路由選擇,iSCSI技術是一種新儲存技術,該技術是將現有SCSI介面與以太網路(Ethernet)技術結合,使服務器可與使用IP網路的儲存裝置互相交換資料,
iSCSI 的主要功能是在TCP/IP 網路上的主機系統(啟動器 initiator)和存盤設備(目標器 target)之間進行大量資料的封裝和可靠傳輸程序,iSCSI可分享的設備型別有很多,包括鏡像檔案(*.img)、磁區(partition)、物理硬碟、raid設備、邏輯卷等,
服務端iscsi target安裝
yum install -y targetcli
[root@#localhost ~]# yum install -y targetcli
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Package targetcli-2.1.53-1.el7_9.noarch already installed and latest version
Nothing to do
[root@#localhost ~]#
客戶端iscsi initiator安裝
yum install -y iscsi-initiator-utils
配置iSCSI Target服務
服務端配置
在192.168.184.139上進入targetcli中進行設定
[root@server1 ~]# targetcli
[root@Centos ~]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>
cd backstores/block
[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
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]
/> cd backstores/block
/backstores/block>
建立塊存盤
/> cd backstores/block
/backstores/block> create nsd /dev/sdb
Created block storage object nsd using /dev/sdb.
/backstores/block> create iqn.2019-05.com.share-disk:server
Missing required parameter dev
/backstores/block> cd ..
/backstores> ls
o- backstores ................................................................................................................ [...]
o- block .................................................................................................... [Storage Objects: 1]
| o- nsd ............................................................................. [/dev/sdb (10.0GiB) write-thru deactivated]
| o- alua ..................................................................................................... [ALUA Groups: 1]
| o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
o- fileio ................................................................................................... [Storage Objects: 0]
o- pscsi .................................................................................................... [Storage Objects: 0]
o- ramdisk .................................................................................................. [Storage Objects: 0]
/backstores>
配置iscsi target命名
create iqn.2019-05.com.share-disk:server
/iscsi> cd /iscsi
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi> create iqn.2019-05.com.share-disk:server
Created target iqn.2019-05.com.share-disk:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>
設定acl
/iscsi> cd iqn.2019-05.com.share-disk:server/tpg1/acls
/iscsi/iqn.20...ver/tpg1/acls> create iqn.2019-05.com.share-disk:node33
Created Node ACL for iqn.2019-05.com.share-disk:node33
/iscsi/iqn.20...ver/tpg1/acls> ls
o- acls .................................................................................................................. [ACLs: 1]
o- iqn.2019-05.com.share-disk:node33 ............................................................................ [Mapped LUNs: 0]
/iscsi/iqn.20...ver/tpg1/acls>
創建lun
/> cd /backstores/block/nsd/
/backstores/block/nsd> pwd
/backstores/block/nsd
/backstores/block/nsd> cd /iscsi/iqn.2019-05.com.share-disk:server/tpg1/luns
/iscsi/iqn.20...ver/tpg1/luns> create /backstores/block/nsd
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-05.com.share-disk:node33
/iscsi/iqn.20...ver/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
o- lun0 ................................................................................ [block/nsd (/dev/sdb) (default_tg_pt_gp)]
/iscsi/iqn.20...ver/tpg1/luns>
配置portal
/iscsi/iqn.20...k:server/tpg1> cd portals/
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ............................................................................................................ [Portals: 1]
o- 0.0.0.0:3260 ............................................................................................................. [OK]
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.184.139 3260
Using default IP port 3260
Created network portal 192.168.184.139:3260.
/iscsi/iqn.20.../tpg1/portals>
配置驗證用戶名和密碼
/iscsi/iqn.20...ver/tpg1/acls> cd iqn.2019-05.com.share-disk:node33/
/iscsi/iqn.20...e-disk:node33> set auth userid=qin
Parameter userid is now 'qin'.
/iscsi/iqn.20...e-disk:node33> set auth password=111111
Parameter password is now '111111'.
/iscsi/iqn.20...e-disk:node33>
保存服務端配置資訊并退出
/iscsi/iqn.20...e-disk:node33> cd /
/> saveconfig
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@Centos ~]#
192.168.184.133客戶端操作
查找服務端iscsi設備
[root@localhost /]# iscsiadm -m discovery -t st -p 192.168.184.139
192.168.184.139:3260,1 iqn.2019-05.com.share-disk:server
登錄服務端:
iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l
[root@localhost /]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (12 - iSCSI driver not found. Please make sure it is loaded, and retry the operation)
iscsiadm: Could not log into all portals
[root@localhost /]#
報錯:
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (12 - iSCSI driver not found. Please make sure it is loaded, and retry the operation)
iscsiadm: Could not log into all portals
解決:重啟服務器后,報新的錯誤
[root@localhost ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
解決:配置chap驗證密碼
vi /etc/iscsi/iscsid.conf
# *************
# CHAP Settings
# *************
# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = qin
node.session.auth.password = 111111
配置/etc/iscsi/initiatorname.iscsi
[root@localhost iscsi]# cat initiatorname.iscsi
InitiatorName=iqn.2019-05.com.share-disk:node33
[root@localhost iscsi]#
再次登錄:
[root@localhost ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
還是報錯認證失敗,參考https://blog.csdn.net/manom/article/details/89331283
[root@localhost nodes]# rm -rf *
[root@localhost nodes]# cd ..
[root@localhost iscsi]# ls
ifaces isns nodes send_targets slp static
[root@localhost iscsi]# cd send_targets/
[root@localhost send_targets]# ls
192.168.184.133,3260 192.168.184.139,3260
[root@localhost send_targets]# rm -rf *
[root@localhost send_targets]# cd ..
[root@localhost iscsi]# tree /var/lib/iscsi/
bash: tree: command not found...
[root@localhost iscsi]# yum install tree
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 base 46 k
Transaction Summary
===========================================================================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@localhost iscsi]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
├── slp
└── static
6 directories, 0 files
[root@localhost iscsi]# iscsiadm -m discovery -t st -p 192.168.184.139
192.168.184.139:3260,1 iqn.2019-05.com.share-disk:server
[root@localhost iscsi]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l
[root@localhost iscsi]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000c3579
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 62914559 29050880 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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
[root@localhost iscsi]#
登錄成功,在192.168.184.132上fdisk -l可以看到139上共享的磁盤/dev/sdb
[root@localhost iscsi]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000c3579
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 62914559 29050880 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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
故障處理
1、啟動targetcli報錯ImportError: cannot import name ALUATargetPortGroup故障
故障現象:
當前環境
[root@centos7-router ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
安裝targetcli工具包
# yum install targetcli
故障現象
[root@centos7-router ~]# targetcli
Traceback (most recent call last):
File "/usr/bin/targetcli", line 24, in <module>
from targetcli import UIRoot ### Author : Leshami
File "/usr/lib/python2.7/site-packages/targetcli/__init__.py", line 18, in <module>
from .ui_root import UIRoot ### Blog : http://blog.csdn.net/leshami
File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 30, in <module>
from .ui_backstore import complete_path, UIBackstores
File "/usr/lib/python2.7/site-packages/targetcli/ui_backstore.py", line 29, in <module>
from rtslib_fb import ALUATargetPortGroup
ImportError: cannot import name ALUATargetPortGroup
參考資料:
1、https://www.cnblogs.com/gispathfinder/p/8833488.html CentOS7系列–3.2CentOS7中配置iSCSI服務
2、https://blog.csdn.net/manom/article/details/89331283 iSCSI客戶端登陸認證失敗
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/258904.html
標籤:其他
