Storage
企业存储往集中式管理必定是未来的方向,这可以很好的规避单机故障而导致数据丢失或出错。虽然到目前为止,iscsi存储应该在什么环境下使用,但是iscsi前途应该是光明的,他为中小企业以低廉的构建成本构建出优秀存储性能的存储提供了可行的解决方案。
在存储的世界中,有这各色各样的名词和术语,常见的SCSI,FC,NAS,DAS,SAN等。
- SCSI
SCSI是小型计算机系统接口(Small Computer System Interface)的简称,SCSI作为输入输出接口,主要用于硬盘、光盘、磁带机、扫描仪等设备 - FC
FC是光纤通道(Fibre Channel)的简称,是一种适合于千兆数据传输的、成熟而安全的解决方案。与传统的SCSI技术相比,FC提供更高的数据传输速率,更远的传输距离,更多的设备连接支持,更稳定的性能,更简易的安装。 - NAS
网络接入存储(Network-Attached Storage), 它通过网络连接存储系统,建立专门的数据存储的私有网络,用户通过TCP/IP协议访问数据,业界常见的共享协议有NFS,CIFS来实现文件级别数据共享。但是NAS也有一定的局限性,它会受到网络带宽和网络拥堵的影响,在一定程度上限制了NAS的网络传输能力 - DAS
直连式存储(Direct-Attached Storage),是指将存储设备通过SCSI接口或光纤通道直接连接到一台计算机上。当服务器在地理上比较分散,很难通过远程进行互连时,DAS是比较好的解决方案。但是这种式存储只能通过与之连接的主机进行访问,不能实现数据与其他主机的共享,同时,DAS会占用服务器操作系统资源,例如CPU资源、IO资源等,并且数据量越大,占用操作系统资源就越严重。 - SAN
存储区域网络(Storage Area Network),SAN由3个部分组成,分别是连接设备(如路由器、光纤交换机和Hub)、接口(如SCSI、FC)、通信协议(如IP和SCSI)。这3个部分再加上存储设备和服务器就构成了一个SAN系统。SAN捉供了一个灵活的、高性能的和高扩展性的存储网络环境,它可以更加有效地传输海量的数据块。由于采用了光纤接口,因此SAN还具有更高的带宽,同时,SAN也使统一管理和集中控制实现简化。
ISCSI
iSCSI,即Internet SCSI,是IETF制订的一项标准,用于将SCSI数据块映射为以太网数据包。从根本上说,它是一种基于IP Storage理论的新型存储技术,该技术将存储行业广泛应用的SCSI接口技术与IP网络技术相结合,可以在IP网络上构建SAN。简单地说,iSCSI就是在IP网络上运行SCSI协议的一种网络存储技术。
iSCSI的优势主要表现为:首先,iSCSI沿用TCP/IP协议,而TCP/IP是在网络方面最通用、最成熟的协议,且IP网络的基础建设非常完善,同时,SCSI技术是被磁盘和磁带等设备广泛采用的存储标准,这两点使iSCSI的建设费用和维护成本非常低廉;其次,iSCSI支持一般的以太网交换机而不是特殊的光纤通道交换机,从而减少了异构网络带来的麻烦;还有,iSCSI是通过IP封包传输存储命令,因此可以在整个Internet上传输数据,没有距离的限制。
在iSCSI技术出现后,通过IP技术搭建的存储网络也应运而生,SAN技术也就出现了两种不同的实现方式,即FC SAN与IP SAN。简单来说,以光纤搭建的存储网络就是FC SAN.以iSCSI技术搭建的存储网络叫做IP SAN。
IP SAN
Linux提供了一整套的ISCSI的解决方法,下面我们来尝试构建一个IP SAN。
iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。

