码迷,mamicode.com
首页 > 其他好文 > 详细

ISCSI测试

时间:2017-10-06 17:33:25      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:b16   cal   iscsi   nim   fst   portal   lock   groups   bytes   

Initiator为应用客户端,服务端Target包括设备服务器端和队列管理两部分。
服务端两种共享方式:
1、在服务端共享分区
2、在服务端以文件方式作为共享设备共享出来

实验1-磁盘方式iscsi

在RHEL1()192.168.100.1)上:
新建一个4G的分区/dev/sdb1作为共享设备

[root@rhel1 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x1a638cd0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     8390655     4194304   83  Linux

服务端安装targetcli
yum install targetcli

配置防火墙
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd –reload

创建共享设备

[root@rhel1 ~]# targetcli
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type ‘help‘.

/> ls
o- / .................................................................................................................... [...]
   o- backstores ......................................................................................................... [...]
   | o- block ............................................................................................. [Storage Objects: 0]
   | o- fileio ............................................................................................ [Storage Objects: 0]
   | o- pscsi ............................................................................................. [Storage Objects: 0]
   | o- ramdisk ........................................................................................... [Storage Objects: 0]
   o- iscsi ....................................................................................................... [Targets: 0]
   o- loopback .................................................................................................... [Targets: 0]
/> /backstores/block create mydisk1 /dev/sdb1
Created block storage object mydisk1 using /dev/sdb1.
/> /iscsi create iqn.2017-10.com.rusky:rhel1ShareDisk1
Created target iqn.2017-10.com.rusky:rhel1sharedisk1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/acls create iqn.2017-10.com.rusky:rhel2
Created Node ACL for iqn.2017-10.com.rusky:rhel2
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/acls create iqn.2017-10.com.rusky:rhel3
Created Node ACL for iqn.2017-10.com.rusky:rhel3
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/luns create /backstores/block/mydisk1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-10.com.rusky:rhel3
Created LUN 0->0 mapping in node ACL iqn.2017-10.com.rusky:rhel2
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/portals create 192.168.100.1 3260
Using default IP port 3260
Could not create NetworkPortal in configFS
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/portals create 192.168.100.1 3260
Using default IP port 3260
Could not create NetworkPortal in configFS
/> iscsi/iqn.2017-10.com.rusky:rhel1sharedisk1/tpg1/portals create 192.168.100.1 3260
Using default IP port 3260
Created network portal 192.168.100.1:3260.
/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@rhel1 ~]# systemctl restart target.service
[root@rhel1 ~]# systemctl enable target.service
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@rhel1 ~]# targetcli
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type ‘help‘.

/> ls
o- / ......................................................................................................................... [...]
   o- backstores .............................................................................................................. [...]
   | o- block .................................................................................................. [Storage Objects: 1]
   | | o- mydisk1 ........................................................................ [/dev/sdb1 (0 bytes) write-thru activated]
   | |   o- alua ................................................................................................... [ALUA Groups: 1]
   | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
   | o- fileio ................................................................................................. [Storage Objects: 0]
   | o- pscsi .................................................................................................. [Storage Objects: 0]
   | o- ramdisk ................................................................................................ [Storage Objects: 0]
   o- iscsi ............................................................................................................ [Targets: 1]
   | o- iqn.2017-10.com.rusky:rhel1sharedisk1 ............................................................................. [TPGs: 1]
   |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
   |     o- acls .......................................................................................................... [ACLs: 2]
   |     | o- iqn.2017-10.com.rusky:rhel2 .......................................................................... [Mapped LUNs: 1]
   |     | | o- mapped_lun0 ............................................................................... [lun0 block/mydisk1 (rw)]
   |     | o- iqn.2017-10.com.rusky:rhel3 .......................................................................... [Mapped LUNs: 1]
   |     |   o- mapped_lun0 ............................................................................... [lun0 block/mydisk1 (rw)]
   |     o- luns .......................................................................................................... [LUNs: 1]
   |     | o- lun0 ................................................................... [block/mydisk1 (/dev/sdb1) (default_tg_pt_gp)]
   |     o- portals .................................................................................................... [Portals: 1]
   |       o- 192.168.100.1:3260 ............................................................................................... [OK]
   o- loopback ......................................................................................................... [Targets: 0]
