本地端挂载远程服务器的磁盘或者分区当成本地磁盘使用,目前有两台机器,分别是foundation(服务

器端192.168.122.1/24)和Desktop(终端192.168.122.2/24),先配置服务器端:以RHEL7为例,准备一个分区/dev/sda5

#yum -y install targetcli            //安装软件
#systemctl enable target.service     //设置开机自启
#systemctl start target.service        //启动服务
#targetcli                            //进入命令行

进入到/> cd backstores/block/目录,创建后端区域磁盘,名字为back,这里使用的是分区/dev/sda5

/> cd backstores/block/
/> create back /dev/sda5
/backstores/block> cd ../../iscsi/
/iscsi> create iqn.2015-09.com.example:rhce   //创建本地链接名称

进入到tpg1目录,创建acls,由于只有一个lun0,故这里可以不指定

/iscsi/iqn.20...hce/tpg1/acls>create iqn.2015-09.com.example.foundation:888

进入到luns目录,创建对应关系

/iscsi/iqn.20...hce/tpg1/luns> create /backstores/block/back

指定端口

create ip_address=192.168.122.1 ip_port=3260

最后的目录结构为:

/> ls
o- / ................................................................................................... [...]
  o- backstores ........................................................................................ [...]
  | o- block ............................................................................ [Storage Objects: 1]
  | | o- back ...................................................... [/dev/sda5 (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.2015-09.com.example:rhce ................................................................ [TPGs: 1]
  |   o- tpg1 ......................................................................... [no-gen-acls, no-auth]
  |     o- acls .................................................................................... [ACLs: 1]
  |     | o- iqn.2015-09.com.example.foundation:888 ......................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................................ [lun0 block/back (rw)]
  |     o- luns .................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................... [block/back (/dev/sda5)]
  |     o- portals .............................................................................. [Portals: 1]
  |       o- 192.168.122.1:3260 ......................................................................... [OK]
  o- loopback ................................................................................... [Targets: 0]

接下来配置防火墙

#firewall-cmd --permanent --add-port=3260/tcp --zone=public 
#firewall-cmd --permanent --add-port=3260/udp --zone=public 
#firewall-cmd --reload

现在将视线转到desktop端

#yum install iscsi-*
#vim /etc/iscsi/initiatorname.iscsi   //将其中的默认的名字改为服务器端中acls里设置的名字
#systemctl enable iscsi
#systemctl enable iscsid
#systemctl start iscsi
#systemctl start iscsid
#iscsiadm -m discovery -t st -p 192.168.122.1:3260    //发现设备
#iscsiadm --node -l                                    //登陆

登陆成功后fdisk -l即可看到新增的一块磁盘,接下来可以对磁盘进行格式化和挂载,即可正常使用