2020年3月20日 星期五

Ubuntu 18.04 install iscsi server and client

** Ubuntur 18.04 setting ISCSI

Install the targetcli
# apt-get install targetcli-fb

Create the backend storage device
# targetcli 
targetcli shell version 2.1.fb43
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]
  o- srpt ............................................................................................................. [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
/>

To create a backstore, you can cd to backstores/block or backstores/fileio and create the respective backstore.
/> cd /backstores/block
/backstores/block>

/backstores/block> create name=iscsi-disk01 dev=/dev/nullb0
Created block storage object iscsi-disk01 using /dev/nullb0.
/backstores/block>

or

/backstores> cd fileio
/backstores/fileio>

/backstores/fileio> create iscsi_file /tmp/iscsi_disks/disk01.img 10G
/tmp/iscsi_disks/disk01.img exists, using its size (1073741824 bytes) instead
Created fileio iscsi_file with size 1073741824

PS. 要確定建立 /tmp/ iscsi_disks 資料夾

跳到 / , 重新ls 查看建立資料
/backstores/fileio> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi-disk01 .............................................................. [/dev/nullb0 (250.0GiB) write-thru deactivated]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- iscsi_file .................................................. [/tmp/iscsi_disks/disk01.img (1.0GiB) write-back deactivated]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
  o- srpt ............................................................................................................. [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
/>

block        #用 block 方式分享  /dev/sda /dev/sdb ...
fileio        #將檔案建於 file system 之上, 再通過 iSCSI 當做 block device 分享出去
pscsi         #連結的設備原本就是 iSCSI 設備時,選 pscsi
remdisk    #不需長久儲存時,可用 ramdisk 分享

Create the iSCSI Target and Portal
naming rule :
[ iqn.(year)-(month).(reverse of domain name):(name of your choice) ]

/> cd iscsi
/iscsi>

/iscsi>  create iqn.2020-03.com.accusys.storage.target1
Created target iqn.2020-03.com.accusys.storage.target1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>

As you can see on the last line, a default portal listening on TCP port 3260 is created when the target is created. To verify this, run ls command.

Set up the LUN

/iscsi> cd /iscsi/iqn.2020-03.com.accusys.storage.target1/tpg1/luns
/iscsi/iqn.20...et1/tpg1/luns>

/iscsi/iqn.20...et1/tpg1/luns> ls /
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi-disk01 .............................................................. [/dev/nullb0 (250.0GiB) write-thru deactivated]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- iscsi_file .................................................. [/tmp/iscsi_disks/disk01.img (1.0GiB) write-back deactivated]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2020-03.com.accusys.storage.target1 ........................................................................... [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]
  o- srpt ............................................................................................................. [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
/iscsi/iqn.20...et1/tpg1/luns> create /backstores/block/iscsi-disk01 
Created LUN 0.
/iscsi/iqn.20...et1/tpg1/luns> create /backstores/fileio/iscsi_file
Created LUN 1.
/iscsi/iqn.20...et1/tpg1/luns>

Set up Access Control Lists (ACL)
ACL is used to specify the clients (iSCSI intiators) allowed to access the iSCSI target backstores.
To cteate an ACL for an intiator, run create command with IQN of the initiator just like as did above.

/> cd /iscsi/iqn.2020-03.com.accusys.storage.target1/tpg1/acls
/iscsi/iqn.20...et1/tpg1/acls> create iqn.2020-03.com.accusys.storage.initiator
Created Node ACL for iqn.2020-03.com.accusys.storage.initiator
Created mapped LUN 1.
Created mapped LUN 0.
/iscsi/iqn.20...et1/tpg1/acls>

Set User ID and password for iSCSI initiator authentication
/> cd /iscsi/iqn.2020-03.com.accusys.storage.target1/tpg1/acls/iqn.2020-03.com.accusys.storage.initiator
/iscsi/iqn.20...age.initiator>

/iscsi/iqn.20...age.initiator>  set auth userid=username  // 指定loging 的 帳號 = username
Parameter userid is now 'username'.
/iscsi/iqn.20...age.initiator> set auth password=password // 指定loging 的 密碼 = password
Parameter password is now 'password'.

/iscsi/iqn.20...age.initiator> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/rtslib-fb-target/backup.
Configuration saved to /etc/rtslib-fb-target/saveconfig.json

PS. Create Ram Disk named test1:

/> backstores/ramdisk/ create name=test1 nullio=true size=4G


PS. iser setting.
/iscsi/iqn.20.../0.0.0.0:3260> pwd
/iscsi/iqn.2020-03.com.accusys.storage.target1/tpg1/portals/0.0.0.0:3260

/iscsi/iqn.20.../0.0.0.0:3260> enable_iser true
iSER enable now: True
/iscsi/iqn.20.../0.0.0.0:3260> ls
o- 0.0.0.0:3260 ............................................................................................................. [iser]

/iscsi/iqn.20.../0.0.0.0:3260> enable_iser false
iSER enable now: False
/iscsi/iqn.20.../0.0.0.0:3260> ls
o- 0.0.0.0:3260 ............................................................................................................... [OK]


PS. Parameter setting
/iscsi/iqn.20....target1/tpg1> pwd
/iscsi/iqn.2020-03.com.accusys.storage.target1/tpg1

/iscsi/iqn.20....target1/tpg1> set parameter MaxConnections=32
Parameter MaxConnections is now '32'.

/iscsi/iqn.20....target1/tpg1> set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
Parameter authentication is now '0'.
Parameter demo_mode_write_protect is now '0'.
Parameter generate_node_acls is now '1'.
Parameter cache_dynamic_acls is now '1'.

PARAMETER CONFIG GROUP
======================
AuthMethod=string
--------------------
Authentication method used by the TPG.

DataDigest=string
--------------------
If set to CRC32C, the integrity of the PDU data part is verified.

DataPDUInOrder=yesno
-----------------------
If set to Yes, the data PDUs within sequences must be in order.

DataSequenceInOrder=yesno
----------------------------
If set to Yes, the data sequences must be in order.

DefaultTime2Retain=number
----------------------------
Maximum time, in seconds, after an initial wait, before which an active task reassignment is still possible after an unexpected connection termination or a connection reset.

DefaultTime2Wait=number
--------------------------
Minimum time, in seconds, to wait before attempting an explicit/implicit logout or an active task reassignment after an unexpected connection termination or a connection reset.

ErrorRecoveryLevel=number
----------------------------
Recovery levels represent a combination of recovery capabilities.

FirstBurstLength=number
--------------------------
Maximum amount in bytes of unsolicited data an initiator may send.

HeaderDigest=string
----------------------
If set to CRC32C, the integrity of the PDU header part is verified.

IFMarkInt=string
-------------------
Deprecated according to RFC 7143.

IFMarker=yesno
-----------------
Deprecated according to RFC 7143.

ImmediateData=string
-----------------------
Immediate data support.

InitialR2T=yesno
-------------------
If set to No, the default use of R2T (Ready To Transfer) is disabled.

MaxBurstLength=number
------------------------
Maximum SCSI data payload in bytes in a Data-In or a solicited Data-Out iSCSI sequence.

MaxConnections=number
------------------------
Maximum number of connections acceptable.

MaxOutstandingR2T=number
---------------------------
Maximum number of outstanding R2Ts per task.

MaxRecvDataSegmentLength=number
----------------------------------
Maximum data segment length in bytes the target can receive in an iSCSI PDU.

MaxXmitDataSegmentLength=number
----------------------------------
Outgoing MaxRecvDataSegmentLength sent over the wire during iSCSI login response.

OFMarkInt=string
-------------------
Deprecated according to RFC 7143.

OFMarker=yesno
-----------------
Deprecated according to RFC 7143.

TargetAlias=string
---------------------
Human-readable target name or description.

ATTRIBUTE CONFIG GROUP
======================
authentication=number
------------------------
If set to 1, enforce authentication for this TPG.

cache_dynamic_acls=number
----------------------------
If set to 1 in demo mode, cache dynamically generated ACLs.

default_cmdsn_depth=number
-----------------------------
Default CmdSN (Command Sequence Number) depth.

default_erl=number
---------------------
Default Error Recovery Level.

demo_mode_discovery=number
-----------------------------
If set to 1 in demo mode, enable discovery.

demo_mode_write_protect=number
---------------------------------
If set to 1 in demo mode, prevent writes to LUNs.

fabric_prot_type=number
--------------------------
Fabric DIF protection type.

generate_node_acls=number
----------------------------
If set to 1, allow all initiators to login (i.e. demo mode).

login_keys_workaround=string
-------------------------------

login_timeout=number
-----------------------
Login timeout value in seconds.

netif_timeout=number
-----------------------
NIC failure timeout in seconds.

prod_mode_write_protect=number
---------------------------------
If set to 1, prevent writes to LUNs.

t10_pi=number
----------------
If set to 1, enable T10 Protection Information.

tpg_enabled_sendtargets=number
---------------------------------
If set to 1, the SendTargets discovery response advertises the TPG only if the TPG is enabled.


**Ubuntu Iscsi clent
install iSCSI initiator packages
# apt-get install open-iscsi

Edit the /etc/iscsi/initiatorname.iscsi and set the IQN of the initiator to be just the same as the one we created on the target
above you can comment out the existing and add a new one as shown below.
vi /etc/iscsi/initiatorname.iscsi 

## DO NOT EDIT OR REMOVE THIS FILE!
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator.  The InitiatorName must be unique
## for each iSCSI initiator.  Do NOT duplicate iSCSI InitiatorNames.
#InitiatorName=iqn.1993-08.org.debian:01:c27157ed3fb4
InitiatorName=iqn.2020-03.com.accusys.storage.initiator

Edit the /etc/iscsi/iscsid.conf configuration file to set the authentication method and specify the username and password defined above, under the CHAP settings
# vi /etc/iscsi/iscsid.conf 

51 # CHAP Settings
52 # *************
53
54 # To enable CHAP authentication set node.session.auth.authmethod
55 # to CHAP. The default is None.
56 node.session.auth.authmethod = CHAP      <---- uncomment this line
57
58 # To set a CHAP username and password for initiator
59 # authentication by the target(s), uncomment the following lines:
60 node.session.auth.username = username    <---- uncomment and set the right user
61 node.session.auth.password = password    <---- uncomment and set the right password

Save the configuration file and restart and enable both iscsid and iscsi services.

# systemctl restart iscsid open-iscsi
# systemctl enable iscsid open-iscsi


Run target discovery against our iSCSI target server to find out the shared targets.
# iscsiadm -m discovery -t st -p 10.10.8.22         
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
iscsiadm: config file line 1 do not has value
10.10.8.22:3260,1 iqn.2020-03.com.accusys.storage.target1

We need to login or logout to it. Run the command below to login to the target.
# iscsiadm -m node --login 
# iscsiadm -m node --logout
Logging in to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.55,3260] (multiple)
Logging in to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.22,3260] (multiple)
Login to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.55,3260] successful.
Login to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.22,3260] successful.


