02Linux系统上IP SAN的实现
配置环境
node1:192.168.1.151CentOS6.5
node2:192.168.1.152CentOS6.5
node3:192.168.1.153CentOS6.5#服务端:node3添加两块20G磁盘
配置iSCSI target(服务端)
1、准备硬盘
在node3上添加两块20磁盘
2、安装程序包,启动服务
[[email protected] ~]# yum -y install scsi-target-utils
[[email protected] ~]# service tgtd start
[[email protected] ~]# chkconfig tgtd on
3、创建target
方法1:命令行
创建iscsi target
[[email protected] ~]# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2015-06.com.magedu:s1.t1
查看当前主机上的iscsi target
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2015-06.com.magedu:s1.t1
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:
Account information:
ACL information:
方法2:配置文件方式
[[email protected] ~]# cd /etc/tgt/
[[email protected] tgt]# cp targets.conf{,.bak}
[[email protected] tgt]# vim targets.conf
添加
<target iqn.2015-06.com.magedu:s2.t1>
backing-store /dev/sdb
backing-store /dev/sdc
initiator-address 192.168.1.0/24
</target>
[[email protected] tgt]# service tgtd restart
[[email protected] tgt]# tgtadm -L iscsi -m target -o show
Target 1: iqn.2015-06.com.magedu:s2.t1
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdc
Backing store flags:
Account information:
ACL information:
192.168.1.0/24
4、创建lun
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2015-06.com.magedu:s1.t1
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:
Account information:
ACL information:
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2015-06.com.magedu:s1.t1
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdc
Backing store flags:
Account information:
ACL information:
删除lun
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 2
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2015-06.com.magedu:s1.t1
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:
Account information:
ACL information:
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc
5、授权
(1)通常IP地址认证
[[email protected] ~]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.1.0/24
(2)通过账号认证
#创建用户账号
[[email protected] ~]# tgtadm -L iscsi -m account -o new --user obama --password obama
#绑定用户账号
[[email protected] ~]# tgtadm -L iscsi -m account -o bind --tid 1 --user obama
#解绑用户账号
[[email protected] ~]# tgtadm -L iscsi -m account -o unbind --tid 1 --user obama
#查看用户账号
[[email protected] ~]# tgtadm -L iscsi -m account -o show
[[email protected] ~]# vim /etc/iscsi/iscsid.conf
去掉
60 #node.session.auth.username = username
61 #node.session.auth.password = password
74 #discovery.sendtargets.auth.username = username
75 #discovery.sendtargets.auth.password = password
行首的#号
配置iSCSI initiator(客户端)
1、安装程序包,配置initiator的名字,并启动服务
[[email protected] ~]# yum -y install iscsi-initiator-utils
[[email protected] ~]# service iscsi start
[[email protected] ~]# service iscsid start
[[email protected] ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu)" > /etc/iscsi/initiatorname.iscsi
[[email protected] ~]# for i in iscsi iscsid;do service $i restart;done
2、使用iscsiadm实现target的发现,注册等
(1)发现模式:discovery
[[email protected] ~]# iscsiadm -m discovery -d 3 -t st -p 192.168.1.153:3260
iscsiadm: ip 192.168.1.153, port 3260, tgpt -1
iscsiadm: Max file limits 1024 4096
Starting iscsid: [ OK ]
iscsiadm: Could not open /var/lib/iscsi/send_targets/192.168.1.153,3260: No such file or directory
iscsiadm: starting sendtargets discovery, address 192.168.1.153:3260,
iscsiadm: connecting to 192.168.1.153:3260
iscsiadm: connected local port 58181 to 192.168.1.153:3260
iscsiadm: connected to discovery address 192.168.1.153
iscsiadm: login response status 0000
iscsiadm: discovery process to 192.168.1.153:3260 exiting
iscsiadm: disconnecting conn 0xd87ce8, fd 3
192.168.1.153:3260,1 iqn.2015-06.com.magedu:s1.t1
[[email protected] ~]# ls /var/lib/iscsi/send_targets/
192.168.1.153,3260
[[email protected] ~]# ls /var/lib/iscsi/send_targets/192.168.1.153,3260/
iqn.2015-06.com.magedu:s1.t1,192.168.1.153,3260,1,default st_config
(2)节点模式:node#登录
登录target
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l
Logging in to [iface: default, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] (multiple)
Login to [iface: default, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.
登出target
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -u
Logging out of session [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]
Logout of [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.
删除target
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete#需要先登出target
[[email protected] ~]# ls /var/lib/iscsi/send_targets/192.168.1.153,3260/
st_config
[[email protected] ~]# iscsiadm -m discovery -d 3 -t st -p 192.168.1.153:3260
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l
[[email protected] ~]# fdisk -l /dev/sd[a-z]
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000284a7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x27fc8101.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won‘t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-20480, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): +5G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# mke2fs -t ext4 /dev/sdb1
[[email protected] ~]# mount /dev/sdb1 /mnt
[[email protected] ~]# cd /mnt/
[[email protected] ~]# fdisk -l /dev/sd[a-z]
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000284a7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x27fc8101
Device Boot Start End Blocks Id System
/dev/sdb1 1 5121 5243888 83 Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[[email protected] mnt]# cp /etc/issue /mnt/
[[email protected] mnt]# vim /mnt/issue
new line
node2安装配置iSCSI initiator
[[email protected] ~]# yum -y install iscsi-initiator-utils
[[email protected] ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu.com)" > /etc/iscsi/initiatorname.iscsi
[[email protected] ~]# service iscsi start
[[email protected] ~]# service iscsid start
[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.153:3260
Starting iscsid: [ OK ]
192.168.1.153:3260,1 iqn.2015-06.com.magedu:s1.t1
[[email protected] ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l
[[email protected] ~]# fdisk -l /dev/sd[a-z]
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000284a7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5248 41943040 83 Linux
/dev/sda3 5248 5509 2097152 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x27fc8101
Device Boot Start End Blocks Id System
/dev/sdb1 1 5121 5243888 83 Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[[email protected] ~]# mount /dev/sdb1 /mnt/
[[email protected] ~]# ls /mnt/
issue lost+found
issue lost+found
[[email protected] ~]# cat /mnt/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
new line
#和node1上添加后的内容一致
[[email protected] ~]# vim /mnt/issue
删除node1添加的new line行
[[email protected] mnt]# cat /mnt/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
new line
#node1上issue显示的还是原来的结果
[[email protected] ~]# umount /mnt
[[email protected] ~]# umount /mnt
解除绑定
1、客户端
#登出
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -uLogging out of session [sid: 3, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]
Logout of [sid: 3, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.
#删除
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -u
Logging out of session [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]
Logout of [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.
[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete
2、服务端
#删除lun
[[email protected] ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 2
[[email protected] ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 1
删除target
[[email protected] ~]# tgtadm -L iscsi -m target -o delete -t 1
[[email protected] ~]# tgtadm -L iscsi -m target -o show
[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.153:3260
[[email protected] ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s2.t1 -p 192.168.1.153:3260 -l
[[email protected] ~]# fdisk -l /dev/sd[a-z]