RH436-3 ISCSI Configuration

简介:

  ISCSI Configuration

 
一、概述
1.   Redhat iscsi driver

  1.1  作用:提供主机通过ip传输存储的能力

  1.2 iscsi和FC比较
 

 
2.   iscsi数据访问过程
 2.1 客户端发送scsi命令到远程存储设备(服务端target)
 2.2 默认使用tcp/ip协议端口tcp:3260
 2.3 客户端(initiator)
   2.3.1 通过discovery process方式访问请求到远程存储(指定存储IP)
   2.3.2 必需按照提供iscsi取得的协议
   2.3.3 iscsi服务保证target设备的持续性(iscsi每次启动时都生效)
   2.3.4 软件包:iscsi-initiator-utils-*.rpm
 2.4 服务器端(target)
   2.4.1 允许一到多个block设备可不客户端(initiator)访问
   2.4.2 系统要求RHEL5.1以上版本
   2.4.3 软件包:scsi-target-utils-*.rpm
 
3.   iscsi驱动功能
 3.1 支持头部和数据的加密
 3.2 支持双向CHAP认证
 3.3 支持流量控制
 3.4 支持多路径
 3.5 支持动态target的发现
 3.6 支持target改变时异步同步
 3.7 及时数据支持
 3.8 动态驱动从配置
 3.9 系统重启或可自动挂载
 
 
4.   iscsi的设备名
 4.1.  Linux会自动给iscsi分配一个设备名
 4.2.  uuid和卷标的功能(这个不是很好的方法)
 4.3.  Udev;uuid和卷标时这个设备名有可能在下次重启计算机的时候变化,所以最好使用udev。
 
5.   iscsi的挂载
l  1. netfs服务解决了网络服务启动在iscsi服务之前,但iscsi在系统启动后也能正常工作的问题。因为netfs在iscsi之后启动,重新挂载网络的挂载服务。
l  2. 写入写入/etc/fstab中
eg:
[root@station9 ~]# vim /etc/fstab
/dev/VolGroup00/LogVol00  /                      ext3    defaults                     1 1
LABEL=/boot                            /boot               ext3    defaults                     1 2
tmpfs                                        /dev/shm         tmpfs   defaults                    0 0
devpts                                      /dev/pts            devpts  gid=5,mode=620   0 0
sysfs                                         /sys                     sysfs   defaults                      0 0
proc                                          /proc                   proc    defaults                    0 0
LABEL=SWAP-sda2                swap                    swap    defaults                   0 0
/dev/sdb1                              /data                     ext3    defaults,_netdev     0 0
#_netdev选型表示挂载网络设备,当有网络时会重新挂载该设备,保证当netfs服务未启动时也能挂载。
6.   iscsi target的命名
 6.1.   iscsi名称要求是完整标识IQN(iscsi qualified name)
 6.2.   在全局上要求唯一
 6.3 .  IQN格式:iqn.<data_code>.<reversed_domain>.<string>[:<substring>]
   6.3.1  要求类型iqn
   6.3.2  data code:yyyy-mm
   6.3.3  反转dns域名:sales.example.com的IQN应该是:com.example.sales
   6.3.4  自定义的唯一的磁盘名,建议通过":string"方式对分组
  eg:
 
iqn.2011-09.com.example.sales:sata.rack2.disk
 
二、iscsi target配置(服务器端)
1.   启动tgtd服务
[root@station9 ~]#tgtd start
 
[root@station9 ~]#chkconf tgtd on
 
#启动tgtd服务,在做下面的操作之前一定要启动tgtd服务,否则会因为连接不上报错 
 
2.   创建target
[root@station9 ~]#tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2011-09:disk1
 
#创建id号为1的target,并命名为iqn.2011-09:disk1
 
3.  给target分配设备
 
[root@station9 ~]#tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
 
#为id号为1的target分配设备/dv/sdb1(也可为文件),并为新设备分配lun(逻辑单元号)。
 
4.绑定可访问target的IP
[root@station9 ~]#tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.32.0/24
 
#设置ACL访问权限,允许192.168.32.0/24网段可访问此target;允许所有可用-I ALL
 
#为保证系统生效,必须将以上命令写入到开机脚本/etc/rc.d/rc.local中
 
5.  查询target信息
[root@station9 ~]# tgtadm --lld iscsi --mode target --op show
 
#查询target,也可用tgt-admin -s
 
Target 1: iqn.2011-9:diskpub1
 
    System information:
 
        Driver: iscsi
 
        State: ready
 
    I_T nexus information:
 
    LUN information:
 
        LUN: 0                 
 
#lun 0默认为控制器,分配lun时只能从1开始
 
            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: 5124 MB
 
            Online: Yes
 
            Removable media: No
 
            Backing store type: rdwr
 
            Backing store path: /dev/sdb1
 
    Account information:
 
    ACL information:
 
        192.168.32.0/24
 
三、    移除target
 
1.   取消iscsi initiator绑定
[root@station9 ~]#tgtadm --lld iscsi --mod target --op unbind --tid 1 --initiator-address 192.168.32.0/24 
 
2.   查询要移除设备的lun号
[root@station9 ~]# tgtadm --lld iscsi --mod target --op show
 
Target 1: iqn.2011-9:diskpub1
 
    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: 5124 MB
 
            Online: Yes
 
            Removable media: No
 
            Backing store type: rdwr
 
            Backing store path: /dev/sdb1
 
       #/dev/sdb1的lun号为1
 
3.   从target中移除设备
[root@station9 ~]#tgtadm --lld iscsi --mod logicalunit --op delete --tid 1 –lun 1
 
#移除lun号为1的设备/dev/sdb1
 
[root@station9 ~]# tgtadm --lld iscsi --mod target --op show
 
Target 1: iqn.2011-9:diskpub1
 
    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:
 
 #lun为1的/dev/sdb1设备已经移除
 
4.    移除target
[root@station9 ~]# tgtadm --lld iscsi --mod target --op delete --tid 1
 
#移除id号为1的target,即名称为iqn.2011-9:diskpub1设备被移除
 
四、    iscsi initiator配置(客户端)
全局配置文件:/etc/iscsi/iscsid.conf
 
