Use targetcli to configure iSCSI access control for multiple initiators under radhat7

Test environment description: The test environment uses a total of 4 servers, two Linux, two Windows, one Linux as the iSCSI Server, using Targetcli to provide storage sharing services in the form of iSCSI, and the other three use the storage resources on the iSCSI Server, each accessing The respective resources cannot see each other's storage resources, so that resource access control can be achieved.    iSCSI Server      OS: Red Hat Enterprise Linux Server release 7.0     IP: 10.20.1.100   Client      OS: Windows Server 2008 R2      IP: 10.20.1.55      OS: NeoKylin Linux 6.5      IP: 10.20.1.56      OS: Windows Server 2008 R2      IP: 10.20.1.57Three The client has already configured the basic environment.
   












iSCSI Server configuration process
1. Some basic configuration, the purpose is to install and use targetcli, mainly configure IP, turn off firewall and yum source, install targetcli requires python environment, and select python package during system installation. :


[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens192
      TYPE=Ethernet
      BOOTPROTO=none
      IPADDR=10.20.1.100
      NETMASK=255.255.255.0
      GATEWAY=10.20.1.254
      NAME=ens192
      ONBOOT=yes
[root@localhost /]#systemctl stop firewalld



2, yum source configuration.


[root@localhost /]# cd /mnt
[root@localhost /]# mkdir rehl7
[root@localhost /]# mount /dev/sr0 /mnt/rehl7/ //Virtual CD-ROM, prepared in advance
[root@localhost /]# vim /etc/yum.repos.d/base.repo
     [base]
     name=base
     baseurl = file: /// mnt/rehl7
     enable=1
     gpgcheck=0
[root@localhost /]# yum clean all //Clear cache
[root@localhost /]# yum makecache //Reload cache



3. Disk partition, it is best to use LVM format when partitioning, so as to adjust the shared disk space later.


[root@localhost /]# fdisk -l
Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes



After the system is divided, there is still 500G space left, use fdisk to partition, create a partition for the above device /dev/sdb, and change the format to LVM.


[root@localhost ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x8fa166b8.
  Command (m for help): n  Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-1048575999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): 
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): t
Selected partition 1 Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x8fa166b8
    Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048575999   524286976   8e  Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# partprobe /dev/sdb1 //Reload partition table



4. Create LVM. Create PV and VG on /dev/sdb1 respectively, and create LV according to the partition plan.

Partition planning:
        IP pv name lv name size

       10.20.1.57 /dev/sdb1 iscsi_57 150G
       10.20.1.56 /dev/sdb1 iscsi_56 150G
       10.20.1.55 /dev/sdb1 iscsi_55 150G

LVM operation steps:


[root@localhost /]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@localhost /]# vgcreate iSCSI /dev/sdb1
  Volume group "iSCSI" successfully created
[root@localhost /]# lvcreate -L 150G -n iscsi_56 iSCSI
  Logical volume "iscsi_56" created
[root@localhost /]# lvcreate -L 150G -n iscsi_57 iSCSI
  Logical volume "iscsi_57" created
[root@localhost /]# lvcreate -L 150G -n iscsi_55 iSCSI
  Logical volume "iscsi_55" created
[root@localhost /]# vgs
  VG    #PV #LV #SN Attr   VSize   VFree 
  iSCSI   1   3   0 wz--n- 500.00g 50.00g
  rhel 1 2 0 wz - n- 83.80g 0 
[root@localhost /]# lvs
  LV  VG  Attr  LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_55 iSCSI -wi-a----- 150.00g  
  iscsi_56 iSCSI -wi-a----- 150.00g  
  iscsi_57 iSCSI -wi-a----- 150.00g
  home     rhel  -wi-ao----   4.88g
  root     rhel  -wi-ao----  78.92g




5, targetcli installation and iSCSI configuration. When configuring the local server, in order to distinguish it, you need to modify the iqn name in advance. It is best to add the suffix to the name of the server to distinguish it from the Client.


[root@localhost /]# yum install targetcli –y //Install the iscsi service manager
[root@localhost /]# systemctl start target //Start target service
[root@localhost /]# systemctl enable target //Set the service to start automatically at boot
[root@localhost /]# yum install iscsi-initiator-utils //安装iscsi Initiator
[root@localhost /]# vim /etc/iscsi/initiatorname.iscsi //Modify iqn name
InitiatorName=iqn.1994-05.com.redhat:iSCSIserver



Run the iSCSI configuration command


