RHCE:ISCSI服务端和客户端配置

ISCSI: 基于块的存储

存储接口类型:

DAS:硬盘直接连接到主机上, 基于数据块

Sata sas  fc  ->das->file  system->分区,格式化文件系统

 

NAS:网络附加存储, 基于文件

NFS协议,用自己的文件系统,相当于一个文件服务器

Sata sas  fc  -ethernet ->NAS ->nfs,cifs ->直接访问存储文件

 

SAN: 区域网络存储,ISCSI  基于数据块

Sata sas fc  ->ethernet ->SAN->iscsi->file system->格式化文件系统

 

 

SCSI:小型计算机运行接口

ISCSI:internet 小型计算机运行接口

 

服务端:target 目标  客户端:initiator启动器

 

服务端专有名称详解:

启动器(ISCSI initiator):

为启动器授于一个名称(IQN)

目标(ISCSI target)

有一个名称,可以划多个逻辑单元(LUN),可以有多个目标

ACL(访问控制列表)

配置一个IQN,这个IQN要与服务器的IQN一致,才能连接到服务端,相当于服务端的认证

Discovery(发现)

 

Login(登录)

 

LUN(logic unit number):相关的磁盘分区 ,客户端看到一个磁盘

 

Node(节点)这个节点由IQN来标记

 

Portal(门户) 指定监听的IP地址和端口,默认端口3260

 

TPG(Target Portal Group)特定ISCSI目标将要侦听的接口IP地址和TCP端口的集合

 

IQN格式:

Iqn.YYYY-MM.com.reversed.domain[:optional_string]

Iqn.2017-12.com.linxumysql:server0

Iqn.2017-12.com.linuxmysql:desktop0

 

ISCSI目标 配置:

server上配置iscsi的服务端

Targetcli 既是命令行实用程序,也是一个交互式SHELL

安装targetcli

[root@server ~]# yum install targetcli

Package targetcli-2.1.fb34-1.el7.noarch already installed and latest version

 

进入targetcli交互式shell

[root@server ~]# 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: 0] 给客户端使用的磁盘块(考试内容)

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

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

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

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

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

/>

创建后备存储:

Block-块设备 

Fileio -将一个磁盘上的文件当作块设备

Pscsi-物理scsi

Ramdisk-非永久存储,服务器重启后会丢失,在服务器上的内存中创建一个指定大小的ramdisk设备

 

创建分区命令:

创建的分区或逻辑卷不需要格式化为文件系统,客户端挂载ISCSI的磁盘后再格式化文件系统:

创建逻辑卷类型的磁盘:

/backstores> block/ create block1 /dev/iSCSI_vg/disk1_1v

Created block storage object block1 using /dev/iSCSI_vg/disk1_1v.

创建分区类型的磁盘

/backstores> block/ create block2 /dev/vdb3

Created block storage object block2 using /dev/vdb3.

创建文件类型的磁盘

/backstores> fileio/ create file1 /root/iscsi_file 100M

/root/iscsi_file exists, using its size (104857600 bytes) instead

Created fileio file1 with size 104857600

 

创建目标IQN:

此步骤还将在IQN下面创建一个默认TPG

/iscsi> create#直接运行create,系统将自动创建IQN和一个默认的TPG

Created target iqn.2017-12.com.linuxmysql.com:server

Created TPG 1.

/iscsi> ls

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

  o- iqn.2017-12.com.linuxmysql.com:server...................... [TPGs: 1]

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

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

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

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

 

 

tpg中创建一个ACL以供客户端节点稍后使用

/iscsi> iqn.2017-12.com.linuxmysql.com:server/

/iscsi/iqn.20....5ca9a908aaaf> tpg1/

/iscsi/iqn.20...a908aaaf/tpg1> ls

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

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

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

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

/iscsi/iqn.20...a908aaaf/tpg1> acls/ create

Missing required parameter wwn

/iscsi/iqn.20...a908aaaf/tpg1> acls/ create iqn.2017-12.com.linuxmysql:desktop

Created Node ACL for iqn.2017-12.com.linuxmysql:desktop

/iscsi/iqn.20...a908aaaf/tpg1> ls

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

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

  | o- iqn.2003-01.org.linux-iscsi.server.x8664:sn.server ..................................... [Mapped LUNs: 0]

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

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

说明:

这个ACL条目配置为仅接受来自以iqn.2017-12.com.linuxmysql:desktop作为其启动器IQN的客户端的连接

 

TPG,为每个现有后备存储创建一个LUN,此步骤还将激活每个后备存储,由于TPG存在ACL,因此ACL将自动分配给每个创建的LUN

 