You can also login or logout to target by specifying the iqn as in:
# iscsiadm -m node -T iqn.2020-03.com.accusys.storage.target1 -p 10.10.8.22 --login
# iscsiadm -m node -T iqn.2020-03.com.accusys.storage.target1 -p 10.10.8.22 --logout

Once logged in, you can run the following command to see the details of the established session.
# iscsiadm -m node -T iqn.2020-03.com.accusys.storage.target1 -l
Logging in to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.55,3260] (multiple)
Logging in to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.22,3260] (multiple)
Login to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.55,3260] successful.
Login to [iface: default, target: iqn.2020-03.com.accusys.storage.target1, portal: 10.10.8.22,3260] successful.

# iscsiadm -m session -o show 
tcp: [7] 10.10.8.55:3260,1 iqn.2020-03.com.accusys.storage.target1 (non-flash)
tcp: [8] 10.10.8.22:3260,1 iqn.2020-03.com.accusys.storage.target1 (non-flash)

# iscsiadm -m session -o show -P 1
Target: iqn.2020-03.com.accusys.storage.target1 (non-flash)
        Current Portal: 10.10.8.55:3260,1
        Persistent Portal: 10.10.8.55:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.2020-03.com.accusys.storage.initiator
                Iface IPaddress: 10.10.8.36
                Iface HWaddress: <empty>
                Iface Netdev: <empty>
                SID: 7
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE
        Current Portal: 10.10.8.22:3260,1
        Persistent Portal: 10.10.8.22:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.2020-03.com.accusys.storage.initiator
                Iface IPaddress: 10.10.8.36
                Iface HWaddress: <empty>
                Iface Netdev: <empty>
                SID: 8
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE

# lsblk --scsi
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sda  2:0:0:0    disk VMware,  VMware Virtual S 1.0  spi
sdb  39:0:0:0   disk LIO-ORG  iscsi-disk01     4.0  iscsi
sdc  40:0:0:0   disk LIO-ORG  iscsi-disk01     4.0  iscsi
sdd  40:0:0:1   disk LIO-ORG  iscsi_file       4.0  iscsi
sde  39:0:0:1   disk LIO-ORG  iscsi_file       4.0  iscsi
sr0  4:0:0:0    rom  NECVMWar VMware SATA CD01 1.00 sata

沒有留言:

張貼留言