iscsi server installation and configuration

Keywords: firewall network vim yum

Installation and configuration of iscsi server

1, Principle

ISCSI (Internet small computer system interface)
It supports sending commands from the client to the storage device on the remote server through ip. The default port is 3260/tcp.
1. iscsi initiator: the client
2. iscsi target: remote shared disk provided by the server
3. Target portal: Server
4. iqn: globally unique name identifier between initiator and target

2, Installation configuration

1. Server side installation configuration

1) Installation

[root@server ~]# yum install targetcli -y

2) Simple configuration server

Create a new partition first`fdisk /dev/vdb`,Then open the service`systemctl start target`,Then configure
/> 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 lcl:storage1 /dev/vdb1      ##Create a new partition you want to share as a block store
Created block storage object lcl:storage1 using /dev/vdb1.
/> /iscsi create iqn.2017-12.com.example:storage1   ##Create a share name, iqn for a globally unique name ID
Created target iqn.2017-12.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:lclkey      ##Create an encrypted string. The acl indicates that the ISCSI client host with the key can connect to the server
Created Node ACL for iqn.2017-12.com.example:lclkey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/lcl:storage1      ##Create logical unit of target block device
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:lclkey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.254.170   ##Create ip
Using default IP port 3260
Created network portal 172.25.254.170:3260.
/> ls
o- / ..................................................................... [...]
  o- backstores .......................................................... [...]
  | o- block .............................................. [Storage Objects: 1]
  | | o- lcl:storage1 ................ [/dev/vdb1 (5.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.2017-12.com.example:storage1 .............................. [TPGs: 1]
  |   o- tpg1 ........................................... [no-gen-acls, no-auth]
  |     o- acls ...................................................... [ACLs: 1]
  |     | o- iqn.2017-12.com.example:lclkey ................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ...................... [lun0 block/lcl:storage1 (rw)]
  |     o- luns ...................................................... [LUNs: 1]
  |     | o- lun0 ............................. [block/lcl:storage1 (/dev/vdb1)]
  |     o- portals ................................................ [Portals: 1]
  |       o- 172.25.254.170:3260 .......................................... [OK]
  o- loopback ..................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp  ##From the above results, we can see that the port used is 3260 and the protocol is tcp
success
[root@server ~]# firewall-cmd --reload 
success 

3. Client installation configuration

1) Installation

[root@client nfs]# yum install iscsi-initiator-utils.x86_64 -y

2) Mount test

[root@client ~]# systemctl start iscsi
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-12.com.example:lclkey        ##The content in acls set by the server allows the client to connect to the server
[root@client ~]# systemctl restart iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.170 ##Discover devices on 170 hosts
##-m for action - t for type - p for ip
172.25.254.170:3260,1 iqn.2017-12.com.example:storage1
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.170 -l     ##Add - T for targetname
Logging in to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.170,3260] (multiple)
Login to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.170,3260] successful.
[root@client ~]# fdisk -l      ##One more / dev/sda device will be found, which is the shared device of the server
......
Disk /dev/sda: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
[root@client ~]# fdisk /dev/sda    ...
[root@client ~]# partprobe 
[root@client ~]# mkfs.xfs /dev/sda1
[root@client ~]# mount /dev/sda1 /mnt
/dev/sda1                    2086912   33056   2053856   2% /mnt

4. Set up auto mount

[root@client ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="SIaPf4-OdHu-OzAW-NlQG-vZ3D-X8ZO-1FK3Ih" TYPE="LVM2_member" 
/dev/mapper/vg0-vo: UUID="12294be2-bdad-4817-b162-038e22313d9f" TYPE="ext4" 
/dev/sda1: UUID="07c00245-0c05-4da5-88a7-261efb0fec4f" TYPE="xfs" 
[root@client ~]# vim /etc/fstab
UUID="07c00245-0c05-4da5-88a7-261efb0fec4f"     /mnt    xfs     defaults,_netdev        0       0   ##UUID is the UUID of / dev/sda1_ netdev indicates network priority startup
**There may be a bugļ¼ŒAs a result, the system cannot be started. After the virtual machine is forced to shut down and turned on again, it can be turned on.

5. Delete client shared disk

Delete the contents of the shared disk in / etc/fstab, and then enter 'umount /mnt'`
[ root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.170 -u - logout
Logging out of session [sid: 3, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.170,3260]
Logout of [sid: 3, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.170,3260] successful.
[ root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.170 -o delete
 After restarting the service, use fdisk -l to check that there is no shared disk / dev/sda1

6. Set the shared disk to lvm format, which can be expanded.

Create a new partition and format it
fdisk /dev/vdb ... n ... t...8e
partprobe
mkfs.xfs /dev/vdb1

//Then create a logical volume
[root@localhost ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@localhost ~]# vgcreate iscsi_vg /dev/vdb1
  Volume group "iscsi_vg" successfully created
[root@localhost ~]# lvcreate -l 255 -n iscsi_lv0 iscsi_vg
  Logical volume "iscsi_lv0" created
[root@localhost ~]# lvs
  LV        VG       Attr       LSize    Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_lv0 iscsi_vg -wi-a----- 1020.00m                                        
[root@localhost ~]# mkfs.xfs /dev/iscsi_vg/iscsi_lv0 
meta-data=/dev/iscsi_vg/iscsi_lv0 isize=256    agcount=4, agsize=65280 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=261120, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0


//Make a shared disk
[root@localhost ~]# targetcli 
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> /backstores/block create lichunliang:storage1 /dev/iscsi_vg/iscsi_lv0
Created block storage object lichunliang:storage1 using /dev/iscsi_vg/iscsi_lv0.
/> /iscsi create iqn.2017-12.com.example:storage1
Created target iqn.2017-12.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:lichunliangkey
Created Node ACL for iqn.2017-12.com.example:lichunliangkey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/lichunliang:storage1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:lichunliangkey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.254.170
Using default IP port 3260
Created network portal 172.25.254.170:3260.

//Add ports that can pass through the firewall:
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success


## Test on client
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-12.com.example:lichunliangkey
[root@client ~]# systemctl restart iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.170
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.170 -l
//At this time, the fdisk-l command will add another disk shared by the server

//Server side expansion
//Add a new disk again
fdisk /dev/vdb ... 8e
pvcreate /dev/vdb2
vgextend iscsi_vg /dev/vdb2
lvextend -L 1500M /dev/iscsi_vg/iscsi_lv0

Posted by jrobles on Wed, 03 Jun 2020 09:52:01 -0700