4.6.1 ISCSI网络存储

 

目前计算机领域的存储解决方案主要有直连存储(DAS)、存储区域网络(SAN)、以及网络附加存储(NAS)三种。

DASDirect-Attached Storage)指的是主机总线直接通过SCSI接口与存储设备相连,这种连接方式主要应用在家庭个人电脑环境中。

SANStorage Area Network)指的是一整套存储网络的解决方案,SAN采用的是光纤通道技术,SAN就是通过光纤交换机将服务器与存储设备连接在一起的网络整体环境,SAN的优势在于其先进的光纤通信技术,为当今爆炸式的数据增长环境提供了快速高效的存储方案。

NASNetwork-Attached Storage)可以使用普通的网络环境,通过以太网交换机等设备连接服务器与存储设备,NAS的优势在于无需对网络环境进行改造,NAS可以使用现有的网络环境,而且不同厂家的设备只要使用TCP/IP协议,就可以满足设备之间对兼容性的要求,NFSCIFS就属于网络附加存储的解决方案,它们都提供了对文件系统的共享。

由于传统的SAN需要价格昂贵的光纤设备作为基础,所以现在又有了基于IP技术的SAN,可以通过IP网络进行数据存储,服务器在不进行任何改造的情况下使用现有的以太网卡就可以访问IP SANISCSI就是这样的技术)。

NASSAN的主要区别在于,NAS共享的是文件系统,SAN共享的是块设备。

本节重点关注ISCSI网络存储与数据同步rsync系统。

 

4.6.1 ISCSI网络存储

ISCSIInternet Small Computer System Interface)是典型的IP-SAN技术,是基于因特网的SAN存储技术,该技术使得我们可以在基于IP协议的网络上传输SCSI命令,在ISCSI环境中,客户端(initiators)发送SCSI命令给远程的SCSI存储设备(targets),实现数据的存储与备份功能。ISCSI使用TCP8603260端口进行通信。

ISCSISCSI最大的区别在于ISCSI摆脱了存储设备的距离限制,使得任何主机都可以通过局域网或广域网访问我们的存储设备,而对于数据中心而言,这是至关重要的。

下面我们将在Centos 6.3中部署一个ISCSI服务器以及客户端访问的环境。

1. 部署ISCSI服务

Centos 6.3平台上部署ISCSI服务需要安装target软件,安装完成后,可以通过命令或修改配置文件这两种方式部署ISCSI服务。

如果需要使用命令配置服务,可以参考tgtadm命令的man手册,其中有详细的示例。以下操作将使用修改配置文件的方式来进行,先弄清楚两个概念:LUNIQN

LUNLogic Unit Number)是设备的逻辑单元号,一般为一个数字,我们使用LUN来标识存储设备。

IQNISCSI Qualified Name)为ISCSI合格名称,一般格式为iqn.yyyy-mm<reversed domain name>:identifier,其中,yyyy代表年,mm代表月,reversed domain name是域名的反写,identifier为标识名称。

部署ISCSI服务器时,首先需要安装scsi-target-utils软件。默认的服务器配置文件为/etc/tgt/targets.conf,我们需要在配置文件添加共享设备,为共享设备创建LUNIQN

[root@instructor ~]# yum -y install scsi-target-utils
[root@instructor ~]# vim /etc/tgt/targets.conf 
<target iqn.2014.08.com.example.instructor:disk1>   
  backing-store /dev/sdb3    
 backing-store /dev/sdb5 
</target>  
<target iqn.2014-08.com.example.instructor:disk2>   
  backing-store /dev/sdc3    
 lun 10    
 vendor_id jacob Inc.   
  incominguser tom tompass12 
</target> 
<target iqn.2014.08.com.example.instructor:disk3>    
 backing-store /dev/sdd3   
  lun 20    
 initiator-address 192.168.0.102   
  incominguser tom tompass12 
</target>    
[root@instructor ~]# service tgtd restart && chkconfig tgtd on

 

/etc/tgt/targets.conf配置文件说明如下。

第一个target定义了两个LUNLUN编号会自动按顺序分配给LUN1LUN2LUN0一般会分配给SCSI控制器。默认允许所有人访问该target/dev/sdb3/dev/sdb5是准备共享的设备,通过backing-store指定设备路径,backing-store支持文件或块设备。此外,也可以使用direct-store指定设备路径,但direct-store仅支持本地SCSI设备。

