Linux 配置iSCSI服务器
2013-04-12 by dongnan
开始之前
最近在做 iscsi 性能评估,为以后VMware ESXi集群等高级功能做准备,使用过 openfiler 不过测试时 openfiler
自带的iscsi target软件性能似乎有问题,所以有了本文的主角TGT,RHLE/CentOS 自带,使用Yum安装即可。
操作步骤
检查系统是否安装 scsi-target软件:
rpm -qa | grep scsi 
scsi-target-utils-1.0.14-4.el6.x86_64
配置文档与管理程序
/etc/tgt/targets.conf   # 主配置文档,设置要分享的磁盘 
/usr/sbin/tgt-admin     # 线上查询、删除target 等功能的管理工具; 
/usr/sbin/tgt-setup-lun # 建立target 以及设置分享的磁盘与可使用的用户端等工具软体。 
/usr/sbin/tgtadm        # 手动直接管理的管理员工具(可使用配置文档取代); 
/usr/sbin/tgtd          # 主要提供iSCSI target 服务的主程式; 
/usr/sbin/tgtimg        # 建置预计分享的映像档装置的工具(以映像档模拟磁盘)
准备共享磁盘
本次将使用一个LVM 物理卷,名称为iscsi,路径为/dev/VolGroup/iscsi:
lvscan | tail -n1
  ACTIVE            '/dev/VolGroup/iscsi' [200.00 GiB] inherit
配置文档
语法如下:
<target iqn.相关装置的target名称> 
    backing-store /你的/虚拟装置/完整名称-1  <==LUN 1 
    backing-store /你的/虚拟装置/完整名称-2  <==LUN 2 
    lun N <==LUN 10 自定义lun
</target>
iqn名称规范 
iqn.yyyy-mm.<reversed domain name>:identifier 
iqn.年年-月.单位网域名的反转写法:这个分享的target名称
配置target.conf:
# 编辑配置文件
vim /etc/tgt/targets.conf
# 添加如下配置项目
<target iqn.2012-04.com.test:server.target1> 
    backing-store /dev/VolGroup/iscsi
    lun 10
</target>
启动并检查:
/etc/init.d/tgtd start
tgt-admin --show 
Target 1: iqn.2012-04.com.test:server.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 
            Online: Yes 
            Removable media: No 
            Backing store type: rdwr 
            Backing store path: None 
        LUN: 10
            Type: disk 
            SCSI ID: IET     00010001 
            SCSI SN: beaf11 
            Size: 214748 MB 
            Online: Yes 
            Removable media: No 
            Backing store type: rdwr 
            Backing store path: /dev/VolGroup/iscsi 
    Account information: 
    ACL information: 
        ALL
tgtd 进程使用 tcp 3260 端口:
# lsof -i :3260 
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME 
tgtd    2856 root    5u  IPv4  19726      0t0  TCP *:iscsi-target (LISTEN) 
tgtd    2856 root    6u  IPv6  19727      0t0  TCP *:iscsi-target (LISTEN) 
tgtd    2857 root    5u  IPv4  19726      0t0  TCP *:iscsi-target (LISTEN) 
tgtd    2857 root    6u  IPv6  19727      0t0  TCP *:iscsi-target (LISTEN)
验证
为 ESXi服务器,配置iSCSI存储设备:
配置 -> iSCSI Software Adapter -> 属性:

可以在静态发现或者动态发现添加iscsi targetIP地址:

配置 -> 存储器 -> 添加存储器 -> 磁盘/lun -> 下一步 -> 下一步:
