.iscsi介绍

SCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。

二.设置iscsi的共享设备(共享磁盘中的一个分区)

****服务器

1.服务端修改主机名,关闭防火墙   

   hostnamectl set-hostname iscsi-server.example.com

   systemctl stop firewalld

2.在服务端添加一块大小5G的磁盘

   fdisk -l           查看服务器主机的硬盘

   fdisk /dev/vdb     给磁盘/dev/vdb 创建一个分区,划分一个3G的硬盘/dev/vdb1

   partprobe        同步分区表

3. 安装服务,并且设置开机自启

   yum search iscsi      查找软件

   yum install targetcli -y    安装iscsi目标交互式配置服务 targetcli

   systemctl start target   开启服务

   systemctl enable target  设置开机自动启动

4.配置iscsi服务

  targetcli 进入iscsi目标交互配置模式

  /> 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 westos:storage1 /dev/vdb1      (1) 在/backstores/block 创建westos:storage1,以/dev/vdb1设备iscsi_storage为存储

Created block storage object westos:storage1 using /dev/vdb1.

/> ls

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

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

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

  | | o- westos:storage1 ........... [/dev/vdb1 (3.0GiB) write-thru deactivated]

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

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

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

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

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

/> /iscsi create iqn.2017-08.com.example:storage1       (2)创建iscsi限定名称,发起端与目标需要唯一名称进行标识

Created target iqn.2017-08.com.example:storage1.

Created TPG 1.

/> ls

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

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

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

  | | o- westos:storage1 ........... [/dev/vdb1 (3.0GiB) 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-08.com.example:storage1 .............................. [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.20...storage1/tpg1> luns/ create /backstores/block/westos:storage1        (3) 创建逻辑单元号

Created LUN 0.

/iscsi/iqn.20...storage1/tpg1> acls/ create iqn.2017-08.com.example:storage1key       (4)创建访问控制列表storage1key

Created Node ACL for iqn.2017-08.com.example:storage1key                  

Created mapped LUN 0.

/iscsi/iqn.20...storage1/tpg1> portals/ create 172.25.254.224       

Using default IP port 3260

Created network portal 172.25.254.224:3260.           (5) 使用172.25.254.224的3260端口访问

/iscsi/iqn.20...storage1/tpg1> exit                   (6)退出,完成配置

Global pref auto_save_on_exit=true

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

Configuration saved to /etc/target/saveconfig.json

 

 

 

客户端

1.修改主机名,关闭防火墙服务

  hostnamectl set-hostname iscsi-client.example.com

  systemctl stop firewalld

2.安装iscsi客户端

  yum search iscsi

  yum install iscsi-initiator-utils.x86_64 -y

3.设置发起端的lQN

  vim /etc/iscsi/initiatorname.isxsi

  InitiatorName=iqn.2017-08.com.example:storage1key

4.重启iscsi服务,并且查找iscsi 172.25.254.224服务器提供的iscsi目标

 [root@client ~]# systemctl restart iscsi

 [root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.224

  172.25.254.224:3260,1 iqn.2017-08.com.example:storage1

5.登录服务器上的一个iscsi目标,并且查看磁盘设备

  iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -l

  fdisk -l

  可以看到/dev/sda 就是服务端共享出来的磁盘

6.对磁盘进行分区,格式化,挂载

  (1) fdisk /dev/sda   对磁盘进行分区

       partprobe        同步分区表

  (2)mkfs.xfs /dev/sda1   格式化分区

  (3)mount /dev/sda1 /mnt/  挂载分区

7.删除iscsi共享设备

客户端:

    umount /mnt/   卸载

    yum install tree.x86_64 -y     tree软件可以查看本机上的iscsi信息

    [root@client ~]# tree -c /var/lib/iscsi/  (查看iscsi信息)

/var/lib/iscsi/

├── nodes

   └── iqn.2017-08.com.example:storage1

       └── 172.25.254.224,3260,1

           └── default

├── send_targets

   └── 172.25.254.224,3260

       ├── iqn.2017-08.com.example:storage1,172.25.254.224,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-08.com.example:storage1/172.25.254.224,3260,1

       └── st_config

├── ifaces

├── isns

├── slp

└── static

 

    iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -u     登出iscsi目标,暂时断开连接

    iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -o delete  删除iscsi目标的本地记录,以永久断开连接

    [root@client ~]# tree -c /var/lib/iscsi/          (再次查看iscsi信息)

/var/lib/iscsi/

├── nodes

├── send_targets

   └── 172.25.254.224,3260

       └── st_config

├── ifaces

├── isns

├── slp

└── static

 

7 directories, 1 file

 

 

服务端:

[root@iscsi-server ~]# targetcli   进入iscsi目标交互配置模式

targetcli shell version 2.1.fb34

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

 

/> clearconfig confirm=True      清除iscsi的所有配置信息

All configuration cleared

/> 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]

/>

 

 

 三.设置iscsi LVM共享设备

服务端:

   1.将之前的/dev/vdb1分区创建成vg分区iscisvg

     vgcreate iscsivg /dev/vdb1

     vgdisplay      查看vg设备   

   2.将全部的iscsivg创建为lv0,并查看状态

     lvcreate -l 1279 -n iscsilv0 iscsivg

     ll /dev/iscsivg/iscsilv0    查看iscsilv0的信息

   3.配置iscsi服务

     targetcli 进入iscsi目标交互配置模式

  /> /backstores/block create westos:storage1 /dev/iscsivg/iscsilv0

  /> /iscsi create iqn.2017-08.com.example:storage1

  />/iscsi/iqn.2017.08.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1

  />/iscsi/iqn.2017.08.com.example:storage1/tpg1/acls create iqn.2017-08.com.example:storage1key

  />/iscsi/iqn.2017.08.com.example:storage1/tpg1/portals create 172.25.254.224

  /iscsi/iqn.20...storage1/tpg1> exit

客户端:   

  1.设置发起端的lQN

  vim /etc/iscsi/initiatorname.isxsi

  InitiatorName=iqn.2017-08.com.example:storage1key

  iscsiadm -m discovery -t st -p 172.25.254.224       查×××器共享出来的iscsi目标

  iscsi -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -l    登录172.25.254.224服务器上的一个iscsi目标

  2.查看新设备

  fdisk -l   查看磁盘设备

  /dev/sda  即为服务端所共享出来的磁盘

服务端:

  1.在服务器上添加一块新的1G硬盘/dev/vdb2,将分区修改为lvm类型

    fdisk /dev/vdb  给磁盘创建新的分区

    partprobe      同步分区表

  2.增加1G的vg,并且将lv增加到3500M

    vgextend iscsivg /dev/vdb2

    vgdisplay

    lvextend -L 3500M /dev/iscsivg/iscsilv0

客户端:

  1.取消在添加服务器的一个iscsi目标

  iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -u

  2.重新启动iscsi,并且重新登入172.25.254.224的服务器上的一个iscsi目标

   iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.224 -l

  3.查看更新后的设备/dev/sda

    fdisk -l