Hetzner Storage box iSCSI export

Just a note on the side. If you are using the Hetzner Storage boxes you can use iSCSI to export them to other servers, even accross the internet thru a vpn. performance would no be that greate but it works.

based on my iSCSI howto i just unmounted my /backup dir and mounted the Storagebox instead and it all worked like a charm..

root@atlas01 /var/log # df -h /backup/Filesystem Size Used Avail Use% Mounted on //u147976.your-storagebox.de/backup 100G 220K 100G 1% /backup root@atlas01 /var/log # mount |grep backup//u157976.your-storagebox.de/backup on /backup type cifs (rw,relatime,vers=1.0,cache=strict,username=u157976,domain=PUBLICBACKUP286,uid=0,noforceuid,gid=0,noforcegid,addr=2a01:04f8:0b16:3000:0000:0000:0000:0067,unix,posixpaths,serverino,acl,rsize=1048576,wsize=65536,actimeo=1) root@atlas01 /var/log #

Posted in commandline, linux, storage | Leave a comment

Mount an iSCSI Target with Linux (Debian)

now part two. we have to mount the LUN’s on a other computer to test it.

apt-get install open-iscsi

edit the file /etc/iscsi/iscsid.conf, set node.startup = automatic

then we restart the whole thing

service open-iscsi restart

we look if we can see something..

iscsiadm -m discovery -t sendtargets -p SERVERIP

we note the ip and the targetname… then we try to login.

iscsiadm –mode node –targetname TARGETNAME –portal SERVERIP:3260 –login

it fails.. of course we didnt authenticated ourselfe.

update –name node.session.auth.authmethod –value=CHAP

iscsiadm -m node –targetname “TARGETNAME” –portal “SERVERIP:3260” –op=update –name node.session.auth.username –value=USERNAME

iscsiadm -m node –targetname “TARGETNAME” –portal “SERVERIP:3260” –op=update –name node.session.auth.password –value=PASSWORD

now a restart of the serive to make sure everthing runs fine after a reboot.

we can now see the 3 disks by typing fdisk -l

root@kvm02:/home/kvm# fdisk -l Disk /dev/vda: 8 GiB, 8589934592 bytes, 16777216 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x566539ac Device Boot Start End Sectors Size Id Type/dev/vda1 * 2048 499711 497664 243M 83 Linux /dev/vda2 501758 16775167 16273410 7,8G 5 Extended /dev/vda5 501760 16775167 16273408 7,8G 8e Linux LVM Disk /dev/mapper/kvm01–vg-root: 7,4 GiB, 7935623168 bytes, 15499264 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/kvm01–vg-swap_1: 376 MiB, 394264576 bytes, 770048 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes

thats it.. have fun!

Posted in commandline, linux, storage | Leave a comment

Export an iSCSI Target with linux

As some already know I work voluntarily at the realcomputer e.V.
We have got a Bladecenter, unfortunately without hard drives so I try with another linux machine to export a few iSCSI targets to provide the blades with some storage.

Because there are no exact specifications I use as usual debian.

install the necesary packages..

apt-get install iscsitarget

set „ISCSITARGET_ENABLE“ to true in the file /etc/default/iscsitarget.

Create some LUN

I think that the term “LUN” is widely used and can be seen as standard for Virtual disks for an operating system.

in my case i have a disk mounted as /backup wich still has some space so i create /backup/lun

mkdir /luns
cd /luns

there we create our lun’s

dd if=/dev/zero of=storagelun0 count=0 obs=1 seek=10G
dd if=/dev/zero of=storagelun1 count=0 obs=1 seek=10G
dd if=/dev/zero of=storagelun2 count=0 obs=1 seek=10G

We have created tree Images wich contain 10G each.

Name of the target

The name of the respective target must be unique in your environment and you should at least half-way to the convention. In this case, “iqn” stands for “iSCSI Qualified Name” and should be used as well. The second block consists of year and month (YYYY-MM), in which the domain is valid and can be omitted. In the third place is the converted domain name (instead of example.at> at.example) and behind it a name is freely selectable.

then edit the file /etc/iet/ietd.conf

Target iqn.local.example:storage.sys1
IncomingUser BENUTZERNAME PASSWORT
Lun 0 Path=/luns/storagelun0,Type=fileio,ScsiId=lun0,ScsiSN=lun0
Lun 1 Path=/luns/storagelun1,Type=fileio,ScsiID=lun1,ScsiSN=lun1
Lun 2 Path=/luns/storagelun2,Type=fileio,ScsiID=lun2,ScsiSN=lun2

