iscsi(共享磁盘)

来源:互联网 发布:mac如何解压rar文件 编辑:程序博客网 时间:2024/05/29 18:45

谈到iSCSI,我能想到的就是存储分为NAS和SAN,NAS与SAN都是在DAS的基础上发展起来的,是新型数据存储模式中的两个主要发展方向。

直接存取 (direct-attached storage):例如本机上面的磁碟,就是直接存取設備;存储网络 (SAN):来自区网內的其他存储设备提供的磁碟;网络连接式存储 (NAS):來自 NAS 提供的档案系統,只能立即使用,不可进行格式化。

这里写图片描述

从上图中,我们可以发现在一般的主机环境下,磁碟装置 (SATA, SAS, FC) 可以透过主机的界面 (DAS) 來直接进行档案系統的建立 (mkfs 进行格式化),如果想要使用外部的磁碟,那可以透过 SAN (內含多个磁碟的设备),然后透过 iSCSI 等介面来连线, 当然,还是得要进行格式化等动作 (假设这个 SAN 尚未被使用時)。最后,如果是 NAS 的条件下,那么 NAS 必须要先透过自己的作业系统將将磁碟装置进行档案系統的建立后,再以 NFS/CIFS 等方式來提供其他主机挂载使用。

接下来,网络服务器、用戶端系統、NAS 与 SAN 的角色在区域网里面又是如何呢?(DAS 是每部主机內部的磁碟,即底下图示中的圆柱体):
这里写图片描述

NAS 可以使用自己的磁碟,也能够透过光纤或以太网取得 SAN 所提供的磁碟来制作成为存储网络,提供其他人的使用。 Server 可以透过NFS/CIFS 等方式取得 NAS 的档案系統,当然也能夠直接存取 SAN 的磁碟。用戶端主要则是透过存储网络, 并且直接使用 Server 提供的网络资源 (如 FTP, WWW, mail 等等)。

iscsi这个架构主要将存储装置使用的主机分为两个部分,分別是:

  • iSCSI target:就是存储设备端,存放磁碟或RAID的设备,目前也能够将Linux主机模拟成ISCSI target 了!目的在提供其他主机使用的『磁碟』

  • iSCSI initiator:就是能够使用 target 的用戶端,通常是客服器。 也就是说,想要连接到 iSCSI target的客户端,也必须要安装 iSCSI initiator 的相关功能后才能够使用 iSCSI target 提供的磁碟就是了。

iscsi-server 172.25.254.138     target
iscsi-client 172.25.254.238     initiator

基本服务配置

server:

