EchoCow

念念不忘,必有回响

念念不忘,必有回响
  menu
96 文章
89 评论
89212 浏览
4 当前访客
ღゝ◡╹)ノ❤️

rhce 19 配置ISCSI服务端

配置system1提供一个ISCSI 服务磁盘名为 iqn.2014-08.com.example:system1 并符合下列要求:

  1. 服务端口为3260
  2. 使用iscsi_store作其后端卷名称,其大小为3G
  3. 此服务只能被system2.group8.example.com访问

操作

安装 target 、开启服务并开机启动

yum install targetcli.noarch -y
systemctl enable target
systemctl start target
firewall-cmd --permanent --add-port=3260/tcp    //需要配置访问控制、富规则
firewall-cmd --reload

为其创建后端卷并查看

[root@system1 ~]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).
  
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
    
    
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (26626048-41943039, default 26626048): 
Using default value 26626048
Last sector, +sectors or +size{K,M,G} (26626048-41943039, default 41943039): +3G
Partition 3 of type Linux and of size 3 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@system1 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0  9.8G  0 part /
└─sda2   8:2    0    3G  0 part [SWAP]
[root@system1 ~]# partprobe 
[root@system1 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0  9.8G  0 part /
├─sda2   8:2    0    3G  0 part [SWAP]
└─sda3   8:3    0    3G  0 part 
配置 ISCSI 并重启服务
[root@system1 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
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]
/> /backstores/block create name=iscsi_store dev=/dev/sda3 
Created block storage object iscsi_store using /dev/sda3.
// 创建后端卷    

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_store ................................................................... [/dev/sda3 (3.0GiB) write-thru deactivated]
  | 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 wwn=iqn.2014-08.com.example:system1 
Created target iqn.2014-08.com.example:system1.
Created TPG 1.
    
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_store ................................................................... [/dev/sda3 (3.0GiB) write-thru deactivated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.example:system1 ................................................................................... [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.2014-08.com.example:system1/tpg1/acls create 
add_mapped_luns=  wwn=              
...........................................................wwn|keyword=
/> /iscsi/iqn.2014-08.com.example:system1/tpg1/acls create iqn.2014-08.com.example:system2 
Created Node ACL for iqn.2014-08.com.example:system2
//访问控制

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_store ................................................................... [/dev/sda3 (3.0GiB) write-thru deactivated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.example:system1 ................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2014-08.com.example:system2 ...................................................................... [Mapped LUNs: 0]
  |     o- luns .......................................................................................................... [LUNs: 0]
  |     o- portals .................................................................................................... [Portals: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/> /iscsi/iqn.2014-08.com.example:system1/tpg1/luns 
@last      cd         delete     get        ls         refresh    status     
bookmarks  create     exit       help       pwd        set        
....................................................command
/> /iscsi/iqn.2014-08.com.example:system1/tpg1/luns create /backstores/block/iscsi_store 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2014-08.com.example:system2
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_store ..................................................................... [/dev/sda3 (3.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.2014-08.com.example:system1 ................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2014-08.com.example:system2 ...................................................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................................................................... [lun0 block/iscsi_store (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................................. [block/iscsi_store (/dev/sda3)]
  |     o- portals .................................................................................................... [Portals: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/> /
/*            /backstores/  /iscsi/       /loopback/    
...path
/> /iscsi/iqn.2014-08.com.example:system1/tpg1/portals 
@last      cd         delete     get        ls         refresh    status     
bookmarks  create     exit       help       pwd        set        
.......................................................command
/> /iscsi/iqn.2014-08.com.example:system1/tpg1/portals create 172.24.8.11
Using default IP port 3260
Created network portal 172.24.8.11:3260.
/> 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
[root@system1 ~]# systemctl restart target.service 
[root@system1 ~]# systemctl enable target.service 

念念不忘,必有回响。

如果觉得文章不错或者帮到了您,帮忙点点下面广告呗~谢谢啦~

评论