阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.6 安装 iSCSI

157次阅读
没有评论

共计 17290 个字符,预计需要花费 44 分钟才能阅读完成。

一,ISCSI 简介

iSCSI,即 internet SCSI,又称为 IP-SAN,是 IETF 制订的一项标准,用于将 SCSI 数据块映射成以太网数据包。iSCSI 是一种基于 TCP/IP 的协议,用来建立和管理 IP 存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得 SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于 C / S 模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。

iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。

从根本上说,iSCSI 协议是一种跨过 IP 网络来传输潜伏时间短的 SCSI 数据块的方法。

完整的 iSCSI 系统的拓扑结构如下:

CentOS 6.6 安装 iSCSI

与传统的 SCSI 技术比较起来,iSCSI 技术有以下三个革命性的变化:

  1. 把原来只用于本机的 SCSI 协同透过 TCP/IP 网络传送,使连接距离可作无限的地域延伸;
  2.  
  3. 连接的服务器数量无限(原来的 SCSI- 3 的上限是 15);
  4.  
  5. 由于是服务器架构,因此也可以实现在线扩容以至动态部署。

ISCSI 的协议结构:

CentOS 6.6 安装 iSCSI

————————————– 分割线 ————————————–

CentOS 6.4 挂载 iSCSI 网络存储 http://www.linuxidc.com/Linux/2014-01/95130.htm

基于 RHCS+iSCSI+CLVM 实现 Web 服务的共享存储集群架构 http://www.linuxidc.com/Linux/2013-05/84888.htm

Linux 环境 iSCSI 存储及多路径功能配置 http://www.linuxidc.com/Linux/2013-05/84635.htm

构建基于 IP SAN 的 iSCSI 存储系统 http://www.linuxidc.com/Linux/2013-05/84570.htm

iSCSI 连接不上解决 http://www.linuxidc.com/Linux/2013-01/78462.htm

Citrix XenServer 中安装 CentOS 6.0 并配置 iSCSI 服务 http://www.linuxidc.com/Linux/2013-01/78461.htm

CentOS 5.3 使用 iSCSI 挂载存储磁盘柜 http://www.linuxidc.com/Linux/2011-01/31529.htm

带你 3 步快速掌握 iSCSI 搭建 http://www.linuxidc.com/Linux/2014-09/106853.htm

————————————– 分割线 ————————————–

二,搭建基于 IP SAN 的 ISCSI 存储系统

  1. 规划:
  2.  
  3. 环境:CentOS 6.6 32 位
  4.  
  5. 服务器端 IP:192.168.1.43
  6.  
  7. 客户端 IP:192.168.1.111
  8.  
  9. 共享磁盘:/dev/sdb

1,配置服务器端

  1. [root@localhost ~]# yum -y install scsi-target-utils #安装服务器端软件
  2.  
  3. [root@node1 iscsi]# rpm -ql scsi-target-utils
  4. /etc/rc.d/init.d/tgtd
  5. /etc/sysconfig/tgtd
  6. /etc/tgt/targets.conf #配置文件
  7. /usr/sbin/tgt-admin
  8. /usr/sbin/tgt-setup-lun
  9. /usr/sbin/tgtadm
  10. /usr/sbin/tgtd
  11. /usr/sbin/tgtimg
  12. /usr/share/doc/scsi-target-utils-1.0.24
  13. /usr/share/doc/scsi-target-utils-1.0.24/README
  14. /usr/share/doc/scsi-target-utils-1.0.24/README.iscsi
  15. /usr/share/doc/scsi-target-utils-1.0.24/README.iser
  16. /usr/share/doc/scsi-target-utils-1.0.24/README.lu_configuration
  17. /usr/share/doc/scsi-target-utils-1.0.24/README.mmc
  18. /usr/share/man/man5/targets.conf.5.gz
  19. /usr/share/man/man8/tgt-admin.8.gz
  20. /usr/share/man/man8/tgt-setup-lun.8.gz
  21. /usr/share/man/man8/tgtadm.8.gz
  22.  
  23. [root@localhost ~]# lsmod |grep scsi
  24. mptscsih 31330 1 mptspi
  25. mptbase 86744 2 mptspi,mptscsih
  26. scsi_transport_spi 19726 1 mptspi #高级驱动程序

