Configuring iSCSI Target
- installation
- yum -y install targetcli
- systemctl start target
- systemctl enable target
- enable iscsi-target service in firewalld
- firewall-cmd --permanent --add-service=iscsi-target
- firewall-cmd --reload
- using partition
- fdsik /dev/sdb
- create new 3G partition
- if DNS is not configured make sure to add servers in /etc/hosts
- 192.168.23.145 server6 server6.example.com
- 192.168.23.144 server7 server7.example.com
- 192.168.23.146 server8 server8.example.com
- configuring target
- targetcli
- create block
- cd backstores
- /backstores> block/ create block1 /dev/vgsan/lv_san1
- /backstores> block/ create block2 /dev/vgsan/lv_san2
- create target
- cd iscsi
- /iscsi> create iqn.2016-04.com.example:target
- create acls
- /iscsi> cd iqn.2016-04.com.example:target/
- /iscsi/iqn.20...xample:target> cd tpg1/
- /iscsi/iqn.20...e:target/tpg1> acls/ create iqn.2016-04.com.example:server7
- /iscsi/iqn.20...e:target/tpg1> acls/ create iqn.2016-04.com.example:server8
- create luns
- /iscsi/iqn.20...e:target/tpg1> luns/ create /backstores/block/block1
- /iscsi/iqn.20...e:target/tpg1> luns/ create /backstores/block/block2
- configure portals - if 0.0.0.0:3260 is already exist delete it first.
- /iscsi/iqn.20...e:target/tpg1> portals/ delete 0.0.0.0 3260
- /iscsi/iqn.20...e:target/tpg1> portals/ create 192.168.23.145 3260 <-- IP of target server.
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 2]
| | o- block1 ................................................................. [/dev/vgsan/lv_san1 (2.0GiB) write-thru activated]
| | o- block2 ................................................................. [/dev/vgsan/lv_san2 (2.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.2016-04.com.example:target .................................................................................... [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 2]
| | o- iqn.2016-04.com.example:server7 ...................................................................... [Mapped LUNs: 1]
| | | o- mapped_lun0 ................................................................................ [lun0 block/block1 (rw)]
| | o- iqn.2016-04.com.example:server8 ...................................................................... [Mapped LUNs: 1]
| | o- mapped_lun1 ................................................................................ [lun1 block/block2 (rw)]
| o- luns .......................................................................................................... [LUNs: 2]
| | o- lun0 .............................................................................. [block/block1 (/dev/vgsan/lv_san1)]
| | o- lun1 .............................................................................. [block/block2 (/dev/vgsan/lv_san2)]
| o- portals .................................................................................................... [Portals: 1]
| o- 192.168.23.145:3260 .............................................................................................. [OK]
o- loopback ......................................................................................................... [Targets: 0]
Configuring iSCSI Initiator
- in server7.example.com
- yum -y install iscsi-initiator-utils
- systemctl start iscsi
- systemctl enable iscsi
- vim /etc/iscsi/initiatorname.iscsi
- InitiatorName=iqn.2016-04.com.example:server7
- discover targets at a given IP address
- command is very long to memorize "man iscsiadm" and see the example at the bottom.
- iscsiadm --mode discoverydb --type sendtargets --portal 192.168.23.145 --discover
- login
- command is very long to memorize "man iscsiadm" and see the example at the bottom
- iscsiadm --mode node --targetname iqn.2016-04.com.example:target --portal 192.168.23.145:3260 --login
[root@server7 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.23.145 --discover
192.168.23.145:3260,1 iqn.2016-04.com.example:target
[root@server7 ~]# iscsiadm --mode node --targetname iqn.2016-04.com.example:target --portal 192.168.23.145:3260 --login
Logging in to [iface: default, target: iqn.2016-04.com.example:target, portal: 192.168.23.145,3260] (multiple)
Login to [iface: default, target: iqn.2016-04.com.example:target, portal: 192.168.23.145,3260] successful.
- to check
- yum -y install lsscsi
- lsscsi
[root@server7 ~]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
[2:0:1:0] disk VMware, VMware Virtual S 1.0 /dev/sdb
[3:0:0:0] disk LIO-ORG block1 4.0 /dev/sdc <--iscsi device
- creating filesystem using iscsi device
- mkdir /data
- mkfs.xfs /dev/sdc
- make the filesystem persistent upon boot
- vim /etc/fstab
- /dev/sdc /data xfs _netdev 0 0 <--make sure to put _netdev - network device
- mount /data
[root@server7 ~]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 2.0G 33M 2.0G 2% /data