/> cd iscsi/

/iscsi> cd iqn.2017-12.com.linuxmysql.com:server/

/iscsi/iqn.20....5ca9a908aaaf> cd tpg1/

/iscsi/iqn.20...a908aaaf/tpg1> ls

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

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

  | o- iqn.2017-12.com.linuxmysql:desktop ..................................... [Mapped LUNs: 0]

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

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

/iscsi/iqn.20...a908aaaf/tpg1> luns/ create /backstores/block/block1

Created LUN 0.

Created LUN 0->0 mapping in node ACL iqn.2003-01.org.linux-iscsi.server.x8664:sn.server

/iscsi/iqn.20...a908aaaf/tpg1> luns/ create /backstores/block/block2

Created LUN 1.

Created LUN 1->1 mapping in node ACL iqn.2003-01.org.linux-iscsi.server.x8664:sn.server

/iscsi/iqn.20...a908aaaf/tpg1> luns/ create /backstores/fileio/file1

Created LUN 2.

Created LUN 2->2 mapping in node ACL iqn.2003-01.org.linux-iscsi.server.x8664:sn.server

/iscsi/iqn.20...a908aaaf/tpg1> ls

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

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

  | o- iqn.2017-12.com.linuxmysql:desktop ..................................... [Mapped LUNs: 3]

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

  |   o- mapped_lun1 ..................................................... [lun1 block/block2 (rw)]

  |   o- mapped_lun2 ..................................................... [lun2 fileio/file1 (rw)]

  o- luns ............................................................. [LUNs: 3]

  | o- lun0 ........................................[block/block1 (/dev/iSCSI_vg/disk1_1v)]

  | o- lun1 ....................................... [block/block2 (/dev/vdb3)]

  | o- lun2 ........................................ [fileio/file1 (/root/iscsi_file)]

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

说明:

将三个LUN分配给目标意味着,当启动器连接到目标时,客户端将收到三个新的ISCIS磁盘设备

 

TPG中创建一个门户配置以指定侦听IP地址和端口,默认端口为3260

/iscsi/iqn.20...a908aaaf/tpg1>

/iscsi/iqn.20...a908aaaf/tpg1> portals/ create 172.25.0.11

Using default IP port 3260

Created network portal 172.25.0.11:3260.

说明:

如果创建时未指定IP地址,将使用0.0.0.0作为IP,表示允许服务器上定义的所有网络接口上的连接

 

查看整个配置,然后输入exit退出,targetcli退出后将自动保存配置文件。

 

配置文件位置:/etc/target/saveconfig.json

 

将端口3260添加到防火墙放行:

[root@server ~]# firewall-cmd --add-port=3260/tcp --permanent

Success

[root@server ~]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0 eth1 eth2

  sources:

  services: dhcpv6-client dns mountd nfs rpc-bind samba smtp ssh

  ports: 3260/tcp

 

重新启动服务,使配置生效:

[root@server ~]# systemctl  restart target

 

客户端访问ISCIS存储:

desktop上配置iscsi的客户端;

[root@desktop ~]# yum install iscsi-initiator-utils

启动服务:

[root@desktop ~]# systemctl restart iscsi

[root@desktop iscsi]# systemctl restart iscsid

Iscsid服务在配置文件在:/etc/iscsi/目录下的 iscsid.conf

作为iscsi节点,

客户端需要一个唯一的IQN,配置文件位置在/etc/iscsi/initiatorname.iscsi文件中

[root@desktop iscsi]# pwd

/etc/iscsi

[root@desktop iscsi]# cat initiatorname.iscsi

InitiatorName=iqn.2003-01.org.linux-iscsi.server.x8664:sn.server

注意:

这个InitiatorName是服务端ACL的名称

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

  | o- iqn.2017-12.com.linuxmysql.com:server.......................[TPGs: 1]

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

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

  |     | o- iqn.2017-12.com.linuxmysql:desktop ...................[Mapped LUNs: 1]

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

 

Iscsid.conf

包含了在新目标发现期间创建的节点记录的默认设置:(超时,重试参数,身份验证用户名及密码)

[root@desktop iscsi]# ls

initiatorname.iscsi  iscsid.conf

这两个文件修改后要重启服务:systemctl restart iscsid

 

发现目标:

语法:#iscsiadm -m discovery -t sendtargets -p  target_server[:port]

[root@desktop ~]# iscsiadm -m discovery -t sendtargets -p 172.25.0.11

172.25.0.11:3260,1 iqn.2017-12.com.linuxmysql.com:server