1.   发现指定IP的target设备。
[root@station2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.32.39:3260
 
192.168.32.39:3260,1 iqn.2011-9:diskpub1
 
# -p : iSCSI target 的IP,iSCSI预设使用的port 是3260
 
2.   链接(挂载)发现的target
[root@station2 ~]#iscsiadm -m node -T iqn.2011-9:diskpub1 -p 192.168.32.39:3260 -l
 
Logging in to [iface: default, target: iqn.2011-9:diskpub, portal: 192.168.32.39,3260]
 
Login to [iface: default, target: iqn.2011-9:diskpub, portal: 192.168.32.39,3260]: successful。
 
#-T : 指定target_iqn_name
 
-l: login,保证系统重启后,iscsi自动链接target设备并生效。 
 
3.   查询是否链接
[root@station2 ~]# fdisk -l
 
Disk /dev/vda: 42.9 GB, 42991616000 bytes
 
255 heads, 63 sectors/track, 5226 cylinders
 
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
/dev/vda1   *           1          13      104391   83  Linux
 
/dev/vda2              14        5226    41873422+  8e  Linux LVM
 
Disk /dev/sda: 5124 MB, 5124317184 bytes
 
158 heads, 62 sectors/track, 1021 cylinders
 
Units = cylinders of 9796 * 512 = 5015552 bytes
 
Disk /dev/sda doesn't contain a valid partition table
 
#以上显示/dev/sda设备为iscsi链接设备 
 
4.   Target端查询是否链接
[root@station9 ~]# tgtadm --lld iscsi --mode target --op show
 
Target 1: iqn.2011-9:diskpub1
 
    System information:
 
        Driver: iscsi
 
        State: ready
 
    I_T nexus information:
 
        I_T nexus: 1
 
            Initiator: iqn.1994-05.com.redhat:e3e44fad96d1
 
            Connection: 0
 
                IP Address: 192.168.32.32
 
#通过target端查看iSCSI Initiator:192.168.32.32已经连接
 
五、    注销或移除iscsi initiator设定
1.   临时注销
[root@station2 ~]# iscsiadm -m node -T iqn.2011-9:diskpub1 -p 192.168.32.39:3260 -u
 
Logging out of session [sid: 1, target: iqn.2011-9:diskpub1, portal: 192.168.32.39,3260]
 
Logout of [sid: 1, target: iqn.2011-9:diskpub1, portal: 192.168.32.39,3260]: successful
 
#-u: (logout) 临时注销,重新iscsi服务后链接又会生效,
 
[root@station2 ~]# fdisk -l
 
Disk /dev/vda: 42.9 GB, 42991616000 bytes
 
255 heads, 63 sectors/track, 5226 cylinders
 
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
/dev/vda1   *           1          13      104391   83  Linux
 
/dev/vda2              14        5226    41873422+  8e  Linux LVM
 
#显示/dev/sda设备删除了 
 
[root@station2 ~]# service iscsi restart
 
Stopping iSCSI daemon:
 
iscsid 已死,但 pid 文件仍存                               [确定]
 
Starting iSCSI daemon:                                     [确定]
 
                                                           [确定]
 
设置 iSCSI 目标:Logging in to [iface: default, target: iqn.2011-9:diskpub1, portal: 192.168.32.39,3260]
 
Login to [iface: default, target: iqn.2011-9:diskpub1, portal: 192.168.32.39,3260]: successful
 
                                                          [确定]
 
#以上显示target设备有重新链接了 
 
[root@station2 ~]# fdisk -l
 
Disk /dev/vda: 42.9 GB, 42991616000 bytes
 
255 heads, 63 sectors/track, 5226 cylinders
 
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
/dev/vda1   *           1          13      104391   83  Linux
 
/dev/vda2              14        5226    41873422+  8e  Linux LVM
 
Disk /dev/sda: 5124 MB, 5124317184 bytes
 
158 heads, 62 sectors/track, 1021 cylinders
 
Units = cylinders of 9796 * 512 = 5015552 bytes
 
Disk /dev/sda doesn't contain a valid partition table
 
#找到target设备/dev/sda 
 
2.   永久移除
[root@station2 ~]# iscsiadm -m node -T iqn.2011-9:diskpub1 -p 192.168.32.39:3260 -o delete
 
-o delete : 可以永久移除掉Target的连结,需重新启动iSCSI生效.
 
六、    iscsi chap身份验证
iscsi除了指定IP做ACL,还可以透过user/password (CHAP-Challenge Handshake Authentication Protocol(使用MD5的加密验证) )来做身分验证。
 
1.   iscsi CHAP验证种类
 1.1 单向CHAP验证:在此安全性等级,只有目标Target会做验证
 1.2 相互( Mutual ) CHAP验证:在此安全性等级,目标Target与启动器Initiator皆会被彼此做验证.
 1.3 Reverse CHAP验证:一般的CHAP使用one-way hash,密码档无法回朔,但是使用Reverse CHAP是可以的 
 
2.   iscsi单向CHAP验证
预设iSCSI 采用了单向CHAP(Challenge Handshake Authentication Protocol) 的身分验证方式,基本上是一种以MD5 的加密验证方式.方式如下:
 
 2.1. 在双方(Target/Initiator) 建立连线后,Target 送出"challenge" 的讯息告知Initiator 要做身分验证.
 2.2. Initiator 会将使用者密码(md5码加密)给Target 端.
 2.3. Target端将密码和Initiator发送的密码做比对,如果比对正确,这身份验证即成立,否则中断此次连结做.
 2.4. 在正常连线过程中会不时重复做1~3 的CHAP 身分验证.
 
3.   iscsi单向CHAP配置
3.1. target端配置
 3.1.1 创建target并为其分配设备
[root@station9 ~]# tgtadm --lld iscsi --mod target --op new --tid=1 -T iqn.2011-09.com.example.station9:disk1
 
[root@station9 ~]# tgtadm --lld iscsi --mod logicalunit --op new --tid 1 --lun 1 -b /dev/sdb1
 
[root@station9 ~]# tgtadm --lld iscsi --mod target --op bind --tid 1 -I ALL
 
l 3.1.2 创建CHAP验证帐号(与系统帐号无关)
[root@station9 ~]# tgtadm --lld iscsi --mode account --op new --user redhat --password redhat123
 
 #创建帐号redhat密码为redhat123,password 和username 的最大限制是256 字元
 
[root@station9 ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user redhat
 
 #将帐号redhat绑定到tid为1的target
 
[root@station9 ~]# tgtadm --lld iscsi --mode target --op show
 
Target 1: iqn.2011-09.com.example.station9:disk1
 
    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: 5124 MB
 
            Online: Yes
 
            Removable media: No
 
            Backing store type: rdwr
 
            Backing store path: /dev/sdb1
 
    Account information:
 
        redhat
 
    ACL information:
 
        ALL
 
3.2. initiator端配置
  3.2.1修改iscsi配置文件,添加CHAP验证帐号
[root@station2 ~]# vim /etc/iscsi/iscsid.conf
 
node.session.timeo.replacement_timeout = 20   #默认延迟时间120太长,
 
node.session.auth.authmethod = CHAP           #开启CHAP验证
 
node.session.auth.username = redhat           #CHAP帐号,与target中一样
 
node.session.auth.password = redhat123
 
 3.2.2 链接target
[root@station2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.32.39:3260
 
192.168.32.39:3260,1 iqn.2011-09.com.example.station9:disk1
 
[root@station2 ~]# iscsiadm -m node -T iqn.2011-09.com.example.station9:disk1 -p  192.168.32.39:3260 -l
 
Logging in to [iface: default, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]
 
Login to [iface: default, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]: successful 
 
4.   相互(Mutual)HAP incoming / outgoing验证
相互( Mutual ) CHAP验证: CHAP的认证端可为Target(Incoming Authentication)或是Initiator(Outgoing Authentication)任一端来认证.也就是说Target(Incoming Authentication)是由Target端为Initiator认证.这样的认证方式可以允许多个Initiator来连接到Target.而Initiator(Outgoing Authentication)是由Initiator来认证Target端。
 
刚刚已经设定过Incoming 的认证方式,现在要透过"tgtadm" 来建立Outgoing 的认证
 
4.1. target端创建outgong帐号
[root@station9 ~]# tgtadm --lld iscsi --op new --mode account --user out_redhat --password out_redhat123
 
[root@station9 ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user out_redhat –outgoing
 
[root@station9 ~]# tgtadm --lld iscsi --mode target --op show
 
Target 1: iqn.2011-09.com.example.station9:disk1
 
    System information:
 
        Driver: iscsi
 
        State: ready
 
    I_T nexus information:
 
        I_T nexus: 5
 
            Initiator: iqn.1994-05.com.redhat:e3e44fad96d1
 
            Connection: 0
 
                IP Address: 192.168.32.32
 
    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: 5124 MB
 
            Online: Yes
 
            Removable media: No
 
            Backing store type: rdwr
 
            Backing store path: /dev/sdb1
 
    Account information:
 
        redhat
 
        out_redhat (outgoing)
 
    ACL information:
 
        ALL
 
4.2. initiator配置
[root@station2 ~]# vim /etc/iscsi/iscsid.conf
 
node.session.timeo.replacement_timeout = 20  
 
node.session.auth.authmethod = CHAP          
 
node.session.auth.username = redhat          
 
node.session.auth.password = redhat123
 
node.session.auth.username_in = out_redhat   
 
#initiator端验证帐号,和target设备的outgoing帐号一样
 
node.session.auth.password_in = out_redhat123 
 
七、    initiator配合udev自动挂载iscsi
1.   创建iscsi设备信息获取脚本
[root@station2 scripts]# vim /etc/udev/scripts/iscsidev.sh
 
#!/bin/sh
 
# FILE: /etc/udev/scripts/iscsidev.sh
 
BUS=${1}
 
HOST=${BUS%%:*} 
 
[ -e /sys/class/iscsi_host ] || exit 1
 
file="/sys/class/iscsi_session/session*/targetname"
 
target_name=$(cat ${file}) 
 
# This is not an open-scsi drive
 
if [ -z "${target_name}" ]; then
 
  exit 1
 
fi 
 
echo "${target_name##*.}"
 
2.   建立udev策略文件
[root@station2 scripts]# vim /etc/udev/rules.d/99-iscsi.rules
 
KERNEL=="sd*",BUS=="scsi",PROGRAM=="/etc/udev/scripts/iscsidev.sh %b",SYMLINK+="Myiscsi%n"
 
#为iscsi设备生成软连接/dev/Myiscsi%n
 
3.   测试查看
[root@station2 scripts]# iscsiadm -m node -T iqn.2011-09.com.example.station9:disk1 -p 192.168.32.39:3260 -u
 
Logging out of session [sid: 1, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]
 
Logout of [sid: 1, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]: successful
 
#取消iscsi target设备挂载
 
[root@station2 scripts]# service iscsi restart
 
Stopping iSCSI daemon:
 
iscsid 已死,但 pid 文件仍存                               [确定]
 
Starting iSCSI daemon:                                     [确定]
 
                                                           [确定]
 
设置 iSCSI 目标:Logging in to [iface: default, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]
 
Login to [iface: default, target: iqn.2011-09.com.example.station9:disk1, portal: 192.168.32.39,3260]: successful
 
#重启iscsi服务,重新挂载iscsi target设备
 
[root@station2 scripts]# ll /dev/Myiscsi
 
lrwxrwxrwx 1 root root 3 09-22 22:06 /dev/Myiscsi -> sda
 
#udev策略配置生效

本文转自netsword 51CTO博客,原文链接:http://blog.51cto.com/netsword/671371
相关文章
|
Linux
CentOS/RHEL 7 “Failed to load selinux policy, freezing” 问题的解决
嘿!!!您在启动过程中是否遇到过此类问题。
231 0
CentOS/RHEL 7 “Failed to load selinux policy, freezing” 问题的解决
|
Linux
CentOS系统安装之网络问题(Network is unreachable;name or service not found)
CentOS系统安装之网络问题(Network is unreachable;name or service not found)
853 0
CentOS系统安装之网络问题(Network is unreachable;name or service not found)
|
网络协议 Linux 网络安全
Linux 解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.
转载:http://blog.csdn.net/c233728461/article/details/52679558 CentOS7中执行 [plain] view plain copy service iptables start/stop   会报错Failed to start iptables.
4210 0
|
网络协议 Linux JavaScript
|
网络安全 数据格式 XML
|
Linux 虚拟化 数据安全/隐私保护