linux下 iscsi (共享磁盘) 的配置

linux 4个月前 散逸
浏览:242 0

目标:
实现真机(windows),能够使用虚拟机的磁盘。
实现另一台虚拟机(linux),能够使用虚拟机的磁盘。


效果:
linux下 iscsi (共享磁盘) 的配置
linux下 iscsi (共享磁盘) 的配置


一、准备工作(RHEL7)、
添加一块20G硬盘(关机添加再开机)

步骤:
关闭selinux
临时关闭:

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive

永久关闭:

[root@localhost ~]# vim /etc/sysconfig/selinux
SELINUX=enforcing 改为 SELINUX=disabled
重启服务reboot

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld


配置yum
yum repolist //查看yum是否正确

fdisk -l 查看硬盘
如果添加硬盘后,会出现/dev/sdb


iqn号:标识唯一 一台设备


1、配置网络,实现客户端与服务器之间的通信

2、配置yum源,安装软件iscsi targetcli
yum install targetcli -y

3、重启服务,并设置服务的开机自启 iscsi target

   systemctl restart iscsi
   systemctl restart target
   systemctl enable target
   systemctl enable iscsi

4、配置防火墙,允许iscsi通过(之前已经直接关闭了防火墙,所以这里不需要配置;也可以不关闭,设置允许通过即可)

5、创建分区/dev/sdb1 并且加载磁盘

fdisk /dev/sdb
创建主分区具体步骤:https://eee.run/2019-12-16/74.html

partx -a /dev/sdb //加载

6、targetcli配置

targetcli

①基于分区/dev/sdb1创建块设备server0

/backstores/block create server0 /dev/sdb1

②基于server iqn号 创建共享设备iscsi设备 自动tpg1(设备管理组)

cat /etc/iscsi/in......(Tab自动补齐)    //获取iqn号(开启新的终端窗口)

/iscsi create iqn.1994-05.com.redhat:ea14e912e6fb

③基于块设备server0创建1un 1

 /iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/luns create /backstores/block/server0 1

④基于客户端的iqn号创建acl,确定谁可以访问共享的磁盘 (windows获取iqn号→开始-iscsi-配置-复制iqn号 粘贴在 最后 iqn.1991-05.com.microsoft:desktop-sh32141)

/iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/acls create iqn.1991-05.com.microsoft:desktop-sh32141 

⑤添加服务器的IP地址和端口号3260

/iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/portals create 192.168.100.20 3260

/iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/portals delete 0.0.0.0 3260   //使用ls命令查看,如果已经存在0.0.0.0 3260 则使用此命令删除

⑥保存
saveconfig
⑦退出
exit

具体命令如下:

