CentOS 6.6 安装 iSCSI

一,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系统的拓扑结构如下:

041650184024895

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

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

ISCSI的协议结构:

iscsi

--------------------------------------分割线--------------------------------------

--------------------------------------分割线--------------------------------------

二,搭建基于 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

猜你喜欢

转载自www.linuxidc.com/Linux/2016-07/133046.htm