linux 共享磁盘scsi,linux下iscsi共享磁盘的实验

一:SCSI target

framework (tgt)

1.这个在Linux中集成了

# rpm -qa|grep

scsi-target

scsi-target-utils-0.0-6.20091205snap.el5_4.1

2.启动服务

#/etc/init.d/tgtd

start

设置为开机自动启动

Chkconfig tgtd on

确认一下有没有启动起来

#netstat –na|grep 3260

#

netstat -na|grep 3260

tcp        0

0 0.0.0.0:3260            0.0.0.0:*                   LISTEN

tcp        0   0

:::3260                     :::*                   LISTEN

3260是scsi target的侦听端口

3.配置,所有的配置都是通过tgtadm指令进行设置生效的

I:创建target

tgtadm --lld

iscsi --op new --mode target --tid 1 --targetname iqn.node212-sda12

这个命令没有回显,说明执行成功

用下面的命令看看刚才的命令干了些什么

# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.node212-sda12

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:

以上命令创建一个target为iqn.node212-sda12,id为1

--op new 代表新建

--op delete 代表删除

--op show 代表显示

--op

bind/unbind等等

LUN0是系统自动产生的,用来管理 device controller

II:向target分配一个物理的或文件的存储空间,再分配一个lun号;

可以向一个target分配一个或多个存储空间,而一个存储空间同时只能分配给一个target

现在我准备了一个划分好的分区和一个文件:

使用 dd 指令来创建一个1GB大小的文件

dd

if=/dev/zero of=/var/lun4 bs=1M count=1024

文件名位lun4,路径为/var/下

使用fdisk 划分一个分区/dev/sda12

接下来向刚才新建的target  iqn.node212-sda12分配储存空间

tgtadm --lld iscsi --op new --mode

logicalunit --tid 1 --lun 1 -b /dev/sda12

向tid为1的target里分配中logical unit为1的logical unit,设备为/dev/sda12,lun号必须指定;

tgtadm --lld iscsi --op show --mode target 查看信息

#

tgtadm --lld iscsi --op show --mode target

Target 1: iqn.node212-sda12

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: 5009 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /dev/sda12

Account information:

ACL information:

从信息可以看到,已经为tid为1的target分配了/dev/sda12的分区,大小为5G,并未它分配了lun号为1(lun0为系统占用,已经不可以使用)

再为这个target分配 /var/lun4,这个是之前用dd创建的设备

tgtadm --lld iscsi --op new --mode logicalunit --tid 1

--lun 2 -b /var/lun4

再看:

[root@localhost init.d]#  tgtadm --lld iscsi --op show --mode target

Target 1: iqn.node212-sda12

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:

5009 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /dev/sda12

LUN: 2

Type:

disk

SCSI

ID: IET     00010002

SCSI

SN: beaf12

Size:

1074 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /var/lun4

Account

information:

ACL

information:

III:设置访问控制:

为Target分配了存储设备后,需要设置访问控制后才可以使用,我们可以设置Target任意被访问,但是这样不安全;所以我们可以设置基于IP地址授权或基于用户验证的方式来控制对Target的访问

任意被访问:

任意被访问:

tgtadm --lld iscsi --op bind --mode target --tid 1 -I

ALL

tgtadm --lld -iscsi --op show --mode target           ?查看,看有什么

# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.node212-sda12

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:

5009 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /dev/sda12

LUN: 2

Type:

disk

SCSI

ID: IET     00010002

SCSI

SN: beaf12

Size:

1074 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /var/lun4

Account

information:

ACL

information:

ALL

把任意访问的授权给去掉

tgtadm

--lld iscsi --op unbind --mode target --tid 1 -I ALL

设置基于ip地址的授权

tgtadm

--lld iscsi --op bind --mode target --tid 1 -I 192.168.2.23

再授权一个ip:

tgtadm

--lld iscsi --op bind --mode target --tid 1 -I 192.168.2.33

授权一段IP

tgtadm

--lld iscsi --op bind --mode target --tid 1 -I 192.168.4.0/24

查看一下:

tgtadm

--lld iscsi --op show --mode target

# tgtadm --lld iscsi --op show --mode target

Target 1: iqn.node212-sda12

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: 5009 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /dev/sda12

LUN: 2

Type: disk

SCSI ID: IET     00010002

SCSI SN: beaf12

Size: 1074 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /var/lun4

Account information:

ACL

information:

192.168.2.23

192.168.5.116

192.168.4.0/24

客户端连接:window7下

控制面板à系统和安全—>管理工具—>ISCSI发起程序

填入服务器的IP地址,点“快速连接”

a0e6db79a193b0644ac9ca0bac87c7c5.png

点完成,再点确定。

从磁盘管理器中可以看到,客户端看到的是两个磁盘

4f4d76e357f4e1f7fb08710e1d314573.png

IV:删除操作:

从Target中移除lun

tgtadm --lld iscsi --op delete --mode logicalunit --tid

1 --lun 2

#  tgtadm --lld

iscsi --op show --mode target

Target 1: iqn.node212-sda12

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:

5009 MB

Online: Yes

Removable media: No

Backing store type: rdwr

Backing store path: /dev/sda12

Account

information:

ACL

information:

192.168.2.23

192.168.5.116

192.168.4.0/24

lun 2已经没了

删除target:

#tgtadm --lld iscsi --op delete --mode target --tid 1

不回显,命令成功;直接就把target给删除了,根本没提示你里面是否包含LUN,如果有客户端连接,客户端必须登出(客户端运行iscsiadm -m node -T iqn.node212 -p

192.168.7.212 –u)

用tgtadm --lld iscsi --op show --mode target看已经什么都没了。

LINUX客户端设置:

发现网络中可用的target:

iscsiadm -m discovery -t sendtargets -p 192.168.7.212

#iscsiadm -m discovery -t sendtargets -p 192.168.7.212

192.168.7.212:3260,1 iqn.node212

也可以写成iscsiadm -m discovery -t sendtargets -p 192.168.7.212:3260,不写端口默认找3260

登入可用的target会话

# iscsiadm -m node -T iqn.node212 -p 192.168.7.212:3260

-l

Logging in to [iface: default, target: iqn.node212,

portal: 192.168.7.212,3260]

Login to [iface: default, target: iqn.node212, portal:

192.168.7.212,3260]: successful

表示成功,fdisk –l查看,会看到这个设备。

查看target信息:

Iscsiadm –m node –P N 查看节点信息(N=0,1)

Iscsiadm –m session –P N 查看iscsi的会话信息(N=1-3)

Iscsiadm –m discovery –P N 查看discovery信息(N=0,1)

登出一个target会话

Logging out of session [sid: 1, target: iqn.node212,

portal: 192.168.7.212,3260]

Logout of [sid: 1, target: iqn.node212, portal:

192.168.7.212,3260]: successful

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值