iscsi 可以使用命令或配置文件进行配置,我们首先使用命令行来进行配置:

  1. [root@node1 iscsi]# service tgtd start
  2. Starting SCSI target daemon: [OK]
  3.  
  4. [root@node1 iscsi]# ss -tlnp |grep 3260 #其监听在 3260 端口
  5. LISTEN 0 128 :::3260 :::* users:((“tgtd”,11882,5),(“tgtd”,11885,5))
  6. LISTEN 0 128 *:3260 *:* users:((“tgtd”,11882,4),(“tgtd”,11885,4))
  7.  
  8. [root@localhost ~]# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2015-08.com.feiyu.testsan:1 #创建一个 target,- t 指定 TID,- T 指定名称

iqn 表示“ISCSI Qualified Name”,简称 iqn。

  1. [root@localhost ~]# tgtadm -L iscsi -o show -m target
  2. Target 1: iqn.2015-08.com.feiyu.testsan:1
  3. System information:
  4. Driver: iscsi
  5. State: ready
  6. I_T nexus information:
  7. LUN information:
  8. LUN: 0
  9. Type: controller
  10. SCSI ID: IET 00010000
  11. SCSI SN: beaf10
  12. Size: 0 MB, Block size: 1
  13. Online: Yes
  14. Removable media: No
  15. Prevent removal: No
  16. Readonly: No
  17. Backing store type: null
  18. Backing store path: None
  19. Backing store flags:
  20. Account information:
  21. ACL information:

