存储技术

  • DAS:直接附加存储
  • NAS:网络附加存储,文件服务器通过文件共享协议NFS(network file system网络文件系统),CIFS(comment Internet file system通用互联网文件系统),将自己的目录共享给客户端,属于文件级别的共享
  • SAN:存储区域网络
  • FC-SAN:光纤存储网络
  • IP-SAN:以太网存储网络,使用的最广泛的标准就是iscsi
  • ISCSI:(Internet small computer system interface),互联网小型计算机系统接口 IDE:并口 SATA:串口 SCSI:(small computer system interface)SCSI协议

ISCSI逻辑图

ISCSI target:目标端(共享端),将块数据进行共享

ISCSI initiator:发起端(客户端),将以太网卡虚拟成ISCSI网卡,通过以太网传输SCSI协议至目标端,找到目标端并挂载目标端共享的设备

iqn格式

iqn:iscsi限定名称

格式:iqn.日期.反向域名:唯一标识

iqn.2019-07.com.server.www:disk

ISCSI的配置

实验环境

  • 添加一块硬盘,并划分一个物理分区(sdb1)
  • 防火墙放行3260端口
角色targetinitiator
IP地址192.168.1.11192.168.1.22

target

启动target管理工具

[root@target ~]# systemctl start target

进入target管理工具

[root@target ~]# targetcli
targetcli shell version 2.1.fb46
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 disk /dev/sdb1

Created block storage object disk using /dev/sdb1.
/> ls
o- / .......................................................................... [...]
o- backstores ............................................................... [...]
| o- block ................................................... [Storage Objects: 1]
| | o- disk .......................... [/dev/sdb1 (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]

创建共享磁盘(iqn.2019-08.com.server.www:disk)

/> iscsi/ create iqn.2019-08.com.server.www:disk

Created target iqn.2019-08.com.server.www:disk.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls
o- / .......................................................................... [...]
o- backstores ............................................................... [...]
| o- block ................................................... [Storage Objects: 1]
| | o- disk .......................... [/dev/sdb1 (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: 1]
| o- iqn.2019-08.com.server.www:disk .................................... [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]
o- loopback .......................................................... [Targets: 0]

创建acl

# 将访问主机加入设备ACL,这样主机才能访问到这个设备
/> iscsi/iqn.2019-08.com.server.www:disk/tpg1/acls create iqn.2019-08.com.client.www:client

Created Node ACL for iqn.2019-08.com.client.www:client
/> ls
o- / .......................................................................... [...]
o- backstores ............................................................... [...]
| o- block ................................................... [Storage Objects: 1]
| | o- disk .......................... [/dev/sdb1 (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: 1]
| o- iqn.2019-08.com.server.www:disk .................................... [TPGs: 1]
| o- tpg1 ................................................ [no-gen-acls, no-auth]
| o- acls ........................................................... [ACLs: 1]
| | o- iqn.2019-08.com.client.www:client ..................... [Mapped LUNs: 0]
| o- luns ........................................................... [LUNs: 0]
| o- portals ..................................................... [Portals: 1]
| o- 0.0.0.0:3260 ...................................................... [OK]
o- loopback .......................................................... [Targets: 0]

使用Block定义存储节点上的lun

/> iscsi/iqn.2019-08.com.server.www:disk/tpg1/luns create /backstores/block/disk 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-08.com.client.www:client
/> ls
o- / .......................................................................... [...]
o- backstores ............................................................... [...]
| o- block ................................................... [Storage Objects: 1]
| | o- disk ............................ [/dev/sdb1 (0 bytes) write-thru activated]
| | 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: 1]
| o- iqn.2019-08.com.server.www:disk .................................... [TPGs: 1]
| o- tpg1 ................................................ [no-gen-acls, no-auth]
| o- acls ........................................................... [ACLs: 1]
| | o- iqn.2019-08.com.client.www:client ..................... [Mapped LUNs: 1]
| | o- mapped_lun0 ................................... [lun0 block/disk (rw)]
| o- luns ........................................................... [LUNs: 1]
| | o- lun0 ....................... [block/disk (/dev/sdb1) (default_tg_pt_gp)]
| o- portals ..................................................... [Portals: 1]
| o- 0.0.0.0:3260 ...................................................... [OK]
o- loopback .......................................................... [Targets: 0]

修改IP(先删除后添加)

/> iscsi/iqn.2019-08.com.server.www:disk/tpg1/portals/ delete 0.0.0.0 3260 
Deleted network portal 0.0.0.0:3260

/> iscsi/iqn.2019-08.com.server.www:disk/tpg1/portals create 192.168.1.11 3260
Using default IP port 3260
Created network portal 192.168.1.11:3260.
/> ls
o- / .......................................................................... [...]
o- backstores ............................................................... [...]
| o- block ................................................... [Storage Objects: 1]
| | o- disk ............................ [/dev/sdb1 (0 bytes) write-thru activated]
| | 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: 1]
| o- iqn.2019-08.com.server.www:disk .................................... [TPGs: 1]
| o- tpg1 ................................................ [no-gen-acls, no-auth]
| o- acls ........................................................... [ACLs: 1]
| | o- iqn.2019-08.com.client.www:client ..................... [Mapped LUNs: 1]
| | o- mapped_lun0 ................................... [lun0 block/disk (rw)]
| o- luns ........................................................... [LUNs: 1]
| | o- lun0 ....................... [block/disk (/dev/sdb1) (default_tg_pt_gp)]
| o- portals ..................................................... [Portals: 1]
| o- 192.168.1.11:3260 ................................................. [OK]
o- loopback .......................................................... [Targets: 0]

保存并退出

/> 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

添加防火墙规则(放行3260端口)

[root@localhost ~]# firewall-cmd --add-rich-rule "rule family=ipv4 source address=192.168.1.0/24 port port=3260 protocol=tcp accept"
success
[root@localhost ~]# firewall-cmd --add-rich-rule "rule family=ipv4 source address=192.168.1.0/24 port port=3260 protocol=tcp accept" --permanent 
success

initiator

启动ISCSI

[root@initiator ~]# systemctl start iscsi

修改ISCSI名称并重启

[root@localhost ~]# vim /etc/iscsi/initiatorname.iscsi
# InitiatorName=上面创建的acl
InitiatorName=iqn.2019-08.com.client.www:client

[root@localhost ~]# systemctl restart iscsi

通过IP发现target端

[root@localhost ~]# iscsiadm -m discovery -p 192.168.1.11:3260 -t sendtargets
192.168.1.11:3260,1 iqn.2019-08.com.server.www:disk

发起ISCSI登录

[root@localhost ~]# iscsiadm -m node -T iqn.2019-08.com.server.www:disk -l
# 已返回successful成功
Logging in to [iface: default, target: iqn.2019-08.com.server.www:disk, portal: 192.168.1.11,3260] (multiple)
Login to [iface: default, target: iqn.2019-08.com.server.www:disk, portal: 192.168.1.11,3260] successful.
Last modification:July 23rd, 2020 at 09:31 pm
如果觉得我的文章对你有用,请随意赞赏