SAN之iscsi网络存储共享构建操作

实验环境:

系统:centos-6.6 

kernel:2.6.32

target端:scsi-target-utils-1.0.24-16.el6.x86_64 

IP:192.168.150.138

initiator端:iscsi-initiator-utils-6.2.0.873-13.el6.x86_64 

IP:192.168.150.139


一.target端构建存储环境

添加七块硬盘,四块做raid5,三块做LVM

wKiom1SqdYCx44KeAAC4ksZboAY359.jpg

动态加载硬盘:

linux5加载方式

echo "scsi add-single-device 0 0 1 0" > /proc/scsi/scsi

linux6加载方式

echo "- - -" > /sys/class/scsi_host/host2/scan


[root@centos-server ~]# cat /proc/partitions    #查看硬盘被加载

major minor  #blocks  name


   8        0   20971520 sda

   8        1     512000 sda1

   8        2   20458496 sda2

 253        0   18391040 dm-0

 253        1    2064384 dm-1

   8       16    1048576 sdb

   8       32    1048576 sdc

   8       48    1048576 sdd

   8       64    1048576 sde

   8       80    1048576 sdf

   8       96    1048576 sdg

   8      112    1048576 sdh


  1. 做raid5:

[root@centos-server ~]# mdadm -Cv /dev/md0 -a yes -n3 -l5 -x1 /dev/sd[b-e]

mdadm: layout defaults to left-symmetric

mdadm: layout defaults to left-symmetric

mdadm: chunk size defaults to 512K

mdadm: size set to 1047552K

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.


[root@centos-server ~]# mdadm -Q /dev/md0

/dev/md0: 2046.34MiB raid5 3 devices, 1 spare. Use mdadm --detail for more detail.


2.做lvm:

[root@centos-server ~]# pvcreate /dev/sd[f-h]

  Physical volume "/dev/sdf" successfully created

  Physical volume "/dev/sdg" successfully created

  Physical volume "/dev/sdh" successfully created


[root@centos-server ~]# vgcreate dragonvg /dev/sd[f-h]

  Volume group "dragonvg" successfully created


[root@centos-server ~]# lvcreate -L 2.8G -n dragonlv  dragonvg

  Rounding up size to full physical extent 2.80 GiB

  Logical volume "peipeilv" created


二.target端发布iscsi:

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

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

正在启动 SCSI target daemon:                              [确定]


制作raid的对象

[root@centos-server ~]# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2015-1.dragon.com:raid

分配存储空间

[root@centos-server ~]# tgtadm --lld iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/md0

指定可以访问的客户机

[root@centos-server ~]# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.150.139

[root@centos-server ~]# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.150.130 #可以指定多个访问IP,但只有一个IP客户端能够挂载


查看创建的iscsi target

[root@centos-server ~]# tgtadm -L iscsi -o show -m target

Target 1: iqn.2015-1.dragon.com:raid

    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, Block size: 1

            Online: Yes

            Removable media: No

            Prevent removal: No

            Readonly: No

            Backing store type: null

            Backing store path: None

            Backing store flags: 

        LUN: 1

            Type: disk

            SCSI ID: IET     00010001

            SCSI SN: beaf11

            Size: 2145 MB, Block size: 512

            Online: Yes

            Removable media: No

            Prevent removal: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/md0

            Backing store flags: 

    Account information:

    ACL information:

        192.168.150.139

        192.168.150.130


发布LVM的target

[root@centos-server ~]# tgtadm -L iscsi -o new -m target -t 2 -T iqn.2015-1.dragon.com:lvm

[root@centos-server ~]# tgtadm --lld iscsi -o new -m lu -t 2 -l 1 -b /dev/dragonvg/dragonlv

[root@centos-server ~]# tgtadm --lld iscsi -o bind -m target -t 2 -I 192.168.150.139


也可以通过配置/etc/tgt/targets.conf发布target 

<target iqn.2015-1.dragon.com:raid>

        backing-store   /dev/md0

        initiator-address 192.168.150.139

</target>

<target iqn.2015-1.dragon.com:lvm>

        backing-store   /dev/dragonvg/dragonlv                

initiator-address 192.168.150.139

</target>


三.客户端发布和挂载iscsi:

[root@centos-server ~]# yum install iscsi-initiator-utils lsscsi #安装iscsi-initiator

[root@centos-server ~]# service iscsi start        #启动服务


[root@centos-server ~]# iscsiadm -m discovery -t sendtargets -p 192.168.150.138    #查找192.168.150.138发布的iscsi发布的可用对象

正在启动 iscsid:                                          [确定]

192.168.150.138:3260,1 iqn.2015-1.dragon.com:raid

192.168.150.138:3260,1 iqn.2015-1.dragon.com:lvm


[root@centos-server ~]# iscsiadm -m node -T iqn.2015-1.dragon.com:raid --login    #连接存储对象iqn.2015-1.dragon.com:raid 

Logging in to [iface: default, target: iqn.2015-1.dragon.com:raid, portal: 192.168.150.138,3260] (multiple)

Login to [iface: default, target: iqn.2015-1.dragon.com:raid, portal: 192.168.150.138,3260] successful.


[root@centos-server ~]# iscsiadm -m node -T iqn.2015-1.dragon.com:lvm --login    #连接存储对象iqn.2015-1.dragon.com:LVM

Logging in to [iface: default, target: iqn.2015-1.dragon.com:lvm, portal: 192.168.150.138,3260] (multiple)

Login to [iface: default, target: iqn.2015-1.dragon.com:lvm, portal: 192.168.150.138,3260] successful.


[root@centos-server ~]# lsscsi    #可以看到本机多了两块虚拟硬盘sdb和sdc

[1:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 

[2:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 

[3:0:0:0]    storage IET      Controller       0001  -       

[3:0:0:1]    disk    IET      VIRTUAL-DISK     0001  /dev/sdb 

[4:0:0:0]    storage IET      Controller       0001  -       

[4:0:0:1]    disk    IET      VIRTUAL-DISK     0001  /dev/sdc 



分区及格式化

[root@centos-server ~]# fdisk  /dev/sdb

n

p

1

[enter]

[enter]

w

[root@centos-server ~]# fdisk  /dev/sdc

n

p

1

[enter]

[enter]

w

[root@centos-server ~]# mkfs -t ext3 /dev/sdb1

[root@centos-server ~]# mkfs -t ext3 /dev/sdc1


挂载成功

[root@centos-server ~]# mkdir /test1

[root@centos-server ~]# mkdir /test2

[root@centos-server ~]# mount /dev/sdb1 /test1

[root@centos-server ~]# mount /dev/sdc1 /test2


wKioL1Sqea3C3B6yAAF0Sx9bUxU454.jpg


你可能感兴趣的:(linux,iSCSI)