Iscsi安装
yum install scsi-target-utils
service tgtd start
chkconfig tgtd on
修改配置文件/etc/tgt/targets.conf 将sdb磁盘添加为scsi磁盘
<target iqn.2008-09.com.example:server.target>
direct-store /dev/sdb
</target>
service tgtd restart 重启使配置文件生效
让任意客户端都可以存取
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
查看状态
[root@server01 ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2008-09.com.example:server.target 1就是tid
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 2
Initiator: iqn.1994-05.com.redhat:ace38f81479c
Connection: 0
IP Address: 192.168.100.31
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb
Backing store flags:
Account information:
ACL information:
ALL 允许所有人访问
上面的lun0不用管,它是用来管理controller device的,自动产生的,lun1
就是我们添加的scsi磁盘
开启防火墙允许客户端访问
iptables -I INPUT -s 192.168.100.31 -p tcp --dport 3260 -j ACCEPT
客户端安装iscsi-initiator
yum install iscsi-initiator *
客户端的iqn名字在文件/etc/iscsi/initiatorname.iscsi里面
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:ace38f81479c
#iscsiadm -m discovery -t sendtargets -p 192.168.100.30
192.168.100.30:3260,1 iqn.2008-09.com.example:server.target
# iscsiadm -m node -T iqn.2008-09.com.example:server.target -p 192.168.100.30:3260 -l
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] (multiple)
Login to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] successful.
fdisk 就可以看到添加的scsi磁盘, 格式化后就可以使用
可以通过修改服务端配置文件,控制客户IP的访问,下列只允许192.168.100.30客户端访问
<target iqn.2008-09.com.example:server.target>
<direct-store /dev/sdb>
initiator-address 192.168.100.30
</target>
[root@server02 ~]# iscsiadm -m node -T iqn.2008-09.com.example:server.target -p 192.168.100.30:3260 -l
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] (multiple) 由于服务端做了限制导致无法登陆。
除了指定一般的partition作为iscsi target端的lun外,还可以使用file当作block device 来使用,要预先建立空档案,
# dd if=/dev/zero of=iscsidisk bs=1M count=1024
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /root/iscsidisk 添加到target 1 作为lun2
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.100.0/24 设置访问规则
查看状态
# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2008-09.com.example:server.target
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /root/iscsidisk
Backing store flags:
Account information:
ACL information:
192.168.100.0/24
注: 在客户端挂载的时候为了避免重启scsi服务导致scsi盘符发生变化可以再/etc/fstab里使用磁盘的uuid挂载,查看uuid方法有两种
# ls -l /dev/disk/by-uuid/
# blkid
/dev/sda1: UUID="609bb710-9511-4429-85e1-bb4465c9b22d" TYPE="ext4"
/dev/sda2: UUID="FVJKca-zOMo-e8YI-uV0s-OwV6-YQe9-ym4Saz" TYPE="LVM2_member"
/dev/sdb: UUID="b7f4f061-b368-4ead-b289-f38394a5f08d" TYPE="xfs"
/dev/mapper/VolGroup-lv_root: UUID="e8bf310b-08e8-4a0d-97f6-711b08376ca3" TYPE="ext4"
/dev/sdc: UUID="7eeb4c9e-fc06-468d-9a6d-3f88cf933335" TYPE="xfs"
/dev/mapper/VolGroup-lv_swap: UUID="aea92c5f-dbea-4a1e-90cd-d319859d7785" TYPE="swap"
/dev/sdd1: UUID="a2d897ae-d931-4323-96b4-450765901b11" TYPE="ext4"
/dev/sde: UUID="3cf741a0-06f1-415e-9630-0bb753a86819" TYPE="ext4"
通过tgtadm命令建立的target相关配置,在关闭机器后将不保存,通过配置文件的方式则可以保存Target相关信息,在系统重启时,tgtd守护进程从配置文件中提取配置信息,根据配置信息建立相应的Target。Linux SCSI target framework (tgt)使用的配置文件为/etc/tgt/targets.conf
yum install scsi-target-utils
service tgtd start
chkconfig tgtd on
修改配置文件/etc/tgt/targets.conf 将sdb磁盘添加为scsi磁盘
<target iqn.2008-09.com.example:server.target>
direct-store /dev/sdb
</target>
service tgtd restart 重启使配置文件生效
让任意客户端都可以存取
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
查看状态
[root@server01 ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2008-09.com.example:server.target 1就是tid
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 2
Initiator: iqn.1994-05.com.redhat:ace38f81479c
Connection: 0
IP Address: 192.168.100.31
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb
Backing store flags:
Account information:
ACL information:
ALL 允许所有人访问
上面的lun0不用管,它是用来管理controller device的,自动产生的,lun1
就是我们添加的scsi磁盘
开启防火墙允许客户端访问
iptables -I INPUT -s 192.168.100.31 -p tcp --dport 3260 -j ACCEPT
客户端安装iscsi-initiator
yum install iscsi-initiator *
客户端的iqn名字在文件/etc/iscsi/initiatorname.iscsi里面
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:ace38f81479c
#iscsiadm -m discovery -t sendtargets -p 192.168.100.30
192.168.100.30:3260,1 iqn.2008-09.com.example:server.target
# iscsiadm -m node -T iqn.2008-09.com.example:server.target -p 192.168.100.30:3260 -l
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] (multiple)
Login to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] successful.
fdisk 就可以看到添加的scsi磁盘, 格式化后就可以使用
可以通过修改服务端配置文件,控制客户IP的访问,下列只允许192.168.100.30客户端访问
<target iqn.2008-09.com.example:server.target>
<direct-store /dev/sdb>
initiator-address 192.168.100.30
</target>
[root@server02 ~]# iscsiadm -m node -T iqn.2008-09.com.example:server.target -p 192.168.100.30:3260 -l
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target, portal: 192.168.100.30,3260] (multiple) 由于服务端做了限制导致无法登陆。
除了指定一般的partition作为iscsi target端的lun外,还可以使用file当作block device 来使用,要预先建立空档案,
# dd if=/dev/zero of=iscsidisk bs=1M count=1024
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /root/iscsidisk 添加到target 1 作为lun2
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.100.0/24 设置访问规则
查看状态
# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2008-09.com.example:server.target
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /root/iscsidisk
Backing store flags:
Account information:
ACL information:
192.168.100.0/24
注: 在客户端挂载的时候为了避免重启scsi服务导致scsi盘符发生变化可以再/etc/fstab里使用磁盘的uuid挂载,查看uuid方法有两种
# ls -l /dev/disk/by-uuid/
# blkid
/dev/sda1: UUID="609bb710-9511-4429-85e1-bb4465c9b22d" TYPE="ext4"
/dev/sda2: UUID="FVJKca-zOMo-e8YI-uV0s-OwV6-YQe9-ym4Saz" TYPE="LVM2_member"
/dev/sdb: UUID="b7f4f061-b368-4ead-b289-f38394a5f08d" TYPE="xfs"
/dev/mapper/VolGroup-lv_root: UUID="e8bf310b-08e8-4a0d-97f6-711b08376ca3" TYPE="ext4"
/dev/sdc: UUID="7eeb4c9e-fc06-468d-9a6d-3f88cf933335" TYPE="xfs"
/dev/mapper/VolGroup-lv_swap: UUID="aea92c5f-dbea-4a1e-90cd-d319859d7785" TYPE="swap"
/dev/sdd1: UUID="a2d897ae-d931-4323-96b4-450765901b11" TYPE="ext4"
/dev/sde: UUID="3cf741a0-06f1-415e-9630-0bb753a86819" TYPE="ext4"
通过tgtadm命令建立的target相关配置,在关闭机器后将不保存,通过配置文件的方式则可以保存Target相关信息,在系统重启时,tgtd守护进程从配置文件中提取配置信息,根据配置信息建立相应的Target。Linux SCSI target framework (tgt)使用的配置文件为/etc/tgt/targets.conf
可查看more /usr/share/doc/scsi-target-utils-1.0.24/下的说明文件获取帮助,
最后启动tgtd会出现如下提示: 是因为实在虚拟机里安装的么???
# service tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
inquiry: field in cdb illegal (page not supported)
tgtadm: invalid request
Command:
tgtadm -C 0 --lld iscsi --op update --mode logicalunit --tid 1 --lun=1 --params vendor_id="VMware, "
exited with code: 22.