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、安装程序包,启动服务
[root@node3 ~]# yum -y install scsi-target-utils
[root@node3 ~]# service tgtd start
[root@node3 ~]# chkconfig tgtd on
3、创建target
方法1:命令行
创建iscsi target
[root@node3 ~]# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2015-06.com.magedu:s1.t1
查看当前主机上的iscsi target
[root@node3 ~]# 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:配置文件方式
[root@node3 ~]# cd /etc/tgt/
[root@node3 tgt]# cp targets.conf{,.bak}
[root@node3 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>
[root@node3 tgt]# service tgtd restart
[root@node3 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
[root@node3 ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb
[root@node3 ~]# 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:
[root@node3 ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc
[root@node3 ~]# 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
[root@node3 ~]# tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 2
[root@node3 ~]# 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:
[root@node3 ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc
5、授权
(1)通常IP地址认证
[root@node3 ~]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.1.0/24
(2)通过账号认证
#创建用户账号
[root@node3 ~]# tgtadm -L iscsi -m account -o new --user obama --password obama
#绑定用户账号
[root@node3 ~]# tgtadm -L iscsi -m account -o bind --tid 1 --user obama
#解绑用户账号
[root@node3 ~]# tgtadm -L iscsi -m account -o unbind --tid 1 --user obama
#查看用户账号
[root@node3 ~]# tgtadm -L iscsi -m account -o show
[root@node1 ~]# 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的名字,并启动服务
[root@node1 ~]# yum -y install iscsi-initiator-utils
[root@node1 ~]# service iscsi start
[root@node1 ~]# service iscsid start
[root@node1 ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu)" > /etc/iscsi/initiatorname.iscsi
[root@node1 ~]# for i in iscsi iscsid;do service $i restart;done
2、使用iscsiadm实现target的发现,注册等
(1)发现模式:discovery
[root@node1 ~]# 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
[root@node1 ~]# ls /var/lib/iscsi/send_targets/
192.168.1.153,3260
[root@node1 ~]# 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
[root@node1 ~]# 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
[root@node1 ~]# 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
[root@node1 ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete#需要先登出target
[root@node1 ~]# ls /var/lib/iscsi/send_targets/192.168.1.153,3260/
st_config
[root@node1 ~]# iscsiadm -m discovery -d 3 -t st -p 192.168.1.153:3260
[root@node1 ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l
[root@node1 ~]# 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
[root@node1 ~]# 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.
[root@node1 ~]# mke2fs -t ext4 /dev/sdb1
[root@node1 ~]# mount /dev/sdb1 /mnt
[root@node1 ~]# cd /mnt/
[root@node3 ~]# 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
[root@node1 mnt]# cp /etc/issue /mnt/
[root@node1 mnt]# vim /mnt/issue
new line
node2安装配置iSCSI initiator
[root@node2 ~]# yum -y install iscsi-initiator-utils
[root@node2 ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu.com)" > /etc/iscsi/initiatorname.iscsi
[root@node2 ~]# service iscsi start
[root@node2 ~]# service iscsid start
[root@node2 ~]# 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
[root@node2 ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l
[root@node2 ~]# 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
[root@node2 ~]# mount /dev/sdb1 /mnt/
[root@node2 ~]# ls /mnt/
issue lost+found
issue lost+found
[root@node2 ~]# cat /mnt/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
new line
#和node1上添加后的内容一致
[root@node2 ~]# vim /mnt/issue
删除node1添加的new line行
[root@node1 mnt]# cat /mnt/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
new line
#node1上issue显示的还是原来的结果
[root@node1 ~]# umount /mnt
[root@node2 ~]# umount /mnt
解除绑定
1、客户端
#登出
[root@node1 ~]# 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.
#删除
[root@node1 ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete
[root@node2 ~]# 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.
[root@node2 ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete
2、服务端
#删除lun
[root@node3 ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 2
[root@node3 ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 1
删除target
[root@node3 ~]# tgtadm -L iscsi -m target -o delete -t 1
[root@node3 ~]# tgtadm -L iscsi -m target -o show
[root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.153:3260
[root@node1 ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s2.t1 -p 192.168.1.153:3260 -l
[root@node1 ~]# fdisk -l /dev/sd[a-z]
本文出自 “追梦” 博客,请务必保留此出处http://sihua.blog.51cto.com/377227/1861938
原文地址:http://sihua.blog.51cto.com/377227/1861938