[root@localhost etc]# 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 //View the tree structure layout
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 iscsi55_data /dev/iSCSI/iscsi_55 //Use LV to create storage blocks respectively.
Created block storage object iscsi55_data using /dev/iSCSI/iscsi_55.
/> /backstores/block create iscsi56_data /dev/iSCSI/iscsi_56   //创建iscsi56-data
Created block storage object iscsi56_data using /dev/iSCSI/iscsi_56.
/> /backstores/block create iscsi57_data /dev/iSCSI/iscsi_57   //创建iscsi57-data
Created block storage object iscsi57_data using /dev/iSCSI/iscsi_57.
/> iscsi/ create iqn.1994-05.com.redhat:iSCSIserver //Configure the server iSCSI Target name, which has been written to the file earlier.
Created target iqn.1994-05.com.redhat:iSCSIserver.
Created TPG 1.
/> iscsi/iqn.1994-05.com.redhat:server/tpg1/portals create 10.20.1.100 //Configure the server IP and port, the default port is 3260
Using default IP port 3260
Created network portal 10.20.1.100:3260.
/>ls //View the configuration




   Configure the Client launcher, the launcher names of the three clients have been modified in advance to a unified format, paste and copy the text file. Because some configuration path names used in targetcli are too long, you can use the cd command to enter this item. If you are not familiar with the command, you can use help to view the help. Use the carete command under acls to create initiators 57, 56, and 55 respectively.


> cd iscsi/iqn.1994-05.com.redhat:iscsiserver/tpg1/acls  
/iscsi/iqn.19...ver/tpg1/acls> create iqn.1991-05.com.microsoft:mq57master 
Created Node ACL for iqn.1991-05.com.microsoft:mq57master






  There are two ways to create a LUN, one is to create it under luns, and the other is to create it directly under the launcher.
  First, test the creation under luns. Each time a LUN is built under the luns item, the program will automatically attach the LUN to all acls. Therefore, the redundant LUNs should be deleted under acls as required. Use create under luns to create a LUN.


  You can see that there are 3 LUNs on each initiator under acls.


  Delete redundant LUNs.


  Created under the initiator, this method is relatively straightforward. Create a new LUN directly on demand under the acls item, and directly map it to the corresponding initiator. Once it is in place, the command is relatively long.
First delete the original three LUNs and create them using create under acls.


  After the iSCSI configuration is complete, take a look at the overall effect:


6. The client configures
the windows configuration. There are many online tutorials on the configuration of the windows to install iSCSI. Here, only the steps are written without the pictures.
Open the iSCSI initiator in the management tool, the following steps:
1) Enter the IP in the target, and click Quick Connect;
2) The quick connection login success report will pop up, and click OK;
3) There will be corresponding content in the discovered and favorited targets;
4) Click on the automatic configuration in the volume and device, and you will get the device yourself;
5) Click on the service manager - storage - disk management - right-click on the newly added hard disk;
6) Initialize to MBR, and then format the disk.

Linux operating system configuration method, linux is arranged according to the steps
1) Use commands to discover resources


 [root@FTPServer ~]# iscsiadm -m discovery -t sendtargets -p 10.20.1.100


2) Use the command to log in to the resource


[root@FTPServer ~]# iscsiadm -m node T iqn.1994-05.com.redhat:iscsiserver -p 10.20.1.100



3) Use fdisk to check and partition


[root@FTPServer ~]# fdisk –l


 
A 161G device is detected and partitioned. Because the disk may be expanded or reduced in the future, it is best to change the disk format to LVM.


[root@FTPServer ~]# fdisk /dev/sdc
[root@FTPServer ~]# partprobe /dev/sdc1 //Reread the partition table


4) Create LVM and format


[root@FTPServer ~]# pvcreate /dev/sdc1 //Create PV
   Physical volume "/dev/sdc1" successfully created
[root@FTPServer ~]# vgcreate FtpDataGroup /dev/sdc1 //Create VG
   Volume group "FtpDataGroup" successfully created
[root@FTPServer ~]# lvcreate -l 38398 -n FtpData FtpDataGroup //Create LV
   Logical volume "FtpData" created
[root@FTPServer ~]# mkfs.xfs /dev/FtpDataGroup/FtpData //Formatted as xfs


5) Mounting a new partition
Since it is a network disk, it is best to use UUID to mount it when using the automatic mount method. Check the UUID first.

Disk mount, be careful not to forget the underscore in front of netdev . Be careful not to fail. . . .
[root@FTPServer ~]# vim /etc/fstab

mount -a look at df -h to view the partition mount, complete. After the configuration is complete, restart the system to make sure that the newly added disk can be recognized normally and the configuration is complete.
 



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325256541&siteId=291194637