概述:
看到iscsi的时候大家是不是很熟悉呀,有一种硬盘技术叫scsi(small computer system interface),而且是服务器常使用的磁盘技术;iscsi(internet small computer system interface)这个i就是网络的意思是一种新型的存储技术,将scsi技术与以太网结合起来,使服务器可与使用IP网络的储存装置互相交换资料。
1.iscsi服务端的配置
下载iscsi管理软件targetcli
[root@localhost mnt]# yum install targetcli
选择一个空闲的
磁盘分区作为网络上共享的磁盘。
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 label type: dos
Disk identifier: 0x206619e5
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux
打开管理软件的shell
[root@localhost mnt]# 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]
使用ls命令可以看到各部分文件的状态
- bookmarks action [bookmark]
- cd [path]
- clearconfig [confirm]
- exit
- get [group] [parameter...]
- help [topic]
- ls [path] [depth]
- pwd
- refresh
- restoreconfig [savefile] [clear_existing]
- saveconfig [savefile]
- sessions [action] [sid]
- set [group] [parameter=value...]
- status
- version
使用help可以查看可以使用的命令。
接下来可以进行分享配置了
/> /backstores/block create mo:storage1 /dev/vdb1
Created block storage object mo:storage1 using /dev/vdb1.
将本地磁盘中将要共享的磁盘在管理工具中定义好
/> /iscsi create iqn.2016-12.com.mo:storage1
Created target iqn.2016-12.com.mo:storage1.
Created TPG 1.
给你共享的设备一个标志名称,尽量在网络上是独一无二的
/> iscsi/iqn.2016-12.com.mo:storage1/tpg1/acls create iqn.2016-12.com.mo:key1
Created Node ACL for iqn.2016-12.com.mo:key1
因为连接的时候需要一个key,这一步是创建连接需要的key。
/> /iscsi/iqn.2016-12.com.mo:storage1/tpg1/luns create /backstores/block/mo:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2016-12.com.mo:key1
建立真是磁盘和存储的一个映射关系。
/> /iscsi/iqn.2016-12.com.mo:storage1/tpg1/portals create 172.25.254.10
Using default IP port 3260
Created network portal 172.25.254.10:3260.
这个设备可以在哪个ip上被发现,而且根据命令的输出,可以看出该服务的端口号是3260
o- / ................................................................................. [...]
o- backstores ...................................................................... [...]
| o- block .......................................................... [Storage Objects: 1]
| | o- mo:storage1 ............................. [/dev/vdb1 (1.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.2016-12.com.mo:storage1 ............................................... [TPGs: 1]
| o- tpg1 ....................................................... [no-gen-acls, no-auth]
| o- acls .................................................................. [ACLs: 1]
| | o- iqn.2016-12.com.mo:key1 ...................................... [Mapped LUNs: 1]
| | o- mapped_lun0 ................................... [lun0 block/mo:storage1 (rw)]
| o- luns .................................................................. [LUNs: 1]
| | o- lun0 .......................................... [block/mo:storage1 (/dev/vdb1)]
| o- portals ............................................................ [Portals: 1]
| o- 172.25.254.10:3260 ....................................................... [OK]
o- loopback ................................................................. [Targets: 0]
配置后,你这个子系统中的各目录关系就变成了上面的样子。
退出后就对刚才的配置进行了保存。
2.客户端使用iscsi分享的设备
客户端使用iscsiadm这个命令来管理。
首先修改一下配置文件
[root@mail ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-12.com.mo:key1
将该文件中的InitiatorName的值改为你刚才在服务端定义的key值iqn.2016-12.com.example:key1。
重启服务
[root@mail ~]# systemctl restart iscsid.service
[root@mail ~]# iscsiadm -m discovery -t st -p 172.25.254.10
172.25.254.10:3260,1 iqn.2016-12.com.mo:storage1
使用上面命令扫描一下172.25.254.10上的共享存储设备
[root@mail ~]# iscsiadm -m node -T iqn.2016-12.com.mo:storage1 -p 172.25.254.10 -l
Logging in to [iface: default, target: iqn.2016-12.com.mo:storage1, portal: 172.25.254.10,3260] (multiple)
Login to [iface: default, target: iqn.2016-12.com.mo:storage1, portal: 172.25.254.10,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
使用fdisk -l命令后发现多出了一个设备,这个设备就是服务器分享出来的设备,接下来可以将这个设备像本地设备一样随意使用了。
客户端停用iscsi设备
首先登出iscsi目标
[root@mail ~]# iscsiadm -m node -T iqn.2016-12.com.mo:storage1 -u
Logging out of session [sid: 7, target: iqn.2016-12.com.mo:storage1, portal: 172.25.254.10,3260]
Logout of [sid: 7, target: iqn.2016-12.com.mo:storage1, portal: 172.25.254.10,3260] successful.
删除本地iscsi记录,永久断开连接
[root@mail ~]# iscsiadm -m node -T iqn.2016-12.com.mo:storage1 -o delete
进入targetcli的子shell,输入下面的命令
/> clearconfig confirm=true
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]
发现刚才设置好的目录已经被清空了。
也就停止了这个设备的共享。