- Target Server
1.准备磁盘设备
2、安装程序包、启动服务
3、创建target
4、创建lun
5、授权
1 | ~]# yum install -y scsi-target-utils |
2 | ~}# systemctl start tgtd |
3 | ~]# tgtadm --lld iscsi --mode target --op show |
4 | ~]# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2017-05.com.jusene:t1 |
5 | ~]# tgtadm --lld iscsi --mode target --op show |
6 | Target 1: iqn.2017-05.com.jusene:t1 |
7 | System information: |
8 | Driver: iscsi |
9 | State: ready |
10 | I_T nexus information: |
11 | LUN information: |
12 | LUN: 0 |
13 | Type: controller |
14 | SCSI ID: IET 00010000 |
15 | SCSI SN: beaf10 |
16 | Size: 0 MB, Block size: 1 |
17 | Online: Yes |
18 | Removable media: No |
19 | Prevent removal: No |
20 | Readonly: No |
21 | SWP: No |
22 | Thin-provisioning: No |
23 | Backing store type: null |
24 | Backing store path: None |
25 | Backing store flags: |
26 | Account information: |
27 | ACL information: |
28 | ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb |
29 | ~]# tgtadm --lld iscsi --mode target --op show |
30 | Target 1: iqn.2017-05.com.jusene:t1 |
31 | System information: |
32 | Driver: iscsi |
33 | State: ready |
34 | I_T nexus information: |
35 | LUN information: |
36 | LUN: 0 |
37 | Type: controller |
38 | SCSI ID: IET 00010000 |
39 | SCSI SN: beaf10 |
40 | Size: 0 MB, Block size: 1 |
41 | Online: Yes |
42 | Removable media: No |
43 | Prevent removal: No |
44 | Readonly: No |
45 | SWP: No |
46 | Thin-provisioning: No |
47 | Backing store type: null |
48 | Backing store path: None |
49 | Backing store flags: |
50 | LUN: 1 |
51 | Type: disk |
52 | SCSI ID: IET 00010001 |
53 | SCSI SN: beaf11 |
54 | Size: 21475 MB, Block size: 512 |
55 | Online: Yes |
56 | Removable media: No |
57 | Prevent removal: No |
58 | Readonly: No |
59 | SWP: No |
60 | Thin-provisioning: No |
61 | Backing store type: rdwr |
62 | Backing store path: /dev/sdb |
63 | Backing store flags: |
64 | Account information: |
65 | ACL information: |
66 | ~]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 10.211.55.0/24 |
67 | ~]# tgtadm --lld iscsi --mode target --op show |
68 | Target 1: iqn.2017-05.com.jusene:t1 |
69 | System information: |
70 | Driver: iscsi |
71 | State: ready |
72 | I_T nexus information: |
73 | LUN information: |
74 | LUN: 0 |
75 | Type: controller |
76 | SCSI ID: IET 00010000 |
77 | SCSI SN: beaf10 |
78 | Size: 0 MB, Block size: 1 |
79 | Online: Yes |
80 | Removable media: No |
81 | Prevent removal: No |
82 | Readonly: No |
83 | SWP: No |
84 | ▽ Thin-provisioning: No |
85 | Backing store type: null |
86 | Backing store path: None |
87 | Backing store flags: |
88 | LUN: 1 |
89 | Type: disk |
90 | SCSI ID: IET 00010001 |
91 | SCSI SN: beaf11 |
92 | Size: 21475 MB, Block size: 512 |
93 | Online: Yes |
94 | Removable media: No |
95 | Prevent removal: No |
96 | Readonly: No |
97 | SWP: No |
98 | Thin-provisioning: No |
99 | Backing store type: rdwr |
100 | Backing store path: /dev/sdb |
101 | Backing store flags: |
102 | Account information: |
103 | ACL information: |
104 | 10.211.55.0/24 |
这样一个target server就已经部署好了,接下来我们需要使用initiator来使用target。
- Initiator
1.安装程序包,配置initiator的名字,并启动服务
2.使用iscsiadm实现target的发现和注册
1 | ~]# yum install -y iscsi-initiator-utils |
2 | ~]# vim /etc/iscsi/initiatorname.iscsi |
3 | InitiatorName=iqn.2017-05.com.jusene:6ea0c4f895 |
4 | ~]# for i in iscsi iscsid;do systemctl start $i ;done |
5 | ~]# iscsiadm -m discovery -t st -p 10.211.55.39:3260 |
6 | 10.211.55.39:3260,1 iqn.2017-05.com.jusene:t1 |
7 | ~]# ls /var/lib/iscsi/send_targets/10.211.55.39,3260/ |
8 | iqn.2017-05.com.jusene:t1,10.211.55.39,3260,1,default/ st_config |
9 | ~]# iscsiadm -m node -T iqn.2017-05.com.jusene:t1 -p 10.211.55.39:3260 -l |
10 | Logging in to [iface: default, target: iqn.2017-05.com.jusene:t1, portal: 10.211.55.39,3260] (multiple) |
11 | Login to [iface: default, target: iqn.2017-05.com.jusene:t1, portal: 10.211.55.39,3260] successful. |
12 | ~]# fdisk /dev/sdb |
13 | Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors |
14 | Units = sectors of 1 * 512 = 512 bytes |
15 | Sector size (logical/physical): 512 bytes / 512 bytes |
16 | I/O size (minimum/optimal): 512 bytes / 512 bytes |
我们可以看到在initiator上看见了在target上设备,虽然initiator可以持久保持这个连接,但是target是通过tgtadm来配置的,它并不持久,我们需要通过写配置文件来实现target server。
先删除initialtor上的相关配置:
1 | ~]# iscsiadm -m node -T iqn.2017-05.com.jusene:t1 -p 10.211.55.39:3260 -u |
2 | Logging out of session [sid: 2, target: iqn.2017-05.com.jusene:t1, portal: 10.211.55.39,3260] |
3 | Logout of [sid: 2, target: iqn.2017-05.com.jusene:t1, portal: 10.211.55.39,3260] successful. |
4 | ~]# iscsiadm -m node -T iqn.2017-05.com.jusene:t1 -p 10.211.55.39:3260 -o delete |
5 | ~]# ls /var/lib/iscsi/send_targets/10.211.55.39,3260/ |
6 | st_config |
- Target Server
1~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 12~]# tgtadm -L iscsi -m target -o delete -t 13~]# tgtadm -L iscsi -m target -o show4~]# cd /etc/tgt/5~]# vim targets.conf6<target iqn.2017-05.com.jusene:t2>7backing-store /dev/sdb8initiator-address 10.211.55.0/249</target>10~]# systemctl restart tgtd11~]# tgtadm -L iscsi -m target -o show12Target 1: iqn.2017-05.com.jusene:t213System information:14Driver: iscsi15State: ready16I_T nexus information:17LUN information:18LUN: 019Type: controller20SCSI ID: IET 0001000021SCSI SN: beaf1022Size: 0 MB, Block size: 123Online: Yes24Removable media: No25Prevent removal: No26Readonly: No27SWP: No28Thin-provisioning: No29Backing store type: null30Backing store path: None31Backing store flags:32LUN: 133Type: disk34SCSI ID: IET 0001000135SCSI SN: beaf1136Size: 21475 MB, Block size: 51237Online: Yes38Removable media: No39Prevent removal: No40Readonly: No41SWP: No42Thin-provisioning: No43Backing store type: rdwr44Backing store path: /dev/sdb45Backing store flags:46Account information:47ACL information:4810.211.55.0/24
上面我们做了基于ip的访问认证,接下来我们做下基于用户的认证:
Target Server
1~]# vim /etc/tgt/targets.conf2<target iqn.2017-05.com.jusene:t2>3backing-store /dev/sdb4backing-store /dev/sdc5initiator-address 10.211.55.0/246incominguser jusene jusene7</target>8~]# tgtadm -L iscsi -m target -o show9Target 1: iqn.2017-05.com.jusene:t210System information:11Driver: iscsi12State: ready13I_T nexus information:14LUN information:15LUN: 016Type: controller17SCSI ID: IET 0001000018SCSI SN: beaf1019Size: 0 MB, Block size: 120Online: Yes21Removable media: No22Prevent removal: No23Readonly: No24SWP: No25Thin-provisioning: No26Backing store type: null27Backing store path: None28Backing store flags:29LUN: 130Type: disk31SCSI ID: IET 0001000132SCSI SN: beaf1133Size: 21475 MB, Block size: 51234Online: Yes35Removable media: No36Prevent removal: No37Readonly: No38SWP: No39Thin-provisioning: No40Backing store type: rdwr41Backing store path: /dev/sdb42Backing store flags:43Account information:44jusene45ACL information:4610.211.55.0/24initatior
1~]# vim /etc/iscsi/iscsi.conf2node.session.auth.username = jusene3node.session.auth.password = jusene45discovery.sendtargets.auth.username = jusene6discovery.sendtargets.auth.password = jusene