ISCSI: Difference between revisions
No edit summary |
|||
(11 intermediate revisions by 3 users not shown) | |||
Line 12: | Line 12: | ||
Example: | Example: | ||
< | <pre>sudo dd if=/dev/zero of=/var/iscsi_disks/zabbix_logs.img count=0 bs=1 seek=100G </pre> | ||
Enable ICSI Targeting: | Enable ICSI Targeting: | ||
Line 61: | Line 61: | ||
Install | Install | ||
<pre>apt-get install open-iscsi parted</pre> | <pre>apt-get install open-iscsi parted </pre> | ||
This should create your unique initiator name which if you need to configure access control on the iscsi server you can get by | This should create your unique initiator name which if you need to configure access control on the iscsi server you can get by | ||
<pre>tail -n1 /etc/iscsi/initiatorname.iscsi</pre> | <pre>tail -n1 /etc/iscsi/initiatorname.iscsi</pre> | ||
Give zabbix user permissions to run command '''iscsiadm''' for monitoring. Open /etc/sudoers with: | |||
<pre>export EDITOR=vim | |||
visudo</pre> | |||
And add this line: | |||
<pre>zabbix ALL=NOPASSWD: /usr/bin/iscsiadm</pre> | |||
Add these lines to '''/etc/zabbix/zabbix_agentd.conf''' | |||
<pre>UserParameter=iscsi.discovery,l=$(sudo iscsiadm -m node | awk '{print $2}');echo -n '{"data":[';for i in ${l};do echo -n "{\"{#VOLNAME}\": \"$i\"},";done|sed -e 's:\},$:\}:';echo -n ']}'; | |||
UserParameter=iscsi.check.connected[*],sudo iscsiadm -m session | cut -d' ' -f4 | grep -Fxq $1 && echo 1 || echo 0 | |||
UserParameter=iscsi.check.mounted[*],grep -q `ls -l /dev/disk/by-path/ | grep $1"-lun-0 ->" | tail -c 4` /proc/mounts && echo 1 || echo 0</pre> | |||
And restart zabbix-agent | |||
<pre>systemctl restart zabbix-agent</pre> | |||
Once you know there is a volume available for use with the server being configured use | Once you know there is a volume available for use with the server being configured use | ||
Line 76: | Line 91: | ||
'''exemple''' <pre>xxx.xxx.xxx.xxx:3260,1 iqn.2005-10.org.freenas.ctl:volumename</pre> | '''exemple''' <pre>xxx.xxx.xxx.xxx:3260,1 iqn.2005-10.org.freenas.ctl:volumename</pre> | ||
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: | 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 to login: | ||
<pre>iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -l</pre> | <pre>iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -l</pre> | ||
Line 112: | Line 127: | ||
<pre>mkdir /path/to/mymountpoint | <pre>mkdir /path/to/mymountpoint | ||
ls -l /dev/disk/by-uuid | ls -l /dev/disk/by-uuid | ||
mount /dev/disk/by-uuid/youruuid /path/to/mymountpoint</pre> | mount /dev/disk/by-uuid/youruuid /path/to/mymountpoint</pre> | ||
Line 125: | Line 139: | ||
Where a key option is _netdev, which tells the operating system not to try and mount this volume until the network is up. | Where a key option is _netdev, which tells the operating system not to try and mount this volume until the network is up. | ||
===Troubleshooting=== | When /etc/fstab is modified a service reload is needed so the new changes are seen. Less needed when just adding a new line, more needed when removing/modifying an existing one so the OS doesn't try to remount an old configuration. | ||
<pre>systemctl daemon-reload</pre> | |||
===Troubleshooting and Tips=== | |||
====Logging out of ISCSI sessions==== | ====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 | If you need to logout of the iscsi storage to allow changes to the volume etc., unmount it and run | ||
<pre>iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -u</pre> | <pre>iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -u</pre> | ||
====Logout all sessions==== | |||
<pre>iscsiadm --mode node --logoutall=all</pre> | |||
====Login all known nodes==== | |||
<pre>iscsiadm --mode node --loginall=all</pre> | |||
====Delete node==== | ====Delete node==== |
Latest revision as of 08:45, 24 May 2023
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
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
Give zabbix user permissions to run command iscsiadm for monitoring. Open /etc/sudoers with:
export EDITOR=vim visudo
And add this line:
zabbix ALL=NOPASSWD: /usr/bin/iscsiadm
Add these lines to /etc/zabbix/zabbix_agentd.conf
UserParameter=iscsi.discovery,l=$(sudo iscsiadm -m node | awk '{print $2}');echo -n '{"data":[';for i in ${l};do echo -n "{\"{#VOLNAME}\": \"$i\"},";done|sed -e 's:\},$:\}:';echo -n ']}'; UserParameter=iscsi.check.connected[*],sudo iscsiadm -m session | cut -d' ' -f4 | grep -Fxq $1 && echo 1 || echo 0 UserParameter=iscsi.check.mounted[*],grep -q `ls -l /dev/disk/by-path/ | grep $1"-lun-0 ->" | tail -c 4` /proc/mounts && echo 1 || echo 0
And restart zabbix-agent
systemctl restart zabbix-agent
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 to login:
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 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.
When /etc/fstab is modified a service reload is needed so the new changes are seen. Less needed when just adding a new line, more needed when removing/modifying an existing one so the OS doesn't try to remount an old configuration.
systemctl daemon-reload
Troubleshooting and Tips
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
Logout all sessions
iscsiadm --mode node --logoutall=all
Login all known nodes
iscsiadm --mode node --loginall=all
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