zoukankan      html  css  js  c++  java
  • 转:Linux下应用tgtadm构建iSCSI Target(SAN)

    Linux target framework(tgt)是为创建、维护SCSI target 驱动(包括iSCSI、FC、SRP等)提供支持。它的关键目标是简洁地集成到scsi-mid层,并且实现大部分应用层空间的tgt(The key goals are the clean integration into the scsi-mid layer and implementing a great portion of tgt in user space)。

    IET(iSCSI Enterprise Target )的开发者帮助开发了Linux SCSI target framework(stgt),

    The developer of IET is also helping to develop Linux SCSI target framework (stgt) which looks like it might lead to an iSCSI target implementation with an upstream kernel component.

    iSCSI Target可以用来:

    a]用来安装stateless server/client (用于无盘安装)

    b]通过局域网、无线网络或者因特网共享磁盘或者磁带设备

    c]安装SAN——存储阵列

    d]通过Linux下的分布式文件系统实现负载均衡的web服务器集群

    在这个教程中,将要学到如何通过tgt框架构建一个全功能的Linux iSCSI SAN。

     

    iSCSI target(server)

    存储资源所在的iSCSI服务器被称为“target”。iSCSI target通常是一个硬盘存储设备。当前大部分的主流操作系统都提供了配合iSCSI target使用的客户端软件initiator。

     

    iSCSI initiator(client)

    initiator就是iSCSI传输的服务端。典型的initiator都有共同的目的,就是作为一个SCSI总线的适配器,代替物理上的SCSI设备(类似硬盘或者磁带)。iSCSI initiator通过IP网络传输SCSI命令。

     

    CentOS / RHEL / fedora 安装tgt

    $yum install scsi-target-utils

     

    Debian / Ubuntu Linux 安装tgt

    $ sudo apt-get install tgt


    tgtadm——Linux SCSI Target管理工具

    tgtadm是用来监控、修改Linux SCSI target 的工具,包括target设置、卷设置,等等。这个工具允许提供为装有SCSI initiator的其它操作系统提供块级(block-level)的SCSI存储。这个功能最初被部署为Linux iSCSI target,通过网络向装有iSCSI initiator的系统提供存储服务。


    启动tgtd

    启动tgtd程序,可以输入:

    $/usr/sbin/tgtd

    RHEL / CentOS 系统下可以启动tgtd的服务程序,输入:

    $/etc/init.d/tgtd start


    定义iSCSI target名

    以下的例子中,创建了一个id为1的target,它的iqn为:iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz,并且添加了一个lun( logical unit)号为1的逻辑单元(由/dev/hdc1提供)

    $ tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz

    iqn号是局域网内iSCSI target的唯一标识,用来区分不同的target,所以在一个网络内,iqn号一定不能相同

    要显示当前的iqn号,输入:

    $ tgtadm --lld iscsi --op show --mode target

    通常输出如下:

    Target 1: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz
        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
                Online: Yes
                Removable media: No
                Backing store type: rdwr
                Backing store path: None
        Account information:
        ACL information:

     

    为target增加一个lun(/dev/sdb1)

    tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1


    对于家用电脑或测试系统的注意事项:

    大部分产品只是通过真正的iSCSI设备使用iSCSI root。但是对于测试目的,这将很有变得很有用,比如在你的图片服务器上安装一个iSCSI target。这样,简单的使用文件系系统,在家中就可以测试、学习iSCSI target、initiator。使用dd 命令创建一个磁盘文件系统:

    # dd if=/dev/zero of=/fs.iscsi.disk bs=1M count=512

    创建了一个512M大小的文件/fs.iscsi.disk

     

    把/fs.iscsi.disk当做一个lun加入到target中:

    # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /fs.iscsi.disk

     

    再查看lun信息:

    # tgtadm --lld iscsi --op show --mode target

     

    可以看到如下结果:

    Target 1: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz
        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
                Online: Yes
                Removable media: No
                Backing store type: rdwr
                Backing store path: None
            LUN: 1
                Type: disk
                SCSI ID: IET     00010001
                SCSI SN: beaf11
                Size: 537 MB
                Online: Yes
                Removable media: No
                Backing store type: rdwr
                Backing store path: /fs.iscsi.disk
        Account information:
        ACL information:

     

    接受iSCSI initiator的访问:

    要使target接受initiator的访问,需要输入:

    # tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL

    这样将打开了3260端口

    #netstat -tulpn | grep 3260

     

    结果如下:

    t c p        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN      27328/tgtd
    tcp6 0 0 :::3260 :::* LISTEN 27328/tgtd

    当你做完这些操作,你的系统就被设置成一个iSCSI Target了。远程的客户端计算机就可以通过网络访问这台计算机上的硬盘了。你可以使用分布式的集群文件系统来安装真正的共享存储。如果需要的话,打开防火墙上的3260端口。

  • 相关阅读:
    052-34
    052-33
    052-32
    052-31
    052-30
    052-28
    react组件之间通信
    排序算法
    点外卖
    js的各种排序算法
  • 原文地址:https://www.cnblogs.com/jjkv3/p/2773102.html
Copyright © 2011-2022 走看看