红帽企业存储管理之iscsi简单应用

共享存储:

Ø das :direct attached storage 直接附加存储 

IDE

scsi 磁盘柜  7  15

Ø nas : network attached storage网络附加存储 (带有自己的操作系统)

samba nfs 文件级的共享

效率低   带有加锁机制,和推送功能

Ø san : 存储区域网络  

fc-san(fiber channer storage area network光纤)fc-switch

 scsi 格式 价格昂贵
ip-san (iscsi:ip)设备为普通设备

target  initiator  认证(ip—账号   --cheap)

效率高
群集文件系统   redhat:gfs2  oracle:ocfs2
DRBD :廉价文件同步方案

HA

Active---standby
Active---active
群集脑裂:split-brain     portioned  cluster

解决方法: stonith     (也叫fence)

硬件:(电源交换机,ssh,meatware)

模块:hp,ibm,sun   机器模块设备

块存储:ext2,ext3(本地文件系统   没有锁机制,没有推送机制)

群集文件系统:有锁机制和推送机制-- redhat:gfs(1-2)  oracle:(ocfs2)

iscsi存储管理:

target     (tgtd)(服务器)

scsi-target-utils.i386   3260    认证(ip-chanper)

Ø  target  id 号码
Ø  逻辑单元号
iqn 格式名字(iqn.日期(年-月).域名反写.string:substring)

如:iqn.2012-05.com.a.node1:target

管理:tgtadm --lld [driver] --op [operation] --mode [mode] [OPTION]...

--lld [driver] --op new --mode target --tid=[id] --targetname [name]

--lld [driver] --op show --mode target

--lld [driver] --op new --mode=logicalunit --tid=[id] --lun=[lun]

       --backing-store [path]

initiator  (客户端)

红帽企业存储管理之iscsi简单应用案例:

应用拓扑图:

红帽企业存储管理之iscsi简单应用_第1张图片

应用实现步骤:

一.Target-server服务器配置

配置本地yum数据库