Please note that the Password has to be at least of 9 chars leanght.

service iscsitarget stop && service iscsitarget start

thats it. if theres no errors everything is fine. we continue with part 2 how to use them on debian

Posted in commandline, linux, storage | Leave a comment

Kill processes older than $giventime

On out ssh jumpserver we sometimes have ssh processes that dont want to die after they are used. over the time they cloak the system.

i found out that the GNU Killall just do the job for me.

“killall –older-than 1d ssh” would do the trick 😉

this kills all ssh processes thats older than 1 day

Posted in commandline, linux | Leave a comment

Little Docker Swarm walkthru

I’ll try to setup a two node docker swarm. quiet easy and done in 10 minutes. i used 2 ubuntu 16.4 64 bit vm’s.

HostnameExternal IPInternal IP
scw-5fd012212.47.239.15310.2.37.217
scw-095a80212.47.240.21810.2.222.81

i also assume u installed docker.

you need to decide which one will be the manager.

i choose scw-5fd012. on that node i enter a

root@scw-5fd012:~# docker swarm init --advertise-addr 10.2.37.217
Swarm initialized: current node (5lpm87bmugszxrx920k2zmx6k) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-4mqfnpv0kthd2of2rc7ji9qj5mhlry2o1ktmpofn80hzmopd1d-913n0w2l4x3if7dog5emgw781 \
10.2.37.217:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Thats it!
the docker swarm is created and scw-5fd012 is the manager.

on scw-095a80 i just enter a

docker swarm join --token SWMTKN-1-4mqfnpv0kthd2of2rc7ji9qj5mhlry2o1ktmpofn80hzmopd1d-913n0w2l4x3if7dog5emgw781 10.2.37.217:2377

and i have my docker swarm set up

on the master i can check if everyhting is working with a simple

root@scw-5fd012:~# docker node ls                                                                                            
ID                           HOSTNAME    STATUS  AVAILABILITY  MANAGER STATUS                                                
5lpm87bmugszxrx920k2zmx6k *  scw-5fd012  Ready   Active        Leader                                                        
f0ogny4uxy5zg956hf8m16eka    scw-095a80  Ready   Active                                                                      
root@scw-5fd012:~#                                                                                                           
Posted in commandline, linux | Tagged , , | Leave a comment

delete all msg in the postfix queue

just type a simple “postsuper -d ALL” and they are gone 😉

Posted in commandline, linux, postfix, snipped | Leave a comment

Bash infinite loop

#!/bin/bash
while :
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

This is a loop that will forever print “Press [CTRL+C] to stop..”. Please note that : is the null command. The null command does nothing and its exit status is always set to true. You can modify the above as follows to improve the readability:

#!/bin/bash
while true
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

A single-line bash infinite while loop syntax is as follows:

 while :; do echo 'Hit CTRL+C'; sleep 1; done

OR

 while true; do echo 'Hit CTRL+C'; sleep 1; done

Bash for infinite loop example

#!/bin/bash
 
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
done

How Do I Escape the Loop?

A for or while loop may be escaped with a break statement when certain condition is satisfied:

 ### for loop example ###
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done

OR

 ### while loop example ###
while :
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done
Posted in commandline, linux, snipped | Tagged | Leave a comment

How to execute a command whenever a file changes?

while inotifywait -e close_write myfile.py; do ./myfile.py; done

or

inotifywait -q -m -e close_write myfile.py |
while read -r filename event; do
  ./myfile.py         # or "./$filename"
done

The first snippet is simpler, but it has a significant downside: it will miss changes performed while inotifywait isn’t running (in particular while myfile is running). The second snippet doesn’t have this defect.

Posted in commandline, linux, snipped | Leave a comment

sed replace word / string syntax

The syntax is as follows:
sed -i 's/old-word/new-word/g' *.txt

GNU sed command can edit files in place (makes backup if extension supplied) using the -i option. If you are using an old UNIX sed command version try the following syntax:

sed 's/old/new/g' input.txt > output.txt

Posted in commandline, linux, snipped | Leave a comment

How can I find the oldest file in a directory tree

find -type f -printf '%T+ %p\n' | sort | head -n 1
Posted in commandline, linux, snipped | Leave a comment