[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb46
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 server0 /dev/sdb1
Created block storage object server0 using /dev/sdb1.
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ......... [/dev/sdb1 (0 bytes) write-thru deactivated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | 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.1994-05.com.redhat:ea14e912e6fb
Created target iqn.1994-05.com.redhat:ea14e912e6fb.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ......... [/dev/sdb1 (0 bytes) write-thru deactivated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | o- fileio .................................... [Storage Objects: 0]
  | o- pscsi ..................................... [Storage Objects: 0]
  | o- ramdisk ................................... [Storage Objects: 0]
  o- iscsi ............................................... [Targets: 1]
  | o- iqn.1994-05.com.redhat:ea14e912e6fb .................. [TPGs: 1]
  |   o- tpg1 .................................. [no-gen-acls, no-auth]
  |     o- acls ............................................. [ACLs: 0]
  |     o- luns ............................................. [LUNs: 0]
  |     o- portals ....................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ........................................ [OK]
  o- loopback ............................................ [Targets: 0]
/> /iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/portals delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ......... [/dev/sdb1 (0 bytes) write-thru deactivated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | o- fileio .................................... [Storage Objects: 0]
  | o- pscsi ..................................... [Storage Objects: 0]
  | o- ramdisk ................................... [Storage Objects: 0]
  o- iscsi ............................................... [Targets: 1]
  | o- iqn.1994-05.com.redhat:ea14e912e6fb .................. [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.1994-05.com.redhat:ea14e912e6fb/tpg1/luns create /backstores/block/server0 1
Created LUN 1.
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ........... [/dev/sdb1 (0 bytes) write-thru activated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | o- fileio .................................... [Storage Objects: 0]
  | o- pscsi ..................................... [Storage Objects: 0]
  | o- ramdisk ................................... [Storage Objects: 0]
  o- iscsi ............................................... [Targets: 1]
  | o- iqn.1994-05.com.redhat:ea14e912e6fb .................. [TPGs: 1]
  |   o- tpg1 .................................. [no-gen-acls, no-auth]
  |     o- acls ............................................. [ACLs: 0]
  |     o- luns ............................................. [LUNs: 1]
  |     | o- lun1 ...... [block/server0 (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals ....................................... [Portals: 0]
  o- loopback ............................................ [Targets: 0]
/> /iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/portals create 192.168.100.20 3260
Using default IP port 3260
Created network portal 192.168.100.20:3260.
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ........... [/dev/sdb1 (0 bytes) write-thru activated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | o- fileio .................................... [Storage Objects: 0]
  | o- pscsi ..................................... [Storage Objects: 0]
  | o- ramdisk ................................... [Storage Objects: 0]
  o- iscsi ............................................... [Targets: 1]
  | o- iqn.1994-05.com.redhat:ea14e912e6fb .................. [TPGs: 1]
  |   o- tpg1 .................................. [no-gen-acls, no-auth]
  |     o- acls ............................................. [ACLs: 0]
  |     o- luns ............................................. [LUNs: 1]
  |     | o- lun1 ...... [block/server0 (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals ....................................... [Portals: 1]
  |       o- 192.168.100.20:3260 ................................. [OK]
  o- loopback ............................................ [Targets: 0]
/> /iscsi/iqn.1994-05.com.redhat:ea14e912e6fb/tpg1/acls create iqn.1991-05.com.microsoft:desktop-sh32141 
Created Node ACL for iqn.1991-05.com.microsoft:desktop-sh32141
Created mapped LUN 1.
/> ls
o- / ............................................................ [...]
  o- backstores ................................................. [...]
  | o- block ..................................... [Storage Objects: 1]
  | | o- server0 ........... [/dev/sdb1 (0 bytes) write-thru activated]
  | |   o- alua ...................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......... [ALUA state: Active/optimized]
  | o- fileio .................................... [Storage Objects: 0]
  | o- pscsi ..................................... [Storage Objects: 0]
  | o- ramdisk ................................... [Storage Objects: 0]
  o- iscsi ............................................... [Targets: 1]
  | o- iqn.1994-05.com.redhat:ea14e912e6fb .................. [TPGs: 1]
  |   o- tpg1 .................................. [no-gen-acls, no-auth]
  |     o- acls ............................................. [ACLs: 1]
  |     | o- iqn.1991-05.com.microsoft:desktop-sh32141  [Mapped LUNs: 1]
  |     |   o- mapped_lun1 .................. [lun1 block/server0 (rw)]
  |     o- luns ............................................. [LUNs: 1]
  |     | o- lun1 ...... [block/server0 (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals ....................................... [Portals: 1]
  |       o- 192.168.100.20:3260 ................................. [OK]
  o- loopback ............................................ [Targets: 0]
/> saveconfig 
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

7、重启服务 iscsi target

    systemctl restart iscsi
    systemctl restart target

以上是共享给windows
给linux 步骤步骤基本相同,
还需要 以下命令:

iscsiadm --mode discoverydb --type sendtargets --portal 192.168.100.3 --discover

iscsiadm --mode node --targetname iqn.1994-05.com.redhat:ea14e912e6fb --portal 192.168.100.3:3260 --login
版权声明:散逸 发表于 2019-12-20 8:58:38。
转载请注明:linux下 iscsi (共享磁盘) 的配置 | 散逸

暂无评论

暂无评论...