配置iSCSI
https://shimo.im/doc/Sx5n2xnFhBYLNkKt?r=08X9DM/%E3%80%8CiSER%E3%80%8D
一、Target(Server)端配置
- 安装管理工具:yum install -y targetcli
[root@node1 ~]# targetcli
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>
- 用一个块设备创建一个后端存储对象
/> cd /backstores/block
/backstores/block> create raid5ssd /dev/nvme0n1p1
Created block storage object raid5ssd using /dev/nvme0n1p1.
/backstores/block> cd /
/> ls
o- / ............................................................. [...]
o- backstores .................................................. [...]
| o- block ...................................... [Storage Objects: 1]
| | o- raid5ssd .... [/dev/nvme0n1p1 (0 bytes) 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]
o- iscsi ................................................ [Targets: 0]
o- loopback ............................................. [Targets: 0]
o- srpt ................................................. [Targets: 0]
/>
- 创建一个iscsi 的target
/> cd iscsi
/iscsi> create iqn.2018-11.com.jay:server1:ssdserver
Created target iqn.2018-11.com.jay:server1:ssdserver.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi .................................................. [Targets: 1]
o- iqn.2018-11.com.jay:server1:ssdserver ................... [TPGs: 1]
o- tpg1 ..................................... [no-gen-acls, no-auth]
o- acls ................................................ [ACLs: 0]
o- luns ................................................ [LUNs: 0]
o- portals .......................................... [Portals: 1]
o- 0.0.0.0:3260 ........................................... [OK]
/iscsi>
- 创建逻辑单元号,将逻辑单元和后端物理存储对象关联
/iscsi> cd iqn.2018-11.com.jay:server1:ssdserver/tpg1/luns
/iscsi/iqn.20...ver/tpg1/luns> create lun=0 storage_object=/backstores/block/raid5ssd
Created LUN 0.
/iscsi/iqn.20...ver/tpg1/luns>
/iscsi/iqn.20...ver/tpg1/luns> ls
o- luns ...................................................... [LUNs: 1]
o- lun0 ......... [block/raid5ssd (/dev/nvme0n1p1) (default_tg_pt_gp)]
/iscsi/iqn.20...ver/tpg1/luns> cd ..
/iscsi/iqn.20...sdserver/tpg1>
- 创建TPG的访问端口
说明:10.0.0.1是本地IB网卡上的IP地址
/iscsi/iqn.20...ver/tpg1/luns> cd ..
/iscsi/iqn.20...sdserver/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 10.0.0.1
Using default IP port 3260
Created network portal 10.0.0.1:3260.
/iscsi/iqn.20.../tpg1/portals> cd ..
/iscsi/iqn.20...sdserver/tpg1> ls
o- tpg1 ......................................... [no-gen-acls, no-auth]
o- acls .................................................... [ACLs: 0]
o- luns .................................................... [LUNs: 1]
| o- lun0 ....... [block/raid5ssd (/dev/nvme0n1p1) (default_tg_pt_gp)]
o- portals .............................................. [Portals: 1]
o- 10.0.0.1:3260 .............................................. [OK]
/iscsi/iqn.20...sdserver/tpg1>
- 启动iSER
/iscsi/iqn.20...sdserver/tpg1> cd portals/10.0.0.1:3260
/iscsi/iqn.20...10.0.0.1:3260> enable_iser boolean=True
iSER enable now: True
/iscsi/iqn.20...10.0.0.1:3260> cd ..
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ................................................ [Portals: 1]
o- 10.0.0.1:3260 .............................................. [iser]
/iscsi/iqn.20.../tpg1/portals>
- 设置tpg的访问属性
/iscsi/iqn.20.../tpg1/portals> cd ..
/iscsi/iqn.20...sdserver/tpg1> set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
Parameter demo_mode_write_protect is now '0'.
Parameter authentication is now '0'.
Parameter generate_node_acls is now '1'.
Parameter cache_dynamic_acls is now '1'.
/iscsi/iqn.20...sdserver/tpg1> get attribute
ATTRIBUTE CONFIG GROUP
======================
authentication=0
----------------
If set to 1, enforce authentication for this TPG.
cache_dynamic_acls=1
--------------------
If set to 1 in demo mode, cache dynamically generated ACLs.
default_cmdsn_depth=64
----------------------
Default CmdSN (Command Sequence Number) depth.
default_erl=0
-------------
Default Error Recovery Level.
demo_mode_discovery=1
---------------------
If set to 1 in demo mode, enable discovery.
demo_mode_write_protect=0
-------------------------
If set to 1 in demo mode, prevent writes to LUNs.
fabric_prot_type=0
------------------
Fabric DIF protection type.
generate_node_acls=1
--------------------
If set to 1, allow all initiators to login (i.e. demo mode).
login_timeout=15
----------------
Login timeout value in seconds.
netif_timeout=2
---------------
NIC failure timeout in seconds.
prod_mode_write_protect=0
-------------------------
If set to 1, prevent writes to LUNs.
t10_pi=0
--------
If set to 1, enable T10 Protection Information.
tpg_enabled_sendtargets=1
-------------------------
If set to 1, the SendTargets discovery response advertises the TPG only if the TPG is enabled.
/iscsi/iqn.20...sdserver/tpg1>
- 添加一个tpg
/iscsi/iqn.20...sdserver/tpg1> cd ..
/iscsi/iqn.20...er1:ssdserver> create tag=2
Created TPG 2.
Default portal not created, TPGs within a target cannot share ip:port.
/iscsi/iqn.20...er1:ssdserver> ls
o- iqn.2018-11.com.jay:server1:ssdserver ..................... [TPGs: 2]
o- tpg1 .......................................... [gen-acls, no-auth]
| o- acls .................................................. [ACLs: 0]
| o- luns .................................................. [LUNs: 1]
| | o- lun0 ..... [block/raid5ssd (/dev/nvme0n1p1) (default_tg_pt_gp)]
| o- portals ............................................ [Portals: 1]
| o- 10.0.0.1:3260 .......................................... [iser]
o- tpg2 ....................................... [no-gen-acls, no-auth]
o- acls .................................................. [ACLs: 0]
o- luns .................................................. [LUNs: 0]
o- portals ............................................ [Portals: 0]
/iscsi/iqn.20...er1:ssdserver>
二、Initiator (Client)端配置
工具安装:iscsi-initiator-utils
yum install -y iscsi-initiator-utils
- 发现Target
其中10.0.0.1是Target的访问地址
[root@node2 ~]# iscsiadm -m discovery -t st -p 10.0.0.1
10.0.0.1:3260,1 iqn.2018-11.com.jay:server1:ssdserver
- 改变传输端口模式为iSER
[root@node2 ~]# iscsiadm -m node -T iqn.2018-11.com.jay:server1:ssdserver -o update -n iface.transport_name -v iser
或者合并1,2
[root@node2 ~]# iscsiadm -m discovery -o new -o old -t st -I iser -p 10.0.0.1 -l
10.0.0.1:3260,1 iqn.2018-11.com.jay:server1:ssdserver
Logging in to [iface: iser, target: iqn.2018-11.com.jay:server1:ssdserver, portal: 10.0.0.1,3260] (multiple)
Login to [iface: iser, target: iqn.2018-11.com.jay:server1:ssdserver, portal: 10.0.0.1,3260] successful.
- 登录已经发现的target
- 登录所有的target
iscsiadm -m node -l
- 登录某个特定TargetName对应的所有Target(1个target多个tpg的情况)
iscsiadm -m node -T iqn.2018-11.com.jay:server1.ssdserver -l
- 登录某个特定IP对应的所有Target
iscsiadm -m node -p 10.0.0.1 -l
- 验证客户端是否为iser transport连接
[root@node2 ~]# iscsiadm -m node -o show | grep iser
iface.transport_name = iser
iface.iscsi_ifacename = iser
iface.transport_name = iser
- 如果存储上的Target下新挂载了一个SAN资源,如何在服务器上连接并识别?
用如下命令刷新(rescan)已连接的iSCSI session以识别新的SAN资源:
iscsiadm -m session -R
- 如何查看连接过来的卷?
cat /proc/scsi/scsi
7.如何注销到所有targets的连接?
iscsiadm -m node --logoutall=all //注销所有
iscsiadm -m node -u //注销
8、如何查看哪些target记录在了Open-iSCSI数据库中?
iscsiadm -m node
- 如何从Open-iSCSI数据库中删除一条target记录?
iscsiadm -m node //查看当前数据库中所有的target记录,然后删除无用的记录
iscsiadm -m node -o delete -T iqn.2018-11.com.jay:server1:ssdserver -p 10.0.0.1:3260
说明:
其中iqn.2018-11.com.jay:server1:ssdserver是某个target的名称,10.10.10.1:3260是其对应的端口地址
- 如何查看当前的连接状态?
iscsiadm -m session -o show
iser: [1] 10.10.10.236:3260,1 iqn.2018-11.com.jay:server1:ssdserver (non-flash)
说明:前面是iser,说明启用了iser扩展;前面显示tcp,说明是普通的网络连接
- 设置开机自动登录
iscsiadm -m node -o update -n node.startup -v automatic