iSCSI (internet Small Computer System Interface) is common way to export storage to a client in enterprise environments (e.g. Clustering with DRBD). In this example, I'll show how to install the iscsi-server and map the exportet LUN to the client.
I'm assuming you have a clean and updated version of CentOS 7.3 installed both on client the client and the server.
My server's ip: 172.31.10.34
My client's ip: 172.31.10.35
We'll start by configuring the server.
First we have to install the package 'targetcli'. This utility is used for all the configuration done.
The other option is 'fileio' which means that we are going to export a storage file (e.g. /storage/iscsi.img).
I'll be configuring a target using fileio.
Before exporting, we need to assign a iqn (iSCSI Qualified Name) to the host and add a target portal group. Format needs to be iqn:tpg.
So first we create our initial LUN.
The client is quite simple. First install the iscsi-initiator
/etc/iscsi/iscsid.conf. Edit the following lines
We will first get the iSCSI's devicename by running
Make the filesystem on it and mounting it can be done the ususal way.
Feel free to comment and / or suggest a topic.
I'm assuming you have a clean and updated version of CentOS 7.3 installed both on client the client and the server.
My server's ip: 172.31.10.34
My client's ip: 172.31.10.35
We'll start by configuring the server.
First we have to install the package 'targetcli'. This utility is used for all the configuration done.
Enable the service to start on boot and start it now.
sudo yum -y install targetcli
[archy@storage01 ~]$
Start the configuration by running
systemctl enable target.service && sudo systemctl start target.service
[archy@storage01 ~]$ sudo
Before configuring the iSCSI-Target I want to mention that there are two options to allocate the storage. The first options is 'blockio' which means that it exports a device (e.g. /dev/vg/lvm_volume1).
targetcli
[archy@storage01 ~]$ sudo
The other option is 'fileio' which means that we are going to export a storage file (e.g. /storage/iscsi.img).
I'll be configuring a target using fileio.
targetcli> backstores/fileio/ create iscsi-lun0 /storage/iscsi-lun0 300M
This creates a 300MB unallocated file with the path '/storage/iscsi-lun0'.Before exporting, we need to assign a iqn (iSCSI Qualified Name) to the host and add a target portal group. Format needs to be iqn:tpg.
From here we can add / edit / delete the acls and portals.
targetcli>
iscsi/ create iqn.2017-08.lan.archyslife:iscsi-lun0
targetcli>
cd iscsi/iqn.2017-08.lan.archyslife:iscsi-lun0/tpg1
So first we create our initial LUN.
Now create an acl for our client allowing it to map the iscsi-lun.
targetcli>
luns/ create /backstores/fileio/iscsi-lun0
There is also the option to add a username and password to the lun by running
targetcli>
acls/ create iqn.2017-08.lan.archyslife:client
Now since CentOS 7.1 there is usually a standard portal set pointing to '0.0.0.0:3260'. I prefer to delete that one and create my own. I'm using the IP-Address of my client (172.31.10.35). along with the standard iSCSI-Port (3260).
targetcli>
acls/iqn.2017-08.lan.archyslife:client/ set auth userid=archy
targetcli>
acls/iqn.2017-08.lan.archyslife:client/ set auth password=your_secret_password
Add the iSCSI-Port to the firewall settings and make them persistent.
targetcli>
portals/ create ip_address=172.31.10.35 ip_port=3260
targetcli>
exit
That concludes the server's setup.
firewall-cmd --zone=internal --add-service=3260/tcp --permanent
sudo
[archy@storage01 ~]$
firewall-cmd --reload
sudo
[archy@storage01 ~]$
The client is quite simple. First install the iscsi-initiator
Next, edit the file /etc/iscsi/initatorname.iscsi and replace the standard value with the initatorname you set in your lun-acl above.
yum -y install iscsi-initator-utils
sudo
[archy@client ~]$
InitiatorName=iqn.2017-08.lan.archyslife:client
If you have setup user and password in the config for your lun, you'll have to enter these in the/etc/iscsi/iscsid.conf. Edit the following lines
node.session.auth.authmethod = CHAP
node.session.auth.username = archy
node.session.auth.password = your_secret_password
Save and edit. Now start the iscsi.service (not iscsid.service)Run iscsiadm to discover and login to your discovered target.
systemctl start iscsi
sudo
[archy@client ~]$
Now that the target was discovered, you can login to it by executing
iscsiadm --mode discovery --type sendtargets --portal 172.31.10.34
sudo
[archy@client ~]$
Your iSCSI-LUN is now mounted to your machine, but there is no filesystem on it whatsoever.
iscsiadm --mode node --targetname iqn.2017-08.lan.archyslife:iscsi-lun0 --portal 172.31.10.34 --login
sudo
[archy@client ~]$
We will first get the iSCSI's devicename by running
The disk with it says your lun on the model is the target. In my case it is /dev/sdb.
lsblk --scsi
[archy@client ~]$
Make the filesystem on it and mounting it can be done the ususal way.
That completes the iSCSI-Target and Initiator setup.
mkfs.xfs /dev/sdb
sudo
[archy@client ~]$
mount /dev/sdb /mnt
sudo
[archy@client ~]$
Feel free to comment and / or suggest a topic.
Comments
Post a Comment