/>

在RHEL2上
yum install -y iscsi-initiator-utils    #默认已安装
vim /etc/iscsi/initiatorname.iscsi    #必须先修改再发现target
InitiatorName=iqn.2015-08.com.qin:RHEL2    #修改
systemctl restart iscsi
systemctl enable iscsi

iscsiadm --mode discoverydb --type sendtargets --portal 192.168.100.1 --discover
#会发现RHEL1上的iqn.2015-08.com.qin:RHEL1disk1
iscsiadm --mode node --targetname iqn.2015-08.com.qin:RHEL1disk1 --portal 192.168.100.1:3260 --login
fdisk -l    #发现/dev/sdb
fdisk /dev/sdb    #分出/dev/sdb1
mkfs.xfs /dev/sdb1
mkdir /mnt/mydisk1
blkid        #找出/dev/sdb1的UUID
vim /etc/fstab
UUID="77b46d01-6c5f-4bac-8fb6-eb6296ebb32a"     /mnt/mydisk1    xfs     defaults,_netdev        0 0    #不加_netdev开机会卡住
systemctl reboot    #重启自动挂载
实验-文件方式iscsi
在RHEL1上
dd if=/dev/zero of=/iscsifile bs=1M count=2048

targetcli
/> ls
/> /backstores/fileio create mydisk2 /iscsifile
/> iscsi/ create iqn.2015-08.com.qin:RHEL1disk2
/> iscsi/iqn.2015-08.com.qin:RHEL1disk2/tpg1/acls create iqn.2015-08.com.qin:RHEL2
/> iscsi/iqn.2015-08.com.qin:RHEL1disk2/tpg1/luns create /backstores/fileio/mydisk2
/> iscsi/iqn.2015-08.com.qin:RHEL1disk2/tpg1/portals create 192.168.100.1 3260
/> saveconfig
/> exit
systemctl restart target

在RHEL2上
iscsiadm --mode discoverydb --type sendtargets --portal 192.168.100.1 --discover
#会发现RHEL1上的两个共享磁盘
iscsiadm --mode node --targetname iqn.2015-08.com.qin:RHEL1disk2 --portal 192.168.100.1:3260 --login
fdisk -l    #发现/dev/sdc
fdisk /dev/sdc    #分出/dev/sdc1
mkfs.xfs /dev/sdc1
mkdir /mnt/mydisk2
blkid        #找出/dev/sdc1的UUID
vim /etc/fstab
UUID="c56a71c0-d17c-4ff2-80f6-8be43b1663ea"     /mnt/mydisk2    xfs     defaults,_netdev        0 0
systemctl reboot    #重启自动挂载
iscsiadm -m session -P[123]        #查看iscsi信息,,大写P,3最详细
实验-iscsi开关顺序
关机顺序
RHEL2先关 RHEL1再关
开机顺序
RHEL1先开 RHEL2再开
实验-iscsi的删除
在RHEL2上
umount /mnt/mydisk1
umount /mnt/mydisk2
删除fstab相关内容
iscsiadm --mode node --targetname iqn.2015-08.com.qin:RHEL1disk1 --portal 192.168.100.1:3260 --logout
iscsiadm --mode node --targetname iqn.2015-08.com.qin:RHEL1disk2 --portal 192.168.100.1:3260 --logout
iscsiadm -m node -T iqn.2015-08.com.qin:RHEL1disk1 -p 192.168.100.1 -o delete
iscsiadm -m node -T iqn.2015-08.com.qin:RHEL1disk2 -p 192.168.100.1 -o delete
fdisk -l    #已经看不到/dev/sdb1和/dev/sdc1了

或者
vim  /etc/iscsi/iscsid.conf
node.startup = manual        #修改,今后将不会自动挂载



dd if=/dev/zero of=/isciffile bs=1M count=2048

ISCSI测试

标签:b16   cal   iscsi   nim   fst   portal   lock   groups   bytes   

原文地址:http://www.cnblogs.com/rusking/p/7631772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!