iSCSI 主要是通过 TCP/IP 的技术,将储存设备端通过 iSCSI target 功能,做成服务端,再通过 iSCSI initiator (iSCSI 初始化用戶) 功能,做成使用 iSCSI target 的用戶端。 客户端可以通过局域网连接服务器上的iSCSI 服务器,在本地虚拟出一块硬盘,以达到通过网络共享服务器硬盘的效果。
- iSCSI target:就是储存设备端,它能够为用户提供可用的存储资源。
- iSCSI客户端则是用户使用的软件,用于获取远程服务端的存储资源,
配置服务端
[root@server ~]# yum install targetcli -y
[root@server ~]# systemctl start target
[root@server ~]# fdisk /dev/vdb
[root@server ~]# partprobe
[root@server ~]# targetcli
/> /backstores/block create westos:storage1 /dev/vdb1
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2018-06.com.example:storage1
Created target iqn.2018-06.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/acls create iqn.2018-06.com.example:westoskey
Created Node ACL for iqn.2018-06.com.example:westoskey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-06.com.example:westoskey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals create 172.25.254.247
Using default IP port 3260
Created network portal 172.25.254.247:3260.
/> ls
o- / .................................................................... [...]
o- backstores ......................................................... [...]
| o- block ............................................. [Storage Objects: 1]
| | o- westos:storage1 ............ [/dev/vdb1 (2.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.2018-06.com.example:storage1 ............................. [TPGs: 1]
| o- tpg1 .......................................... [no-gen-acls, no-auth]
| o- acls ..................................................... [ACLs: 1]
| | o- iqn.2018-06.com.example:westoskey ............... [Mapped LUNs: 1]
| | o- mapped_lun0 .................. [lun0 block/westos:storage1 (rw)]
| o- luns ..................................................... [LUNs: 1]
| | o- lun0 ......................... [block/westos:storage1 (/dev/vdb1)]
| o- portals ............................................... [Portals: 1]
| o- 172.25.254.214: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
注意:/iscsi/iqn.2018-06.com.example:storage1/tpg1/portals/ delete ip ip_port //删除操作
![]()
![]()
![]()
![]()
客户端设置
客户端:
[root@client ~]
[root@client ~]
InitiatorName=iqn.2018-06.com.example:westoskey //编辑内容,加密字符是服务端设定的
[root@client ~]
172.25.254.247:3260,1 iqn.2018-06.com.example:storage1
[root@client ~]
[root@client ~]
Disk /dev/sda: 2477 MB, 2477483648 bytes, 4194304 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@client ~]# fdisk /dev/sda //新建分区sda1
[root@client ~]# partprobe //刷新
[root@client ~]# mkfs.xfs /dev/sda1 //格式化
[root@client ~]# mount /dev/sda1 /mnt //挂载
[root@client ~]# vim /etc/fstab //编辑文件
/dev/sda1 /mnt xfs defaults,_netdev 0 0
[root@client ~]# mount -a
[root@client ~]# df
![]()
![]()
![]()
设备的删除
[root@client ~]# yum install tree -y
[root@client ~]# umount /mnt
[root@client ~]# vim /etc/fstab
[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.247 -u
[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.247 -o delete
[root@client ~]# systemctl restart iscsi
[root@client ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- send_targets
| `-- 172.25.254.247,3260
| `-- st_config
|-- slp
`-- static
![]()
![]()