然后设定 LUN(Logical Unit Number,逻辑单元号),服务器端只需要创建好分区,不需要格式化:

  1. [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/sdb5 #创建一个 LUN,- m 表示模式,-l:LUN,-b:设备
  2.  
  3. [root@localhost ~]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16
  4.  
  5. [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
  6. Target 1: iqn.2015-08.com.feiyu.testsan:1
  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. Backing store type: null
  22. Backing store path: None
  23. Backing store flags:
  24. LUN: 1
  25. Type: disk
  26. SCSI ID: IET 00010001
  27. SCSI SN: beaf11
  28. Size: 2107 MB, Block size: 512
  29. Online: Yes
  30. Removable media: No
  31. Prevent removal: No
  32. Readonly: No
  33. Backing store type: rdwr
  34. Backing store path: /dev/sdb5
  35. Backing store flags:
  36. Account information:
  37. ACL information:
  38.  
  39. [root@node1 iscsi]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16 #设定共享区
  40. [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
  41. Target 1: iqn.2015-08.com.feiyu.testsan:1
  42. System information:
  43. Driver: iscsi
  44. State: ready
  45. I_T nexus information:
  46. LUN information:
  47. LUN: 0
  48. Type: controller
  49. SCSI ID: IET 00010000
  50. SCSI SN: beaf10
  51. Size: 0 MB, Block size: 1
  52. Online: Yes
  53. Removable media: No
  54. Prevent removal: No
  55. Readonly: No
  56. Backing store type: null
  57. Backing store path: None
  58. Backing store flags:
  59. LUN: 1
  60. Type: disk
  61. SCSI ID: IET 00010001
  62. SCSI SN: beaf11
  63. Size: 2107 MB, Block size: 512
  64. Online: Yes
  65. Removable media: No
  66. Prevent removal: No
  67. Readonly: No
  68. Backing store type: rdwr
  69. Backing store path: /dev/sda5
  70. Backing store flags:
  71. Account information:
  72. ACL information:
  73. 192.168.0.0/16
  74.  
  75. [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b /dev/sdb6 #绑定第二个 LUN

2,配置客户端

  1. [root@node1 ~]# yum install -y iscsi-initiator-utils #安装客户端
  2.  
  3.  
  4. [root@node1 iscsi]# echo “InitiatorName=`iscsi-iname -p iqn.2013-05.com.feiyu`” > /etc/iscsi/initiatorname.iscsi #生成 iqn
  5. [root@node1 iscsi]# echo “InitiatorAlias=initiator1” >> /etc/iscsi/initiatorname.iscsi #定义别名
  6.  
  7. [root@node1 iscsi]# ls
  8. initiatorname.iscsi iscsid.conf
  9. [root@node1 iscsi]# cat initiatorname.iscsi #查看所定义的数据
  10. InitiatorName=iqn.2015-08.com.feiyu:10834bd52221
  11. InitiatorAlias=initiator1
  12.  
  13. [root@node1 ~]# service iscsi start #启动服务,需要启动两个服务
  14. [root@node1 ~]# service iscsid start
  15. [root@node1 ~]# chkconfig iscsi on
  16. [root@node1 ~]# chkconfig iscsid on

若出现以下错误,可能由于服务器端的防火墙没有关!

  1. [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43
  2. Starting iscsid: [OK]
  3. iscsiadm: cannot make connection to 192.168.1.43: No route to host
  4.  
  5. [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43 #进行探测
  6. 192.168.1.43:3260,1 iqn.2015-08.com.feiyu.testsan:1
  7.  
  8. [root@node1 ~]# iscsiadm -m node -T iqn.2015-08.com.feiyu.testsan:1 -p 192.168.1.43 -l #登录节点
  9. Logging in to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] (multiple)
  10. Login to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] successful.
  11.  
  12. [root@node1 ~]# fdisk -l #登录成功可以看到多了一块硬盘,
  13.  
  14. Disk /dev/sda: 21.5 GB, 21474836480 bytes
  15. 255 heads, 63 sectors/track, 2610 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17. Sector size (logical/physical): 512 bytes / 512 bytes
  18. I/O size (minimum/optimal): 512 bytes / 512 bytes
  19. Disk identifier: 0x0006d052
  20.  
  21. Device Boot Start End Blocks Id System
  22. /dev/sda1 * 1 39 307200 83 Linux
  23. Partition 1 does not end on cylinder boundary.
  24. /dev/sda2 39 2354 18598912 83 Linux
  25. /dev/sda3 2354 2610 2057689 5 Extended
  26. /dev/sda5 2354 2610 2057657+ 83 Linux
  27.  
  28. Disk /dev/sdc: 10.7 GB, 10742183424 bytes ——-> iscsi 设备
  29. 64 heads, 32 sectors/track, 10244 cylinders
  30. Units = cylinders of 2048 * 512 = 1048576 bytes
  31. Sector size (logical/physical): 512 bytes / 512 bytes
  32. I/O size (minimum/optimal): 512 bytes / 512 bytes
  33. Disk identifier: 0x00000000

为磁盘创建分区并格式化。

  1. [root@node1 ~]# mke2fs -t ext4 /dev/sdc1

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-07/133046p2.htm

若使用两个客户端,不要同时挂载同一个文件系统,它是单机的,不支持同时使用。可以将其分为多个分区,不同客户端挂载不同分区。

  1. [root@node1 mnt]# iscsiadm -m node -T iqn.2015-08.com.feiyu.testsan:1 -p 192.168.1.43 -u #登出
  2. Logging out of session [sid: 1, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260]
  3. Logout of [sid: 1, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] successful.
  4.  
  5. [root@node1 mnt]# ls /var/lib/iscsi/ #此文件夹下存放所有信息
  6. ifaces isns nodes send_targets slp static
  7.  
  8. [root@node1 ~]# iscsiadm -m node -T iqn.2015-08.com.feiyu.testsan:2 -p 192.168.1.43 -o delete #删除探测到的信息

3,服务器端从配置文件中设定,在文件中设置比较简单

  1. [root@localhost ~]# tgtadm -L iscsi -o unbind -m target -t 1 -I 192.168.0.0/16 #解除绑定
  2. [root@localhost ~]# tgtadm -L iscsi -o show -m target #查看 iscsi 信息
  3.  
  4. [root@localhost ~]# tgtadm -L iscsi -o delete -m logicalunit -t 1 -l 2 #将 target1 上的 LUN2 delete 掉
  5. [root@localhost ~]# tgtadm -L iscsi -o delete -m target -t 1 #删除 target
  6.  
  7. [root@localhost tgt]# vim targets.conf #添加以下配置
  8.  
  9. <targetiqn.2015-08.com.feiyu.testsan:2>
  10. backing-store /dev/sdb4
  11. </target>
  12.  
  13. [root@localhost tgt]# service tgtd restart
  14. Stopping SCSI target daemon: [OK]
  15. Starting SCSI target daemon: [OK]
  16. [root@localhost tgt]# tgtadm -L iscsi -o show -m target
  17. Target 1: iqn.2015-08.com.feiyu.testsan:2
  18. System information:
  19. Driver: iscsi
  20. State: ready
  21. I_T nexus information:
  22. LUN information:
  23. LUN: 0
  24. Type: controller
  25. SCSI ID: IET 00010000
  26. SCSI SN: beaf10
  27. Size: 0 MB, Block size: 1
  28. Online: Yes
  29. Removable media: No
  30. Prevent removal: No
  31. Readonly: No
  32. Backing store type: null
  33. Backing store path: None
  34. Backing store flags:
  35. LUN: 1
  36. Type: disk
  37. SCSI ID: IET 00010001
  38. SCSI SN: beaf11
  39. Size: 0 MB, Block size: 512
  40. Online: Yes
  41. Removable media: No
  42. Prevent removal: No
  43. Readonly: No
  44. Backing store type: rdwr
  45. Backing store path: /dev/sdb4
  46. Backing store flags:
  47. Account information:
  48. ACL information:
  49. ALL
  50.  
  51. [root@localhost tgt]# vim targets.conf #设置访问控制权限
  52. <targetiqn.2015-08.com.feiyu.testsan:2>
  53. backing-store /dev/sdb4
  54. initiator-address 192.168.0.0/16
  55. </target>
  56.  
  57. [root@localhost tgt]# service tgtd restart
  58. [root@localhost ~]# tgtadm -L iscsi -o show -m target #查看 iscsi 信息

说明:

1,服务端配置管理工具 tgtadm 的使用:

  1. tgtadm –lld [driver] –op [operation] –mode [mode] [OPTION]…

(1)、添加一个新的 target 且其 ID 为 [id],名字为 [name]:

  1. <code>
  2. –lld [driver] –op new –mode target –tid=[id] –targetname [name]
  3. </code>

(2)、显示所有或某个特定的 target:

  1. <code>
  2. –lld [driver] –op show –mode target [–tid=[id]]
  3. </code>

(3)、向某 ID 为 [id] 的设备上添加一个新的 LUN,其号码为 [lun],且此设备提供给 initiator 使用。[path] 是某“块设备”的路径,此块设备也可以是 raid 或 lvm 设备。lun0 已经被系统预留:

  1. <code>
  2. –lld [driver] –op new –mode=logicalunit –tid=[id] –lun=[lun] –backing-store [path]
  3. </code>

(4)、删除 ID 为 [id] 的 target:

  1. <code>
  2. –lld [driver] –op delete –mode target –tid=[id]
  3. </code>

(5)、删除 target [id]中的 LUN [lun]:

  1. <code>
  2. -lld [driver] –op delete –mode=logicalunit –tid=[id] –lun=[lun]
  3. </code>

(6)、定义某 target 的基于主机的访问控制列表,其中,[address]表示允许访问此 target 的 initiator 客户端的列表:

  1. <code>
  2. –lld [driver] –op bind –mode=target –tid=[id] –initiator-address=[address]
  3. </code>

(7)、解除 target [id]的访问控制列表中 [address] 的访问控制权限:

  1. <code>
  2. –lld [driver] –op unbind –mode=target –tid=[id] –initiator-address=[address]
  3. </code>

例如:

(1)创建一个 target:

  1. <code>
  2. # tgtadm –lld iscsi –op new –mode target –tid 1 -T iqn.2013-05.com.magedu:tsan.disk1
  3. </code>

(2)显示所有:

  1. <code>
  2. # tgtadm –lld iscsi –op show –mode target
  3. </code>

(3)显示刚创建的 target:

  1. <code>
  2. # tgtadm –lld iscsi –op show –mode target –tid 1
  3. </code>

(4)创建 LUN,号码为 1:

  1. <code>
  2. # tgtadm –lld iscsi –op new –mode logicalunit –tid 1 –lun 1 -b /dev/sda5
  3. </code>

(5)开放给 192.168.0.0/24 网络中的主机访问:

  1. <code>
  2. # tgtadm –lld iscsi –op bind –mode target –tid 1 -I 172.16.0.0/16
  3. </code>

其中的 - I 相当于–initiator-address

2、iscsiadm 工具的使用:

iscsiadm 是个模式化的工具,其模式可通过 - m 或–mode 选项指定,常见的模式有 discovery、node、fw、session、host、iface 几个,如果没有额外指定其它选项,则 discovery 和 node 会显示其相关的所有记录;session 用于显示所有的活动会话和连接,fw 显示所有的启动固件值,host 显示所有的 iSCSI 主机,iface 显示 /var/lib/iscsi/ifaces 目录中的所有 ifaces 设定。

  1. <code>
  2. iscsiadm -m discovery [-d debug_level] [-P printlevel] [-I iface -t type -p ip:port [ -l] ]
  3.  
  4. iscsiadm -m node [-d debug_level] [-P printlevel] [-L all,manual,automatic] [-U all,manual,automatic] [[ -T tar-getname -p ip:port -I iface] [-l | -u | -R | -s] ] [[ -o operation]
  5.  
  6. -d, –debug=debug_level 显示 debug 信息,级别为 0 -8;
  7.  
  8. -l, –login
  9.  
  10. -t, –type=type 这里可以使用的类型为 sendtargets(可简写为 st)、slp、fw 和 isns,此选项仅用于 discovery 模式,且目前仅支持 st、fw 和 isns;其中 st 表示允许每个 iSCSI target 发送一个可用 target 列表给 initiator;
  11.  
  12. -p, –portal=ip[:port] 指定 target 服务的 IP 和端口;
  13.  
  14. -m, –mode op 可用的 mode 有 discovery, node, fw, host iface 和 session
  15.  
  16. -T, –targetname=targetname 用于指定 target 的名字
  17.  
  18. -u, –logout
  19.  
  20. -o, –op=OPEARTION:指定针对 discoverydb 数据库的操作,其仅能为 new、delete、update、show 和 nonpersistent 其中之一;
  21.  
  22. -I, –interface=[iface]:指定执行操作的 iSCSI 接口,这些接口定义在 /var/lib/iscsi/ifaces 中;
  23. </code>

例:

  1. <code>
  2. # iscsiadm -m discovery -t sendtargets -p 192.168.0.11
  3.  
  4. # iscsiadm -m node -T iqn.2010-8.com.example.ts:disk1 -p 192.168.0.11:3260 -l
  5.  
  6. # iscsiadm -m node -T iqn.2010-8.com.example.ts:disk1 -p 192.168.0.11:3260 -u
  7.  
  8. # iscsiadm -m node -T iqn.2010-8.com.example.ts:disk1 -p 192.168.0.11:3260 -o delete
  9. </code>

查看会话相关信息:

  1. <code>
  2. # iscsiadm -m session -s
  3. </code>

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-07/133046.htm

一,ISCSI 简介

iSCSI,即 internet SCSI,又称为 IP-SAN,是 IETF 制订的一项标准,用于将 SCSI 数据块映射成以太网数据包。iSCSI 是一种基于 TCP/IP 的协议,用来建立和管理 IP 存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得 SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于 C / S 模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。

iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。

从根本上说,iSCSI 协议是一种跨过 IP 网络来传输潜伏时间短的 SCSI 数据块的方法。

完整的 iSCSI 系统的拓扑结构如下:

CentOS 6.6 安装 iSCSI

与传统的 SCSI 技术比较起来,iSCSI 技术有以下三个革命性的变化:

  1. 把原来只用于本机的 SCSI 协同透过 TCP/IP 网络传送,使连接距离可作无限的地域延伸;
  2.  
  3. 连接的服务器数量无限(原来的 SCSI- 3 的上限是 15);
  4.  
  5. 由于是服务器架构,因此也可以实现在线扩容以至动态部署。

ISCSI 的协议结构:

CentOS 6.6 安装 iSCSI

————————————– 分割线 ————————————–

CentOS 6.4 挂载 iSCSI 网络存储 http://www.linuxidc.com/Linux/2014-01/95130.htm

基于 RHCS+iSCSI+CLVM 实现 Web 服务的共享存储集群架构 http://www.linuxidc.com/Linux/2013-05/84888.htm

Linux 环境 iSCSI 存储及多路径功能配置 http://www.linuxidc.com/Linux/2013-05/84635.htm

构建基于 IP SAN 的 iSCSI 存储系统 http://www.linuxidc.com/Linux/2013-05/84570.htm

iSCSI 连接不上解决 http://www.linuxidc.com/Linux/2013-01/78462.htm

Citrix XenServer 中安装 CentOS 6.0 并配置 iSCSI 服务 http://www.linuxidc.com/Linux/2013-01/78461.htm

CentOS 5.3 使用 iSCSI 挂载存储磁盘柜 http://www.linuxidc.com/Linux/2011-01/31529.htm

带你 3 步快速掌握 iSCSI 搭建 http://www.linuxidc.com/Linux/2014-09/106853.htm

————————————– 分割线 ————————————–

二,搭建基于 IP SAN 的 ISCSI 存储系统

  1. 规划:
  2.  
  3. 环境:CentOS 6.6 32 位
  4.  
  5. 服务器端 IP:192.168.1.43
  6.  
  7. 客户端 IP:192.168.1.111
  8.  
  9. 共享磁盘:/dev/sdb

1,配置服务器端

  1. [root@localhost ~]# yum -y install scsi-target-utils #安装服务器端软件
  2.  
  3. [root@node1 iscsi]# rpm -ql scsi-target-utils
  4. /etc/rc.d/init.d/tgtd
  5. /etc/sysconfig/tgtd
  6. /etc/tgt/targets.conf #配置文件
  7. /usr/sbin/tgt-admin
  8. /usr/sbin/tgt-setup-lun
  9. /usr/sbin/tgtadm
  10. /usr/sbin/tgtd
  11. /usr/sbin/tgtimg
  12. /usr/share/doc/scsi-target-utils-1.0.24
  13. /usr/share/doc/scsi-target-utils-1.0.24/README
  14. /usr/share/doc/scsi-target-utils-1.0.24/README.iscsi
  15. /usr/share/doc/scsi-target-utils-1.0.24/README.iser
  16. /usr/share/doc/scsi-target-utils-1.0.24/README.lu_configuration
  17. /usr/share/doc/scsi-target-utils-1.0.24/README.mmc
  18. /usr/share/man/man5/targets.conf.5.gz
  19. /usr/share/man/man8/tgt-admin.8.gz
  20. /usr/share/man/man8/tgt-setup-lun.8.gz
  21. /usr/share/man/man8/tgtadm.8.gz
  22.  
  23. [root@localhost ~]# lsmod |grep scsi
  24. mptscsih 31330 1 mptspi
  25. mptbase 86744 2 mptspi,mptscsih
  26. scsi_transport_spi 19726 1 mptspi #高级驱动程序

iscsi 可以使用命令或配置文件进行配置,我们首先使用命令行来进行配置:

  1. [root@node1 iscsi]# service tgtd start
  2. Starting SCSI target daemon: [OK]
  3.  
  4. [root@node1 iscsi]# ss -tlnp |grep 3260 #其监听在 3260 端口
  5. LISTEN 0 128 :::3260 :::* users:((“tgtd”,11882,5),(“tgtd”,11885,5))
  6. LISTEN 0 128 *:3260 *:* users:((“tgtd”,11882,4),(“tgtd”,11885,4))
  7.  
  8. [root@localhost ~]# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2015-08.com.feiyu.testsan:1 #创建一个 target,- t 指定 TID,- T 指定名称

iqn 表示“ISCSI Qualified Name”,简称 iqn。

  1. [root@localhost ~]# tgtadm -L iscsi -o show -m target
  2. Target 1: iqn.2015-08.com.feiyu.testsan:1
  3. System information:
  4. Driver: iscsi
  5. State: ready
  6. I_T nexus information:
  7. LUN information:
  8. LUN: 0
  9. Type: controller
  10. SCSI ID: IET 00010000
  11. SCSI SN: beaf10
  12. Size: 0 MB, Block size: 1
  13. Online: Yes
  14. Removable media: No
  15. Prevent removal: No
  16. Readonly: No
  17. Backing store type: null
  18. Backing store path: None
  19. Backing store flags:
  20. Account information:
  21. ACL information:

然后设定 LUN(Logical Unit Number,逻辑单元号),服务器端只需要创建好分区,不需要格式化:

  1. [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/sdb5 #创建一个 LUN,- m 表示模式,-l:LUN,-b:设备
  2.  
  3. [root@localhost ~]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16
  4.  
  5. [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
  6. Target 1: iqn.2015-08.com.feiyu.testsan:1
  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. Backing store type: null
  22. Backing store path: None
  23. Backing store flags:
  24. LUN: 1
  25. Type: disk
  26. SCSI ID: IET 00010001
  27. SCSI SN: beaf11
  28. Size: 2107 MB, Block size: 512
  29. Online: Yes
  30. Removable media: No
  31. Prevent removal: No
  32. Readonly: No
  33. Backing store type: rdwr
  34. Backing store path: /dev/sdb5
  35. Backing store flags:
  36. Account information:
  37. ACL information:
  38.  
  39. [root@node1 iscsi]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16 #设定共享区
  40. [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
  41. Target 1: iqn.2015-08.com.feiyu.testsan:1
  42. System information:
  43. Driver: iscsi
  44. State: ready
  45. I_T nexus information:
  46. LUN information:
  47. LUN: 0
  48. Type: controller
  49. SCSI ID: IET 00010000
  50. SCSI SN: beaf10
  51. Size: 0 MB, Block size: 1
  52. Online: Yes
  53. Removable media: No
  54. Prevent removal: No
  55. Readonly: No
  56. Backing store type: null
  57. Backing store path: None
  58. Backing store flags:
  59. LUN: 1
  60. Type: disk
  61. SCSI ID: IET 00010001
  62. SCSI SN: beaf11
  63. Size: 2107 MB, Block size: 512
  64. Online: Yes
  65. Removable media: No
  66. Prevent removal: No
  67. Readonly: No
  68. Backing store type: rdwr
  69. Backing store path: /dev/sda5
  70. Backing store flags:
  71. Account information:
  72. ACL information:
  73. 192.168.0.0/16
  74.  
  75. [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b /dev/sdb6 #绑定第二个 LUN

2,配置客户端

  1. [root@node1 ~]# yum install -y iscsi-initiator-utils #安装客户端
  2.  
  3.  
  4. [root@node1 iscsi]# echo “InitiatorName=`iscsi-iname -p iqn.2013-05.com.feiyu`” > /etc/iscsi/initiatorname.iscsi #生成 iqn
  5. [root@node1 iscsi]# echo “InitiatorAlias=initiator1” >> /etc/iscsi/initiatorname.iscsi #定义别名
  6.  
  7. [root@node1 iscsi]# ls
  8. initiatorname.iscsi iscsid.conf
  9. [root@node1 iscsi]# cat initiatorname.iscsi #查看所定义的数据
  10. InitiatorName=iqn.2015-08.com.feiyu:10834bd52221
  11. InitiatorAlias=initiator1
  12.  
  13. [root@node1 ~]# service iscsi start #启动服务,需要启动两个服务
  14. [root@node1 ~]# service iscsid start
  15. [root@node1 ~]# chkconfig iscsi on
  16. [root@node1 ~]# chkconfig iscsid on

若出现以下错误,可能由于服务器端的防火墙没有关!

  1. [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43
  2. Starting iscsid: [OK]
  3. iscsiadm: cannot make connection to 192.168.1.43: No route to host
  4.  
  5. [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43 #进行探测
  6. 192.168.1.43:3260,1 iqn.2015-08.com.feiyu.testsan:1
  7.  
  8. [root@node1 ~]# iscsiadm -m node -T iqn.2015-08.com.feiyu.testsan:1 -p 192.168.1.43 -l #登录节点
  9. Logging in to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] (multiple)
  10. Login to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] successful.
  11.  
  12. [root@node1 ~]# fdisk -l #登录成功可以看到多了一块硬盘,
  13.  
  14. Disk /dev/sda: 21.5 GB, 21474836480 bytes
  15. 255 heads, 63 sectors/track, 2610 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17. Sector size (logical/physical): 512 bytes / 512 bytes
  18. I/O size (minimum/optimal): 512 bytes / 512 bytes
  19. Disk identifier: 0x0006d052
  20.  
  21. Device Boot Start End Blocks Id System
  22. /dev/sda1 * 1 39 307200 83 Linux
  23. Partition 1 does not end on cylinder boundary.
  24. /dev/sda2 39 2354 18598912 83 Linux
  25. /dev/sda3 2354 2610 2057689 5 Extended
  26. /dev/sda5 2354 2610 2057657+ 83 Linux
  27.  
  28. Disk /dev/sdc: 10.7 GB, 10742183424 bytes ——-> iscsi 设备
  29. 64 heads, 32 sectors/track, 10244 cylinders
  30. Units = cylinders of 2048 * 512 = 1048576 bytes
  31. Sector size (logical/physical): 512 bytes / 512 bytes
  32. I/O size (minimum/optimal): 512 bytes / 512 bytes
  33. Disk identifier: 0x00000000

为磁盘创建分区并格式化。

  1. [root@node1 ~]# mke2fs -t ext4 /dev/sdc1

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-07/133046p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计17290字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中