[root@target-server ~]# hostname
target-server.junjie.com
[root@target-server ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:1B:F1:BA 
          inet addr:192.168.101.210  Bcast:192.168.101.255  Mask:255.255.255.0

[root@target-server ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]

name=Red Hat Enterprise Linux clusterstorage

baseurl=file:///mnt/cdrom/ClusterStorage/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
 
[root@target-server ~]# yum list all
安装 scsi-target 软件包:

[root@target-server ~]# yum list all |grep scsi-target

This system is not registered with RHN.

RHN support will be disabled.
scsi-target-utils.i386                 0.0-5.20080917snap.el5

[root@target-server ~]# yum install scsi-target-utils

 

[root@target-server ~]# rpm -ql scsi-target-utils

/etc/rc.d/init.d/tgtd                    #服务器控制脚本

/etc/sysconfig/tgtd
/etc/tgt/targets.conf
/usr/sbin/tgt-admin
/usr/sbin/tgt-setup-lun
/usr/sbin/tgtadm                 #target 管理工具
/usr/sbin/tgtd

#设置target开机启动,并启动tgtd服务

[root@target-server ~]# chkconfig tgtd on

[root@target-server ~]# chkconfig --list tgtd  

tgtd              0:off          1:off          2:on          3:on          4:on          5:on          6:off

[root@target-server ~]# service tgtd start

Starting SCSI target daemon:                               [  OK  ]

[root@target-server ~]# netstat -tupln |grep tgtd

tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      3893/tgtd          

tcp        0      0 :::3260                     :::*                        LISTEN      3893/tgtd

新建磁盘:(这里使用磁盘分区)

[root@target-server ~]# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes

255 heads, 63 sectors/track, 1566 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1033     8193150   83  Linux

/dev/sda3            1034        1224     1534207+  82  Linux swap / Solaris

[root@target-server ~]# fdisk /dev/sda

p/n/p//+1000M/p/w

[root@target-server ~]# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes

255 heads, 63 sectors/track, 1566 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1033     8193150   83  Linux

/dev/sda3            1034        1224     1534207+  82  Linux swap / Solaris

/dev/sda4            1225        1347      987997+  83  Linux

重新识别分区:(此处不需要格式化挂载)

[root@target-server ~]# cat /proc/partitions

8     0   12582912 sda

   8     1     104391 sda1

   8     2    8193150 sda2

   8     3    1534207 sda3

[root@target-server ~]# partprobe /dev/sda

[root@target-server ~]# cat /proc/partitions

   8     0   12582912 sda

   8     1     104391 sda1

   8     2    8193150 sda2

   8     3    1534207 sda3

   8     4     987997 sda4

#配置target,新建target设备和逻辑单元设备

[root@target-server ~]# tgtadm --lld iscsi --op new --mode target --tid 1 --targetname iqn.2012-05-22.com.junjie.node1:target

[root@target-server ~]# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.2012-05-22.com.junjie.node1:target

    System information:

        Driver: iscsi

        State: ready

    I_T nexus information:

    LUN information:

        LUN: 0

            Type: controller

            SCSI ID: deadbeaf1:0

            SCSI SN: beaf10

            Size: 0 MB

            Online: Yes

            Removable media: No

            Backing store: No backing store

    Account information:

    ACL information:

[root@target-server ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 --backing-store /dev/sda4

[root@target-server ~]# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.2012-05-22.com.junjie.node1:target

    System information:

        Driver: iscsi

        State: ready

    I_T nexus information:

    LUN information:

        LUN: 0

            Type: controller

            SCSI ID: deadbeaf1:0

            SCSI SN: beaf10

            Size: 0 MB

            Online: Yes

            Removable media: No

            Backing store: No backing store

        LUN: 1

            Type: disk

            SCSI ID: deadbeaf1:1

            SCSI SN: beaf11

            Size: 1012 MB

            Online: Yes

            Removable media: No

            Backing store: /dev/sda4

    Account information:

    ACL information:

配置身份验证机制:

[root@target-server ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 --initiator-address 192.168.101.0/24

[root@target-server ~]# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.2012-05-22.com.junjie.node1:target

    System information:

        Driver: iscsi

        State: ready

    I_T nexus information:

    LUN information:

        LUN: 0

            Type: controller

            SCSI ID: deadbeaf1:0

            SCSI SN: beaf10

            Size: 0 MB

            Online: Yes

            Removable media: No

            Backing store: No backing store

        LUN: 1

            Type: disk

            SCSI ID: deadbeaf1:1

            SCSI SN: beaf11

            Size: 1012 MB

            Online: Yes

            Removable media: No

            Backing store: /dev/sda4

    Account information:

    ACL information:

        192.168.101.0/24

此时的所有配置为临时配置,开机重启会丢失的,若要永久保持,又如下: 2 中方法
方法 1 :将以上脚本写到开机启动脚本中: /etc/rc.d/rc.local
方法 2 :开机启动

[root@target-server ~]# vim /etc/tgt/targets.conf

红帽企业存储管理之iscsi简单应用_第2张图片

二.Initiator-1(存储的客户端)配置

Initiator-1(存储的客户端)

配置本地yum数据库:

[root@initiator-1 ~]# hostname
initiator-1.junjie.com
[root@initiator-1 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:66:E1:DA 
          inet addr:192.168.101.211  Bcast:192.168.101.255  Mask:255.255.255.0

[root@initiator-1 ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]                                     
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=file:///mnt/cdrom/VT/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]

name=Red Hat Enterprise Linux clusterstorage

baseurl=file:///mnt/cdrom/ClusterStorage/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@initiator-1 ~]#

安装配置

[root@initiator-1 ~]# yum install -y iscsi-initiator-utils

[root@initiator-1 ~]# vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2012-05-22.com.junjie.initiator1

[root@initiator-1 ~]# chkconfig iscsi on

[root@initiator-1 ~]# service iscsi start

iscsid is stopped

Turning off network shutdown. Starting iSCSI daemon:       [  OK  ]

                                                           [  OK  ]

Setting up iSCSI targets: iscsiadm: No records found!

                                                           [  OK  ]

[root@initiator-1 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.101.210

192.168.101.210:3260,1 iqn.2012-05-22.com.junjie.node1:target

[root@initiator-1 ~]# iscsiadm --mode node --targetname iqn.2012-05-22.com.junjie.node1:target --portal 192.168.101.210:3260 --login

Logging in to [iface: default, target: iqn.2012-05-22.com.junjie.node1:target, portal: 192.168.101.210,3260]

Login to [iface: default, target: iqn.2012-05-22.com.junjie.node1:target, portal: 192.168.101.210,3260]: successful

[root@initiator-1 ~]# fdisk -l
 
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1033     8193150   83  Linux

/dev/sda3            1034        1224     1534207+  82  Linux swap / Solaris

 
Disk /dev/sdb: 1011 MB, 1011709440 bytes
32 heads, 61 sectors/track, 1012 cylinders
Units = cylinders of 1952 * 512 = 999424 bytes
 
Disk /dev/sdb doesn't contain a valid partition table

红帽企业存储管理之iscsi简单应用_第3张图片

此时就相当于本地磁盘(可以随意使用,可以格式化,挂载等)

[root@initiator-1 ~]# fdisk /dev/sdb

p/n/p/1///p/w

[root@initiator-1 ~]# fdisk -l

……

Disk /dev/sdb: 1011 MB, 1011709440 bytes

32 heads, 61 sectors/track, 1012 cylinders

Units = cylinders of 1952 * 512 = 999424 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1012      987681+  83  Linux

 

[root@initiator-1 ~]# partprobe /dev/sdb

[root@initiator-1 ~]# mkfs -t ext3 /dev/sdb1

[root@initiator-1 ~]# mkdir /mnt/1

[root@initiator-1 ~]# mount /dev/sdb1 /mnt/1/

[root@initiator-1 ~]# cd /mnt/1/

[root@initiator-1 1]# mkdir d1 d2 d3

[root@initiator-1 1]# touch f1 f2 f3

[root@initiator-1 1]# ll

total 28

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d1

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d2

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d3

-rw-r--r-- 1 root root     0 Apr  1 11:37 f1

-rw-r--r-- 1 root root     0 Apr  1 11:37 f2

-rw-r--r-- 1 root root     0 Apr  1 11:37 f3

drwx------ 2 root root 16384 Apr  1 11:34 lost+found

三.Initiator-2(存储的客户端)配置

Initiator-2(存储的客户端)

配置本地yum数据库:

[root@initiator-2~]# hostname
initiator-2.junjie.com
[root@initiator-2 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:79:F8:F7 
          inet addr:192.168.101.212  Bcast:192.168.101.255  Mask:255.255.255.0

[root@initiator-2 ~]# vim /etc/yum.repos.d/server.repo

[rhel-server]                                     
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=file:///mnt/cdrom/VT/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]

name=Red Hat Enterprise Linux clusterstorage

baseurl=file:///mnt/cdrom/ClusterStorage/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[root@initiator-2 ~]#

安装配置

[root@initiator-2 ~]# yum install -y iscsi-initiator-utils

[root@initiator-2 ~]# vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2012-05-22.com.junjie.initiator 2

[root@initiator-2 ~]# service iscsi start

iscsid is stopped

Turning off network shutdown. Starting iSCSI daemon:       [  OK  ]

                                                           [  OK  ]

Setting up iSCSI targets: iscsiadm: No records found!

                                                           [  OK  ]

[root@initiator-2 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.101.210

192.168.101.210:3260,1 iqn.2012-05-22.com.junjie.node1:target

[root@initiator-2 ~]# iscsiadm --mode node --targetname iqn.2012-05-22.com.junjie.node1:target --portal 192.168.101.210:3260 --login

Logging in to [iface: default, target: iqn.2012-05-22.com.junjie.node1:target, portal: 192.168.101.210,3260]

Login to [iface: default, target: iqn.2012-05-22.com.junjie.node1:target, portal: 192.168.101.210,3260]: successful

[root@initiator-2 ~]# fdisk -l

………….

Disk /dev/sdb: 1011 MB, 1011709440 bytes

32 heads, 61 sectors/track, 1012 cylinders

Units = cylinders of 1952 * 512 = 999424 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1012      987681+  83  Linux

[root@initiator-2 ~]#

此时就相当于本地磁盘(可以随意使用,可以格式化,挂载等)

红帽企业存储管理之iscsi简单应用_第4张图片

[root@initiator-2 ~]# mkdir /mnt/1

[root@initiator-2 ~]# mount /dev/sdb1 /mnt/1/

[root@initiator-2 ~]# cd /mnt/1/   

[root@initiator-2 1]# ll

total 28

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d1

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d2

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d3

-rw-r--r-- 1 root root     0 Apr  1 11:37 f1

-rw-r--r-- 1 root root     0 Apr  1 11:37 f2

-rw-r--r-- 1 root root     0 Apr  1 11:37 f3

drwx------ 2 root root 16384 Apr  1 11:34 lost+found

(发现存储设备上的文件信息应经存在)
四.测试文件的锁机制和推送机制

由于该文件系统是块存储:ext2ext3本地文件系统,故没有锁机制,也没有推送机制

4.1测试推送功能

initiator-2上创建qq文件

[root@initiator-2 1]# echo "01" >f1

[root@initiator-2 1]# touch qq

[root@initiator-2 1]# ll

total 32

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d1

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d2

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d3

-rw-r--r-- 1 root root     3 Apr  1 12:03 f1

-rw-r--r-- 1 root root     0 Apr  1 11:37 f2

-rw-r--r-- 1 root root     0 Apr  1 11:37 f3

drwx------ 2 root root 16384 Apr  1 11:34 lost+found

-rw-r--r-- 1 root root     0 Apr  1 12:03 qq

initiator-1上没有发现qq文件

[root@initiator-1 1]# ll

total 28

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d1

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d2

drwxr-xr-x 2 root root  4096 Apr  1 11:37 d3

-rw-r--r-- 1 root root     0 Apr  1 11:37 f1

-rw-r--r-- 1 root root     0 Apr  1 11:37 f2

-rw-r--r-- 1 root root     0 Apr  1 11:37 f3

drwx------ 2 root root 16384 Apr  1 11:34 lost+found

[root@initiator-1 1]#

4.2测试锁机制功能

红帽企业存储管理之iscsi简单应用_第5张图片

经过测试可以知道:块存储:ext2ext3本地文件系统,故没有锁机制,也没有推送机制

 
附录:
initiator 卸载远端存储设备:

iscsiadm --mode node -T iqn.2011-09-28:disk1 -p 192.168.0.254:3260 --logout(service iscsi restart后又会注册)

iscsiadm --mode node -T iqn.2011-09-28:disk1 -p 192.168.0.254:3260 -o delete

《完》

--xjzhujunjie--2012/05/06