第二个target定义了一个LUNLUN编号为手动配置的10,共享设备是/dev/sdc3,手动修改设备的厂家信息为jacob Inc.。此外,通过 incominguser选项将该target设置为仅允许tom账户访问,密码为tompass12

第三个target定义了一个LUNLUN编号为20,共享设备为/dev/sdd3,仅允许tom账户通过192.168.0.102主机访问该target

backing-store 后备存储,一般指非实际的物理盘、如lv卷、某个分区、文件组成的块设备
direct_store 直接存储,与backing-store相对,指实际的物理磁盘,如整个硬盘
initiator-address 使用chap认证协议,由target来认证initiator端,格式为"incominguser username userpassword"
outgingUsername 使用chap认证协议,由initiator来认证target端,格式为"outgoingusername username userpassword",较少使用

当服务器端启动tgtd服务后,随时可以通过tgtadm命令来查看ISCSI的详细信息。以下tgtadm的输出内容为精简后的部分输出结果。

[root@instructor ~]# tgtadm --lld iscsi --op show --mode target( tgt-admin -s)
Target 1: iqn.2014-08.com.example.instructor:disk2
    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: 10
            Type: disk
            SCSI ID: IET     0001000a
            SCSI SN: beaf110
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc3
            Backing store flags: 
    Account information:
        tom
    ACL information:
        ALL
Target 2: iqn.2014.08.com.example.instructor:disk1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 1
            Type: disk
            SCSI ID: IET     00020001
            SCSI SN: beaf21
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb3
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00020002
            SCSI SN: beaf22
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb5
            Backing store flags: 
    Account information:
    ACL information:
        ALL
Target 3: iqn.2014.08.com.example.instructor:disk3
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 20
            Type: disk
            SCSI ID: IET     00030014
            SCSI SN: beaf320
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdd3
            Backing store flags: 
    Account information:
        tom
    ACL information:
        192.168.0.102

 

2. 客户端访问

Linux客户端访问ISCSI服务器需要安装iscsi-initiator-utils软件包。第一部,通过iscsiadm命令的discovery选项可以发现服务器端ISCSIIQN。第二步,通过login选项加载服务器的IQN

[root@desktop24 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.254
Starting iscsid:                                           [  OK  ]
192.168.0.254:3260,1 iqn.2014-08.com.example.instructor:disk2
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk1
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk3
[root@desktop24 ~]# iscsiadm -m node -T iqn.2014.08.com.example.instructor:disk1 -p 192.168.0.254 -l

 

如果想开机自动挂载此硬盘的话需要,注意这里不是default,而是_netdev

[root@desktop24 ~]# echo '/dev/sdc1 /iscsi_ceshi ext4 _netdev 0 0' >> /etc/fstab

 

查看当前链接状态

[root@desktop24 ~]# iscsiadm -m node -S
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk3
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk1
192.168.0.254:3260,1 iqn.2014-08.com.example.instructor:disk2

卸载

[root@desktop24 ~]# umount /iscsi_ceshi/
[root@desktop24 ~]# iscsiadm -m node -T  iqn.2014.08.com.example.instructor:disk1 -u
Logging out of session [sid: 2, target: iqn.2014.08.com.example.instructor:disk1, portal: 192.168.0.254,3260]
Logout of [sid: 2, target: iqn.2014.08.com.example.instructor:disk1, portal: 192.168.0.254,3260] successful.

缓存信息还在系统中,下次启动将自动链接

[root@desktop24 ~]# ls /var/lib/iscsi/nodes
iqn.2014.08.com.example.instructor:disk1
iqn.2014-08.com.example.instructor:disk2
iqn.2014.08.com.example.instructor:disk3

删除缓存信息

[root@desktop24 ~]# iscsiadm -m node -T iqn.2014.08.com.example.instructor:disk
{1,2,3} -o delete

 

客户端对分区进行加密的配置

[root@desktop24 ~]# vim /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP 
node.session.auth.username = tom 
node.session.auth.password = tompass12 
discovery.sendtargets.auth.authmethod = CHAP 
discovery.sendtargets.auth.username = tom 
discovery.sendtargets.auth.password = tompass12    
 
[root@desktop24 ~]# iscsiadm -m discovery -t st -p 192.168.0.254
[root@desktop24 ~]# service iscsi restart
[root@desktop24 ~]# ls /dev/sd*(全部已自动登录)
/dev/sdc   /dev/sdd   /dev/sde  /dev/sdf

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章