1. 服务端配置
实验环境系统版本:
CentOS Linux release 7.3.1611 (Core)
1) 安装软件包
yum -y install targetcli
2) 创建要输出的iscsi存储
可输出的设备有如下几种:
a、lvm卷设备;
b、由文件组成的块设备(经过tgtimg工具处理过的);
c、单一的分区;
d、整个磁盘;
e、RAID组成的卷设备;
这里准备了一个lvm逻辑卷,如下:
[root@dengqp03 conf.d]# lvdisplay --- Logical volume --- LV Path /dev/vg_dengqp03/LogVol01 LV Name LogVol01 VG Name vg_dengqp03 LV UUID wK1tx8-98Eo-wXsN-TMdU-0yl8-8okh-7iiQuo LV Write Access read/write LV Creation host, time dengqp03, 2016-04-19 03:43:00 -0400 LV Status available # open 1 LV Size 10.84 GiB Current LE 2774 Segments 4 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
3) 查看客户端InitiatorName 用户创建acl
[root@dengqp-test ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:f958e9b53119
4) 使用targetcli配置存储
[root@dengqp03 conf.d]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb41 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 mydata /dev/mapper/vg_dengqp03-LogVol01 //创建共享块存储 Created block storage object mydata using /dev/mapper/vg_dengqp03-LogVol01. /> cd iscsi /iscsi> create iqn.2017-03.com.dengqp:server0 //创建一个target Created target iqn.2017-03.com.dengqp:server0. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi> ls o- iscsi .............................................................................................................. [Targets: 1] o- iqn.2017-03.com.dengqp:server0 ...................................................................................... [TPGs: 1] o- tpg1 ................................................................................................. [no-gen-acls, no-auth] o- acls ............................................................................................................ [ACLs: 0] o- luns ............................................................................................................ [LUNs: 0] o- portals ...................................................................................................... [Portals: 1] o- 0.0.0.0:3260 ....................................................................................................... [OK] /iscsi> cd iqn.2017-03.com.dengqp:server0/tpg1/ /iscsi/iqn.20...:server0/tpg1> cd portals/ /iscsi/iqn.20.../tpg1/portals> delete ip_address=0.0.0.0 ip_port=3260 Deleted network portal 0.0.0.0:3260 /iscsi/iqn.20.../tpg1/portals> create 10.20.2.237 //创建共享地址,端口默认为3260 Using default IP port 3260 Created network portal 10.20.2.237:3260. /iscsi/iqn.20.../tpg1/portals> cd .. /iscsi/iqn.20...:server0/tpg1> luns/ create /backstores/block/mydata //在target上面创建一个lun Created LUN 0. /iscsi/iqn.20...:server0/tpg1> acls/ create iqn.1994-05.com.redhat:f958e9b53119 //acls目录创建共享密码 Created Node ACL for iqn.1994-05.com.redhat:f958e9b53119 Created mapped LUN 0. /iscsi/iqn.20...engqp:server0> cd / /> ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 1] | | o- mydata .................................................. [/dev/mapper/vg_dengqp03-LogVol01 (10.8GiB) write-thru activated] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 1] | o- iqn.2017-03.com.dengqp:server0 .................................................................................... [TPGs: 1] | o- tpg1 ............................................................................................... [no-gen-acls, no-auth] | o- acls .......................................................................................................... [ACLs: 1] | | o- iqn.1994-05.com.redhat:f958e9b53119 .................................................................. [Mapped LUNs: 1] | | o- mapped_lun0 ................................................................................ [lun0 block/mydata (rw)] | o- luns .......................................................................................................... [LUNs: 1] | | o- lun0 ................................................................ [block/mydata (/dev/mapper/vg_dengqp03-LogVol01)] | o- portals .................................................................................................... [Portals: 1] | o- 10.20.2.237:3260 ................................................................................................. [OK] o- loopback ......................................................................................................... [Targets: 0] /> 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
5) 启动target服务
[root@dengqp03 conf.d]# systemctl enable target Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service. [root@dengqp03 conf.d]# systemctl start target [root@dengqp03 conf.d]# systemctl status target ● target.service - Restore LIO kernel target configuration Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled) Active: active (exited) since Mon 2017-03-27 03:33:22 EDT; 4s ago Process: 14646 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS) Main PID: 14646 (code=exited, status=0/SUCCESS) Mar 27 03:33:22 dengqp03 systemd[1]: Starting Restore LIO kernel target configuration... Mar 27 03:33:22 dengqp03 systemd[1]: Started Restore LIO kernel target configuration.
2. 客户端配置
实验环境系统版本:
CentOS release 6.7 (Final)
1) man iscsiadm 查看帮助中的examples
Discover targets at a given IP address:
iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover
Login, must use a node record id found by the discovery:
iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --login
2) 发现服务器端输出的设备
[root@dengqp-test samba]# iscsiadm --mode discoverydb --type sendtargets --portal 10.20.2.237 --discover Starting iscsid: [ OK ] 10.20.2.237:3260,1 iqn.2017-03.com.dengqp:server0
3) 链接设备
[root@dengqp-test samba]# iscsiadm --mode node --targetname iqn.2017-03.com.dengqp:server0 --portal 10.20.2.237:3260 --login Logging in to [iface: default, target: iqn.2017-03.com.dengqp:server0, portal: 10.20.2.237,3260] (multiple) Login to [iface: default, target: iqn.2017-03.com.dengqp:server0, portal: 10.20.2.237,3260] successful.
4) 查看验证设备是否已识别
[root@dengqp-test samba]# fdisk -l 如下为发现的网络存储 Disk /dev/sdb: 11.6 GB, 11634×××96 bytes 64 heads, 32 sectors/track, 11096 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes Disk identifier: 0x00000000
5) 创建iscsi挂载点并挂载网络存储
[root@dengqp-test /]# mkdir iscsi [root@dengqp-test /]# mount /dev/sdb /iscsi/ //如果挂载出现如下错误,需要使用mkfs格式化后再进行挂载 mount: you must specify the filesystem type [root@dengqp-test /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sdb 11G 4.1G 6.0G 41% /iscsi