[root@desktop iscsi]# iscsiadm -m discovery -t st -p 172.25.0.11

172.25.0.11:3260,1 iqn.2017-12.com.linuxmysql.com:server

 

发现目标的节点记录将写入到/var/lib/iscsi/nodes目录下,用于后续登录:

[root@desktop nodes]# ls

iqn.2017-12.com.linuxmysql.com:server

[root@desktop nodes]# pwd

/var/lib/iscsi/nodes

 

登录iscsi服务器:

[root@desktop iscsi]#

 [root@desktop nodes]# iscsiadm -m node -T iqn.2017-12.com.linuxmysql.com:server -l

Logging in to [iface: default, target: iqn.2017-12.com.linuxmysql.com:server, portal: 172.25.0.11,3260] (multiple)

Login to [iface: default, target: iqn.2017-12.com.linuxmysql.com:server, portal: 172.25.0.11,3260] successful.

 

登录成功后,会在当前系统下一块磁盘:

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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

[root@desktop iscsi]# lsblk

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda      8:0    0   1G  0 disk

vda    253:0    0  10G  0 disk

└─vda1 253:1    0  10G  0 part /

vdb    253:16   0  10G  0 disk

查看UUID:

[root@desktop nodes]# blkid

/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"

/dev/sda: UUID="8be70afa-c176-4c93-9ddc-c113de157402" TYPE="xfs"

 

创建挂载目录:

[root@desktop ~]# mkdir /iscsidisk/

 

永久挂载目录到本地文件系统:

Vim /etc/fstab

UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /                       xfs     defaults        1 1

UUID="8be70afa-c176-4c93-9ddc-c113de157402"  /iscsidisk   xfs   defaults,_netdev  0 0

Mount -a 使用配置文件生效

 

查看ISCSI磁盘信息:

[root@desktop ~]# lsblk

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda      8:0    0   1G  0 disk /iscsidisk

vda    253:0    0  10G  0 disk

└─vda1 253:1    0  10G  0 part /

vdb    253:16   0  10G  0 disk

 

 

显示有关已知目标的信息:

 [root@desktop nodes]# iscsiadm -m node -T iqn.2017-12.com.linuxmysql.com:server

# BEGIN RECORD 6.2.0.873-21

node.name = iqn.2017-12.com.linuxmysql.com:server

node.tpgt = 1

node.startup = automatic

node.leading_login = No

iface.hwaddress = <empty>

iface.ipaddress = <empty>

iface.iscsi_ifacename = default

iface.net_ifacename = <empty>

 

显示有关活动会话的信息

[root@desktop nodes]# iscsiadm -m session

tcp: [2] 172.25.0.11:3260,1 iqn.2017-12.com.linuxmysql.com:server (non-flash)

 

显示有关发现目标的信息:

 iscsiadm -m discovery

172.25.0.11:3260 via sendtargets

 

列出 iscsi服务所识别的目标:

[root@desktop nodes]# iscsiadm -m session -P 3 | grep Attached

Attached SCSI devices:

Attached scsi disk sdaState: running

 

 

注销iscsi的连接,注销后本地将不再显示连接的磁盘

先卸载本地挂载的文件系统:

[root@desktop ~]# umount /iscsidisk/

注销连接:

[root@desktop iscsi]# iscsiadm -m node -T iqn.2017-12.com.linuxmysql.com:server  -p 172.25.0.11 -u

Logging out of session [sid: 1, target: iqn.2017-12.com.linuxmysql.com:server, portal: 172.25.0.11,3260]

Logout of [sid: 1, target: iqn.2017-12.com.linuxmysql.com:server, portal: 172.25.0.11,3260] successful.

删除连接:

[root@desktop iscsi]# iscsiadm -m node -T iqn.2017-12.com.linuxmysql.com:server  -o delete

 

 

通过重启客户端的服务,重新连接iscsi服务端:

[root@desktop iscsi]# systemctl restart iscsi

[root@desktop iscsi]# lsblk

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda      8:0    0   1G  0 disk

vda    253:0    0  10G  0 disk

└─vda1 253:1    0  10G  0 part /

vdb    253:16   0  10G  0 disk

 

 

更新,删除,新增target方法:

Iscsiadm -m node -o [delete|new|update] -T  targetname

删除:

Iscsiadm -m node -o delete  -T  targetname

 

查看ISCSI接节连接的参数值:

[root@desktop nodes]# less iqn.2017-12.com.linuxmysql.com\:server/172.25.0.11\,3260\,1/default

 

 

 

 

 

 

 

 

 

 


YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS