在开始配置之前,让我们了解一些有关 iSCSI 的基础知识。
iSCSI 缩写表示 Internet S mall C omputer System Interface,它是一种块级协议,用于通过 IP 网络共享存储设备。
iSCSI 可用于通过局域网 (LAN)、广域网 (WAN) 或者 Internet 传输数据,并可实现与位置无关的数据存储和检索。
iSCSI 数据通过网络传输的安全性如何?
这个问题可能会出现,因为数据是通过 IP 网络传输的,因此这些数据可能会受到损害,因此为了克服 iSCSI 中的这些数据,这些数据被封装在操作系统层的几个层中。
封装架构如下所示
- SCSI 有效负载由发送到磁盘和从磁盘发送的读写数据组成。
- 然后提供第一层封装。 iSCSI 工作在 OSI 模型的会话层,将 SCSI 负载封装到 iSCSI PDU 例如:Protocol Data Unit
- 随着 iSCSI PDU 向下传递到网络堆栈的各个层,它会在每一层进一步封装
- 进入网络层的 TCP 段
- 在网络层转换为 IP 数据包
- 在数据链路层转换为以太网帧
当它到达目的地的网络另一端时,它的每一层都被一层一层地撕掉,直到我们留下原始的 scsi 有效载荷。
iSCSI Initiator 被视为客户端,iSCSI traget 被视为服务器。
可以有多个目标可用并拥有存储。
存储被划分为多个 LUN(逻辑单元号)并映射到 iSCSI 目标,然后由客户端使用 iSCSI 启动器使用。
配置 iSCSI 目标(服务器)
# yum install scsi-target-utils -y
启动iscsi相关服务
# service tgtd start # chkconfig tgtd on
创建LUN
让我们创建一个新的逻辑卷
我已将一个新硬盘添加到我的虚拟机,我将在其上创建一个新的逻辑卷。
# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1):1 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):[Press Enter] Using default value 1305 Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes/512 bytes I/O size (minimum/optimal): 512 bytes/512 bytes Disk identifier: 0x398d6cc3 Device Boot Start End Blocks Id System /dev/sdb1 1 1305 10482381 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
# partprobe /dev/sdb # pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created # vgcreate VolGroup1 /dev/sdb1 Volume group "VolGroup1" successfully created # lvcreate -L 5G VolGroup1 -n work Logical volume "work" created
所以在这里我创建了一个新的逻辑卷, 名称为work。
所以接下来是将此路径作为 LUN 添加到我的 iSCSI 目标
# vi /etc/tgt/targets.conf ## 搜索“default-driver iscsi”并在下面添加一行,如下所示 <target iqn.2014-09.com.example:target1> backing-store /dev/VolGroup1/work </target>
这里 backing-store <path> 定义了目标导出的逻辑单元 (LUN)。
这可以指定常规文件或者块设备。
# /etc/init.d/tgtd restart Stopping SCSI target daemon: [ OK ] Starting SCSI target daemon: [ OK ]
查看配置 iSCSI 目标和 LUN
# tgtadm --mode target --op show Target 1: iqn.2014-09.com.example:target1 System information: Driver: iscsi State: ready I_T nexus information: LUN information: LUN: 0 Type: controller SCSI ID: IET 00010000 SCSI SN: beaf10 Size: 0 MB, Block size: 1 Online: Yes Removable media: No Prevent removal: No Readonly: No Backing store type: null Backing store path: None Backing store flags: LUN: 1 Type: disk SCSI ID: IET 00010001 SCSI SN: beaf11 Size: 5369 MB, Block size: 512 Online: Yes Removable media: No Prevent removal: No Readonly: No Backing store type: rdwr Backing store path: /dev/VolGroup1/work Backing store flags: Account information: ACL information: ALL
如我们所见,当我们只创建一个时,可以看到两个 LUN。
如果我们看得很清楚,LUN 0 是一个控制器 LUN,它充当控制器的接口。
LUN 1 是我们刚刚创建的带有 LVM 的磁盘类型。
服务器上的 iptables 规则
# iptables -I INPUT -m state --state NEW -p tcp --dport 3260 -j ACCEPT # service iptables save
在客户端
# yum -y install iscsi-initiator-utils
从服务器发现 iSCSI 目标
# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.11 --discover Starting iscsid: [ OK ] 192.168.1.11:3260,1 iqn.2014-09.com.example:target1
现在让我们确认我们新发现的目标的状态
# iscsiadm --mode node --op show | less # BEGIN RECORD 6.2.0-873.10.el6 node.name = iqn.2014-09.com.example:target1 node.tpgt = 1 node.startup = automatic node.leading_login = No iface.hwaddress = iface.ipaddress = iface.iscsi_ifacename = default iface.net_ifacename = iface.transport_name = tcp iface.initiatorname = iface.bootproto = iface.subnet_mask = iface.gateway = iface.ipv6_autocfg = iface.linklocal_autocfg = iface.router_autocfg = iface.ipv6_linklocal = iface.ipv6_router = iface.state = iface.vlan_id = 0 iface.vlan_priority = 0 iface.vlan_state = iface.iface_num = 0 iface.mtu = 0 iface.port = 0 node.discovery_address = 192.168.1.11 node.discovery_port = 3260 node.discovery_type = send_targets node.session.initial_cmdsn = 0 node.session.initial_login_retry_max = 8 node.session.xmit_thread_priority = -20 node.session.cmds_max = 128 node.session.queue_depth = 32 node.session.nr_sessions = 1 node.session.auth.authmethod = None node.session.auth.username = node.session.auth.password = node.session.auth.username_in = node.session.auth.password_in = node.session.timeo.replacement_timeout = 120 node.session.err_timeo.abort_timeout = 15 node.session.err_timeo.lu_reset_timeout = 30 node.session.err_timeo.tgt_reset_timeout = 30 node.session.err_timeo.host_reset_timeout = 60 node.session.iscsi.FastAbort = Yes node.session.iscsi.InitialR2T = No node.session.iscsi.ImmediateData = Yes node.session.iscsi.FirstBurstLength = 262144 node.session.iscsi.MaxBurstLength = 16776192 node.session.iscsi.DefaultTime2Retain = 0 node.session.iscsi.DefaultTime2Wait = 2 node.session.iscsi.MaxConnections = 1 node.session.iscsi.MaxOutstandingR2T = 1 node.session.iscsi.ERL = 0 node.conn[0].address = 192.168.1.11 node.conn[0].port = 3260 node.conn[0].startup = bananaal node.conn[0].tcp.window_size = 524288 node.conn[0].tcp.type_of_service = 0 node.conn[0].timeo.logout_timeout = 15 node.conn[0].timeo.login_timeout = 15 node.conn[0].timeo.auth_timeout = 45 node.conn[0].timeo.noop_out_interval = 5 node.conn[0].timeo.noop_out_timeout = 5 node.conn[0].iscsi.MaxXmitDataSegmentLength = 0 node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144 node.conn[0].iscsi.HeaderDigest = None node.conn[0].iscsi.IFMarker = No node.conn[0].iscsi.OFMarker = No # END RECORD
在我们最后的步骤中,我们刚刚发现了新的目标,但它们仍然没有添加到我们的服务器,所以让我们继续在本地添加它们。
但在此之前,让我们检查系统上可用的块设备,以便检查差异
# ls -l /dev/| grep sd brw-rw---- 1 root disk 8, 0 Aug 25 16:21 sda brw-rw---- 1 root disk 8, 1 Aug 25 16:21 sda1 brw-rw---- 1 root disk 8, 2 Aug 25 16:21 sda2
# iscsiadm --mode node --targetname iqn.2014-09.com.example:target1 --portal 192.168.1.11 --login Logging in to [iface: default, target: iqn.2014-09.com.example:target1, portal: 192.168.1.11,3260] (multiple) Login to [iface: default, target: iqn.2014-09.com.example:target1, portal: 192.168.1.11,3260] successful.
如我们所见,我们已成功登录,因为我们没有配置任何类型的 CHAP 身份验证,因此它没有提示任何用户身份验证详细信息。
接下来让我们重新检查连接到系统的块设备列表
# ls -l /dev/| grep sd brw-rw---- 1 root disk 8, 0 Aug 25 16:21 sda brw-rw---- 1 root disk 8, 1 Aug 25 16:21 sda1 brw-rw---- 1 root disk 8, 2 Aug 25 16:21 sda2 brw-rw---- 1 root disk 8, 16 Aug 25 18:34 sdb
如我们所见,系统中添加了一个新的块设备 sdb。
确保将 iSCSI 服务设置为在重新启动时启动
# chkconfig --list iscsi iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off