ISCSI
Setup of Target
Install iscsitarget and configure storage:
sudo apt-get -y install iscsitarget iscsitarget-dkms
make a disk image:
sudo mkdir /var/iscsi_disks
sudo dd if=/dev/zero of=/var/iscsi_disks/<disk_name>.img count=0 bs=1 seek=<size>
Example:
sudo dd if=/dev/zero of=/var/iscsi_disks/zabbix_logs.img count=0 bs=1 seek=100G
Enable ICSI Targeting:
Access the file:
sudo vi /etc/default/iscsitarget
and change SCSITARGET_ENABLE=false to true.
Configure Target iqdn:
sudo vi /etc/iet/ietd.conf
add the following at the end of the file:
Target iqdn.<year>-<month>.<domain>:<any name>
Lun 0 Path=<Path_to.img>,Type fileio
initiator-address <ip.add.re.ss>
incominguser <username> <password>
Example:
Target iqdn.2017-08.tandp-host1:ZabbixLogs
Lun 0 Path=/var/icsi_disks/zabbix_logs.img,Type fileio
initiator-address 192.168.80.201
incominguser zabbix S70r4g3P455w0rd
Restart iscsitarget:
sudo systemctl restart iscsitarget
Check status:
sudo ietadm --op show --tid=1
You should see:
Wthreads=8
Type=0<
QueuedCommands=32
NOPInterval=0
NOPTimeout=0
Client setup and initial configuration
Information in configuring open-iscsi by clients (not to become a storage provider)
Install
apt-get install open-iscsi parted <clippy show="true">TextToCopy</clippy>
This should create your unique initiator name which if you need to configure access control on the iscsi server you can get by
tail -n1 /etc/iscsi/initiatorname.iscsi
Once you know there is a volume available for use with the server being configured use
iscsiadm -m discovery -t sendtargets -p portal.ip.add.ress
NB portal IP address may not be the same address as used for managing the SAN
to get the name of the volume available to the server. This will be in the form of
storage.ip.add.ress:port,1 uniqueinitiatornameofstorage-volumename
exemple
xxx.xxx.xxx.xxx:3260,1 iqn.2005-10.org.freenas.ctl:volumename
Depending on the storage server, the initiator name can be quite long, but you just need to be able to cut and paste parts into the next command:
iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -l
exemple
iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:volumename -p xxx.xxx.xxx.xxx:3260 -l
The iscsi volume should now be available as a disk device to be managed by the OS. Check by
ls /dev/disk/by-path/
The output will tell you what disk device to address e.g.
# ls -l /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root 9 Nov 1 16:38 ip-storage.ip.add.ress:3260-uniqueinitiatornameofstorage-volumename-lun-0 -> ../../sda
where sda is the key element. Using that information create a volume on the drive with parted:
parted /dev/sda
Then create a filesystem as needed
mkfs.ext4 /dev/sda1
(what disk filesystem you use depends on need, but assuming backup etc. is taken care of, EXT4 probably best all-round performance option)
NB if using ext4, the defaults leave 5% of space reserved for root operations. If the volume is for use for data storage, then you should reduce this with
tune2fs -m 1 /dev/sda1
To ensure your iscsi volume is available on reboot
vi /etc/iscsi/iscsid.conf
and set
node.startup = automatic
Then edit the settings for your iscsi node
vi /etc/iscsi/nodes/uniqueinitiatornameofstorage-volumename/ip-storage.ip.add.ress,3260,1/default
and set
node.conn[0].startup = automatic
Note if you only have one iscsi volume on a server, there will only be one nodes subdirectory so Tab autocomplete is your friend.
Now mount the volume (note if this is to extend space in use you may need to mount the volume at a temporary location, move existing data and then remount at the desired permanent location. This best done with the UUID, which got created when the volume did.
mkdir /path/to/mymountpoint
ls -l /dev/disk/by-uuid
systemctl daemon-reload
mount /dev/disk/by-uuid/youruuid /path/to/mymountpoint
Assuming success (best to test you can write to the mounted volume) next make the mount auto remount on reboot by
vi /etc/fstab
and appending a line of the form
UUID=youruuid /path/to/mymountpoint ext4 defaults,relatime,_netdev 0 0
for normal file stores, and
UUID=youruuid /path/to/mymountpoint ext4 defaults,noatime,_netdev 0 0
for backups (where noatime means access times are not recorded, which should preserve the accesstime from when the file was last accessed on the active store).
Where a key option is _netdev, which tells the operating system not to try and mount this volume until the network is up.
Troubleshooting
Logging out of ISCSI sessions
If you need to logout of the iscsi storage to allow changes to the volume etc., unmount it and run
iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -u
To logout of all just run
Delete node
To delete a discovered node run
iscsiadm -m node -o delete -T <iqn>
General information
To see all known nodes
iscsiadm -m node
To see current active sessions
iscsiadm -m session -P 3