iSCSI概念

iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令。iSCSI限定名称用于确定发起端和目标,并采用iqn.yyyy-mm.{reversedomain}:label的格式。默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文。

 iSCSI发起端:需要访问原始SAN存储的客户端。

 iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”

 iSCSI目标门户:通过网络向发起端提供目标的服务器。

 

IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,最好的做法是使用一个在Internet上可能独一无二的名称。

 

1.

iscsi是直接对设备进行共享的服务

 

2.启动iscsi共享设备

server端:

 

1)实验前在服务端建立lvm设备

[root@server13 ~]# fdisk /dev/vdb##建立lvm设备

n→p→回车→回车→+1000M→p→t→8e→p→wq

 

[root@server13 ~]# partprobe

[root@server13 ~]# pvcreate /dev/vdb1##共享一个lv

  Physical volume "/dev/vdb1" successfully created

[root@server13 ~]# vgcreate vg0 /dev/vdb1

  Volume group "vg0" successfully created

[root@server13 ~]# vgdisplay

[root@server13 ~]# lvcreate -l 249 -n iscsi_storage vg0

  Logical volume "iscsi_storage" created

 

测试:

[root@server13 ~]# lvs##lvm设备的成功建立

  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert

  iscsi_storage vg0  -wi-a----- 996.00m                                           

 

2)服务的安装与开启

[root@server13 ~]# yum install targetcli.noarch ##安装iSCSI目标软件包

[root@server13 ~]# systemctl enable target.service ##启动服务

ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

[root@server13 ~]# systemctl start  target.service

[root@server13 ~]# systemctl stop firewalld.service

 

 

3)服务端的配置

[root@server13 ~]# targetcli ##进入iSCSI目标交互式配置模式

Warning: Could not load preferences file /root/.targetcli/prefs.bin.

targetcli shell version 2.1.fb34

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 server1storage /dev/vg0/iscsi_storage    ##和逻辑卷建立联系,把/dev/vg0/iscsi_storage用server1storage表示

Created block storage object server1storage using /dev/vg0/iscsi_storage.

/> /iscsi create iqn.2017-06.com.example:strage1    ##创建iqn服务的名称(每个发起端和目标需要唯一名称进行标识)

Created target iqn.2017-06.com.example:strage1.

Created TPG 1.

/> ls

o- / ....................................................... [...]

  o- backstores ............................................ [...]

  | o- block ................................ [Storage Objects: 1]

  | | o- server1storage  [/dev/vg0/iscsi_storage (996.0MiB) write-thru deactivated]

  | o- fileio ............................... [Storage Objects: 0]

  | o- pscsi ................................ [Storage Objects: 0]

  | o- ramdisk .............................. [Storage Objects: 0]

  o- iscsi .......................................... [Targets: 1]

  | o- iqn.2017-06.com.example:strage1 ................. [TPGs: 1]

  |   o- tpg1 ............................. [no-gen-acls, no-auth]

  |     o- acls ........................................ [ACLs: 0]

  |     o- luns ........................................ [LUNs: 0]

  |     o- portals .................................. [Portals: 0]

  o- loopback ....................................... [Targets: 0]

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage     ##创建逻辑单元号

Created LUN 0.

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey    ##创建访问控制列表

Created Node ACL for iqn.2017-06.com.example:server1storagekey

Created mapped LUN 0.

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.13.11    ##加密(默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文)

Using default IP port 3260

Created network portal 172.25.13.11:3260.

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

 

查看:

[root@server13 ~]# targetcli

targetcli shell version 2.1.fb34

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

 

/> ls

o- / ....................................................... [...]

  o- backstores ............................................ [...]

  | o- block ................................ [Storage Objects: 1]

  | | o- server1storage  [/dev/vg0/iscsi_storage (996.0MiB) 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-06.com.example:strage1 ................. [TPGs: 1]

  |   o- tpg1 ............................. [no-gen-acls, no-auth]

  |     o- acls ........................................ [ACLs: 1]

  |     | o- iqn.2017-06.com.example:server1storagekey  [Mapped LUNs: 1]

  |     |   o- mapped_lun0 ...... [lun0 block/server1storage (rw)]

  |     o- luns ........................................ [LUNs: 1]

  |     | o- lun0  [block/server1storage (/dev/vg0/iscsi_storage)]

  |     o- portals .................................. [Portals: 1]

  |       o- 172.25.13.11:3260 .............................. [OK]

  o- loopback ....................................... [Targets: 0]

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

  

 

 

在客户端连接:

[root@desktop13 ~]# vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2017-06.com.example:server1storagekey

 

[root@desktop13 ~]# systemctl restart iscsi

[root@desktop13 ~]# fdisk -l

 

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    20970332    10484142+  83  Linux

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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

 

[root@desktop13 ~]# iscsiadm -m discovery -t st -p 172.25.13.11    ##查找iscsi服务器所提供的iscsi目标

172.25.13.11:3260,1 iqn.2017-06.com.example:strage1

[root@desktop13 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -l    ##登录服务器上的iscsi目标  

Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] (multiple)

Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] successful.

 

 

测试:

[root@desktop13 ~]# fdisk -l    ##客户端上出现一个新硬盘设备

 

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    20970332    10484142+  83  Linux

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 4194304 bytes

Disk label type: dos

Disk identifier: 0xfe173449

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1            8192     2039807     1015808   83  Linux

 

 

 

 

3.自动挂载

 

[root@desktop13 ~]# vim /etc/fstab

 10 UUID=2da90fa4-582e-4c16-863a-bd6d83587e8f /mnt xfs defaults,_netdev 0 0

##_netdev表示开机挂载之前先启动网络服务 


4.删除

[root@desktop13 ~]# umount /mnt/

[root@desktop13 ~]# tree -C /var/lib/iscsi//var/lib/iscsi/

├── ifaces

├── isns

├── nodes

   └── iqn.2017-06.com.example:strage1

       └── 172.25.13.11,3260,1

           └── default

├── send_targets

   └── 172.25.13.11,3260

       ├── iqn.2017-06.com.example:strage1,172.25.13.11,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:strage1/172.25.13.11,3260,1

       └── st_config

├── slp

└── static

 

10 directories, 2 files

 

[root@desktop13 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -u    ## 登出iSCSI目标,以暂时断开连接

Logging out of session [sid: 1, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260]

Logout of [sid: 1, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] successful.

[root@desktop13 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -o delete     ## 删除iSCSI目标的本地记录,以永久断开连接  



在服务端删除:

[root@server13 ~]# targetcli

targetcli shell version 2.1.fb34

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

 

/> clearconfig confirm=True

All configuration cleared

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

 

测试:

[root@desktop13 ~]# tree -C /var/lib/iscsi//var/lib/iscsi/

├── ifaces

├── isns

├── nodes

├── send_targets

   └── 172.25.13.11,3260

       └── st_config

├── slp

└── static