1.创建磁盘vdb1
fdisk /dev/vdb
2.安装iSCSI目标软件包:
yum install targetcli -y
3.进入iSCSI目标交互式配置模式:
[root@iscsi-server ~]# targetcli
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 ppp:storage1 /dev/vdb1
Created block storage object ppp:storage1 using /dev/vdb1.
/> ls
o- / ……………………………………………………………………. […]
o- backstores ………………………………………………………….. […]
| o- block ……………………………………………….. [Storage Objects: 1]
| | o- ppp: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
Created target iqn.2017-08.com.example:storage1.
Created TPG 1.
/> ls
o- / ……………………………………………………………………. […]
o- backstores ………………………………………………………….. […]
| o- block ……………………………………………….. [Storage Objects: 1]
| | o- ppp: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.2017-08.com.example:storage1/tpg1/luns create /backstores/block/ppp:storage1
Created LUN 0.
/> ls
o- / ……………………………………………………………………. […]
o- backstores ………………………………………………………….. […]
| o- block ……………………………………………….. [Storage Objects: 1]
| | o- ppp:storage1 …………………….. [/dev/vdb1 (3.0GiB) 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-08.com.example:storage1 ………………………………… [TPGs: 1]
| o- tpg1 …………………………………………….. [no-gen-acls, no-auth]
| o- acls ………………………………………………………. [ACLs: 0]
| o- luns ………………………………………………………. [LUNs: 1]
| | o- lun0 ………………………………… [block/ppp:storage1 (/dev/vdb1)]
| o- portals …………………………………………………. [Portals: 0]
o- loopback ……………………………………………………… [Targets: 0]
/> /iscsi/iqn.2017-08.com.example:storage1/tpg1/acls create
iqn.2017-08.com.example:storage1key
Created Node ACL for iqn.2017-08.com.example:storage1key
Created mapped LUN 0.
/> /iscsi/iqn.2017-08.com.example:storage1/tpg1/portals create 172.25.254.138
Using default IP port 3260
Created network portal 172.25.254.138:3260.
/> ls
o- / ……………………………………………………………………. […]
o- backstores ………………………………………………………….. […]
| o- block ……………………………………………….. [Storage Objects: 1]
| | o- ppp:storage1 …………………….. [/dev/vdb1 (3.0GiB) 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-08.com.example:storage1 ………………………………… [TPGs: 1]
| o- tpg1 …………………………………………….. [no-gen-acls, no-auth]
| o- acls ………………………………………………………. [ACLs: 1]
| | o- iqn.2017-08.com.example:storage1key ………………….. [Mapped LUNs: 1]
| | o- mapped_lun0 ………………………….. [lun0 block/ppp:storage1 (rw)]
| o- luns ………………………………………………………. [LUNs: 1]
| | o- lun0 ………………………………… [block/ppp:storage1 (/dev/vdb1)]
| o- portals …………………………………………………. [Portals: 1]
| o- 172.25.254.138: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

systemctl stop firewalld.service

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

client
1.安装iSCSI发起端软件包:
yum install iscsi-initiator-utils -y
2.vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2017-08.com.example:storage1key##key要与之前创建的名字一样

3.重起服务
systemctl restart iscsid.service
systemctl restart iscsi
4.查找iSCSI服务器所提供的iSCSI目标(目标门户)
iscsiadm -m discovery -t st -p 172.25.254.138
登录服务器上的一个或多个iscsi目标
iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.138 -l
会出现一个新的磁盘,然后格式化,挂载就可以了
那么如何查看server端共享的盘呢?
yum install tree -y
[root@iscsi-client ~]# tree -C /var/lib/iscsi/

/var/lib/iscsi/|-- ifaces|-- isns|-- nodes|   `-- iqn.2017-08.com.example:storage1|       `-- 172.25.254.138,3260,1|           `-- default|-- send_targets|   `-- 172.25.254.138,3260|       |-- iqn.2017-08.com.example:storage1,172.25.254.138,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-08.com.example:storage1/172.25.254.138,3260,1|       `-- st_config|-- slp`-- static

如何删除节点呢?
临时:iscsiadm -m node -T iqn.2017-08.com.example:storage1 -u
永久:iscsiadm -m node -T iqn.2017-08.com.example:storage1 -o delete

server端如何删除刚才创建的一系列东西?
[root@iscsi-server ~]# targetcli
/> clearconfig confirm=True

现在已经把之前创建的所有东西都删除了,我们来创建LVM

iscsi上的LVM

server:

fdisk /dev/vdb
将之前创建的vdb1修改标签8e

[root@iscsi-server ~]# pvcreate /dev/vdb1  Physical volume "/dev/vdb1" successfully created[root@iscsi-server ~]# pvs  PV         VG   Fmt  Attr PSize PFree  /dev/vdb1       lvm2 a--  3.00g 3.00g[root@iscsi-server ~]# vgcreate iscsivg0 /dev/vdb1  Volume group "iscsivg0" successfully created[root@iscsi-server ~]# vgs  VG       #PV #LV #SN Attr   VSize VFree  iscsivg0   1   0   0 wz--n- 3.00g 3.00g[root@iscsi-server ~]# lvcreate -L 1000M -n iscsilv0 iscsivg0   Logical volume "iscsilv0" created[root@iscsi-server ~]# lvs  LV       VG       Attr       LSize    Pool Origin Data%  Move Log Cpy%Sync Convert  iscsilv0 iscsivg0 -wi-a----- 1000.00m                                  

[root@iscsi-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]
/> /backstores/block create ppp:storage1 /dev/iscsivg0/iscsilv0
Created block storage object ppp:storage1 using /dev/iscsivg0/iscsilv0.
/> /iscsi create iqn.2017-08.com.example:storage1
Created target iqn.2017-08.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2017-08.com.example:storage1/tpg1/luns create /backstores/block/ppp:storage1
Created LUN 0.
/> /iscsi/iqn.2017-08.com.example:storage1/tpg1/acls create
iqn.2017-08.com.example:storage1key
Created Node ACL for iqn.2017-08.com.example:storage1key
Created mapped LUN 0.
/> /iscsi/iqn.2017-08.com.example:storage1/tpg1/portals create 172.25.254.138
Using default IP port 3260
Created network portal 172.25.254.138:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

client端跟之前的配置一样
systemctl restart iscsid.service
systemctl restart iscsi
发现设备:
iscsiadm -m discovery -t st -p 172.25.254.138
连接节点:
iscsiadm -m node -T iqn.2017-08.com.example:storage1 -p 172.25.254.138 -l

若要对LVM进行extend或者reduce要安装插件,这个在之后的企业部分会写。

原创粉丝点击