服务端
yum install targetcli -y
targetcli
/backstores/block/ create westos:storagel /dev/vdb1
/iscsi create iqn.2018-08.com.westos:storagel
iscsi/iqn.2018-08.com.westos:storagel/tpg1/acls create iqn.2018-08.com.westos:westoskey1
iscsi/iqn.2018-08.com.westos:storagel/tpg1/luns create backstores/block/westos:storagel
iscsi/iqn.2018-08.com.westos:storagel/tpg1/portals create 172.25.254.205
[root@localhost ~]# 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: 1]
| | o- westos:storagel ....... [/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-08.com.westos:storagel ......................... [TPGs: 1]
| o- tpg1 ..................................... [no-gen-acls, no-auth]
| o- acls ................................................ [ACLs: 1]
| | o- iqn.2018-08.com.westos:westoskey1 .......... [Mapped LUNs: 1]
| | o- mapped_lun0 ............. [lun0 block/westos:storagel (rw)]
| o- luns ................................................ [LUNs: 1]
| | o- lun0 .................... [block/westos:storagel (/dev/vdb1)]
| o- portals .......................................... [Portals: 1]
| o- 172.25.254.205: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
[root@localhost ~]#
关闭防护墙
客户端
yum install iscsi-initiator-utils
iscsiadm -m discovery -t st -p 172.25.254.205 ##发现设备
vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2018-08.com.westos:westoskey1 ##修改认证
systemctl restart iscsid.service
iscsiadm -m node -T iqn.2018-08.com.westos:storagel -p 172.25.254.205 -l ##连接设备
fdisk -l ##此时会出现2G的/dev/sda硬盘设备
fdisk /dev/sda ##可以在该设备上创建分区
将分区开机时自动挂载
vim /etc/fstab
/dev/sda1 /mnt xfs defaults,_netdev 0 0
如果要删除该硬盘设备
删除自动挂载
vim /etc/fstab
/dev/sda1 /mnt xfs defaults,_netdev 0 0
卸载
umount /mnt
iscsiadm -m node -T iqn.2018-08.com.westos:storagel -p 172.25.254.205 -u ##退出登陆
iscsiadm -m node -T iqn.2018-08.com.westos:storagel -p 172.25.254.205 -o delete ##删除相关文件
tree /var/lib/iscsi/
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- send_targets
| `-- 172.25.254.205,3260
| `-- st_config
|-- slp
`-- static
客户端删除iscsi
删除iscsi中文件
targetcli
/> clearconfig confirm=True