Howto

High-Availability Storage con GlusterFS su Debian 8

GlusterFS

GlusterFS is free and open source software

 

gluster
gluster

Questo tutorial,  mostra come impostare uno storage ad alta disponibilità con due server di archiviazione (Debian Jessie) che utilizza GlusterFS. Ogni server di archiviazione sarà uno specchio dell’altro server di storage e file verranno replicati automaticamente su entrambi i nodi. Il sistema client (Debian ) sarà in grado di accedere alla memoria come se fosse un file system locale. GlusterFS è un file system cluster in grado di scalare a diversi PETA-byte.

 

1 Note Preliminari

In questo tutorial l, si useranno tre sistemi, 2 server e un client.

  • server1.example.com: IP address 192.168.1.100 (server)
  • server2.example.com: IP address 192.168.1.101 (server)
  • client1.example.com: IP address 192.168.1.102 (client)

Tutte e tre le macchine necessitano di poter risolvere i nomi delle altre macchine, Se questo non fosse possibile attraverso server DNS  bisognerà editare /etc/host così come riportato di seguito su tutti e tre i server:

nano /etc/hosts

127.0.0.1 localhost
192.168.1.100 server1.example.com server1
192.168.1.101 server2.example.com server2
192.168.1.102 client1.example.com client1


# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

E 'anche possibile utilizzare gli indirizzi IP invece dei nomi host nella seguente configurazione. 
Se si preferisce utilizzare gli indirizzi IP, non c'è bisogno di preoccuparsi se i nomi host può essere risolto o meno.)

2 “Setting up” GlusterFS Servers

server1.example.com/server2.example.com:

 

L’ultima versione di GlusterFS è disponibile come Debian package da gluster.org . La puoi installare cosi’ …

wget -O – http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/rsa.pub | apt-key add –

dopo aggiungi il repository di  GlusterFS

echo deb http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/Debian/jessie/apt jessie main > /etc/apt/sources.list.d/gluster.list

e pou update del repository .

apt-get update

Ora possiamo installare GlusterFS

apt-get -y install glusterfs-server

poi con il comando

glusterfsd –version

vedrai la versione che hai appena installata

root@server1:/# glusterfsd –version
glusterfs 3.7.9 built on Mar 23 2016 05:24:49
Repository revision: git://git.gluster.com/glusterfs.git
Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
root@server1:/#

Se stai utilizzando il Firewall assicurati che le seguenti porte siano aperte sul : server1.example.com and server2.example.com.

porta 111, 24007, 24008, 24009-(24009 + numero di “bricks” attraverso  i volumi)

GlusterFS deve memorizzare i datiin una  directory/datai sui server. Questo percorso può essere una directory normale se si dispone di un piccolo sistema o si utilizzerà una partizione separata del disco rigido e montata come /data.

Eseguire su entrambi i server:

mkdir /data

per creare la directory.

Quindi, dobbiamo aggiungere server2.example.com al pool di storage trusted (si ricorda che sto correndo tutti i comandi di configurazione del GlusterFS fromserver1.example.com, ma si può anche eseguirli dal server2.example.com perché la configurazione è repliacta tra i nodi GlusterFS – solo assicurarsi di utilizzare i nomi host o gli indirizzi IP corretti):

server1.example.com:

Sul  server1.example.com, esegui

gluster peer probe server2.example.com

root@server1:/# gluster peer probe server2.example.com
peer probe: success.
root@server1:/#

Lo status dei  trusted storage pool dovrebbe essere similke a questo:

gluster peer status

root@server1:/# gluster peer status
Number of Peers: 1

Hostname: server2.example.com
Uuid: 0f7ee46c-6a71-4a31-91d9-6076707eff95
State: Peer in Cluster (Connected)
root@server1:/#

 

Poi creiamo la condivisione battezzandola testvol con due repliche (si prega di notare che il numero di repliche è uguale al numero di server in questo caso perché vogliamo creare mirroring) sul server1.example.com e server2.example.com nel /data/testvol (questo verrà creato se non esiste):

gluster volume create testvol replica 2 transport tcp server1.example.com:/data/testvol server2.example.com:/data/testvol force

root@server1:/# gluster volume create testvol replica 2 transport tcp server1.example.com:/data/testvol server2.example.com:/data/testvol force
volume create: testvol: success: please start the volume to access data
root@server1:/#

Start del  volume:

gluster volume start testvol

root@server1:/# gluster volume start testvol
volume start: testvol: success
root@server1:/#

..partito con successo … e’ UP

ma potrebbe anche non essere andato tutto a buon fine ..

root@server1:~# gluster volume start testvol
Starting volume testvol has been unsuccessful
root@server1:~#

 

in questo caso ..

server1.example.com/server2.example.com:

netstat -tap | grep glusterfsd

su ambedue i server

avrai un output come questo..

root@server1:/# netstat -tap | grep glusterfsd
tcp 0 0 *:49152 *:* LISTEN 8007/glusterfsd
tcp 0 0 server1.example.c:65533 server1.example.c:24007 ESTABLISHED 8007/glusterfsd
tcp 0 0 server1.example.c:49152 server2.example.c:65531 ESTABLISHED 8007/glusterfsd
tcp 0 0 server1.example.c:49152 server1.example.c:65532 ESTABLISHED 8007/glusterfsd
tcp 0 0 server1.example.c:49152 server1.example.c:65531 ESTABLISHED 8007/glusterfsd
tcp 0 0 server1.example.c:49152 server2.example.c:65526 ESTABLISHED 8007/glusterfsd
root@server1:/#

 

… tutto e’ ok ma non hai nessun tipo di output …

root@server2:~# netstat -tap | grep glusterfsd
root@server2:~#

…fai restart del demone di  GlusterFS sul server corrispondente (server1.example.com in questo caso):

server2.example.com:

service glusterfs-server restart

e ricontrolla l’output

netstat -tap | grep glusterfsd

… di nuovo su quel server, dovresti avere qualcosa di simile a questo:

root@server2:/# netstat -tap | grep glusterfsd
tcp 0 0 *:49152 *:* LISTEN 7852/glusterfsd
tcp 0 0 server2.example.c:49152 server2.example.c:65532 ESTABLISHED 7852/glusterfsd
tcp 0 0 server2.example.c:49152 server1.example.c:65526 ESTABLISHED 7852/glusterfsd
tcp 0 0 server2.example.c:49152 server2.example.c:65525 ESTABLISHED 7852/glusterfsd
tcp 0 0 server2.example.c:65533 server2.example.c:24007 ESTABLISHED 7852/glusterfsd
tcp 0 0 server2.example.c:49152 server1.example.c:65524 ESTABLISHED 7852/glusterfsd
root@server2:/#

 

Ora ritorna sul erver1.example.com:

server1.example.com:

Puoi controllare lo status del volume con il comando

gluster volume info

root@server1:/# gluster volume info

Volume Name: testvol
Type: Replicate
Volume ID: 3fc9af57-ca56-4a72-ad54-3d2ea03e5883
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data/testvol
Brick2: server2.example.com:/data/testvol
Options Reconfigured:
performance.readdir-ahead: on
root@server1:/#

di default , tutti i client possono connettersi al volume. Ma se tu vuoi garantire l’accesso solo a client1.example.com (= 192.168.1.102) devi eseguire:

gluster volume set testvol auth.allow 192.168.1.102

root@server1:/# gluster volume set testvol auth.allow 192.168.1.102
volume set: success
root@server1:/#

Si prega di notare che è possibile utilizzare i caratteri jolly per gli indirizzi IP (come 192.168. *) E che è possibile specificare più indirizzi IP separati da virgola (ad esempio 192.168.1.102,192.168.1.103).

L’info sul volume dovrebbe essere cambiato… controlliamo:

gluster volume info

root@server1:/# gluster volume info

Volume Name: testvol
Type: Replicate
Volume ID: 3fc9af57-ca56-4a72-ad54-3d2ea03e5883
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data/testvol
Brick2: server2.example.com:/data/testvol
Options Reconfigured:
auth.allow: 192.168.1.102
performance.readdir-ahead: on
root@server1:/#

3 Setting up del Client per GlusterFS

client1.example.com:

Prima di tutto dobbiamo aggiungere la chiave pubblica del repository gluster.org

wget -O – http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/rsa.pub | apt-key add –

poi aggiungere il GlusterFS repository (tutto su una sola linea)

echo deb http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.9/Debian/jessie/apt jessie main > /etc/apt/sources.list.d/gluster.list

e effettuate update del repository list

apt-get update

Ora possiamo installare il client per GlusterFS come segue:

apt-get -y install glusterfs-client

Ora possiamo creare la seguente directory:

mkdir /mnt/glusterfs

Fatto!!! Ora possiamo montare il GlusterFS filesystem su /mnt/glusterfs con il seguente comando:

mount.glusterfs server1.example.com:/testvol /mnt/glusterfs

(Invece di server1.example.com è possibile anche utilizzare server2.example.com nel comando sopra!)

Si dovrebbe avere  un output del genere

mount

root@client1:/# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=125556,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,relatime,size=204220k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=23,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
server1.example.com:/testvol on /mnt/glusterfs type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
root@client1:/#

.. e …

df -h

root@client1:/# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 57G 1.1G 53G 2% /
udev 10M 0 10M 0% /dev
tmpfs 200M 4.6M 195M 3% /run
tmpfs 499M 0 499M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 499M 0 499M 0% /sys/fs/cgroup
server1.example.com:/testvol 57G 21G 34G 39% /mnt/glusterfs
root@client1:/#

Instead of mounting the GlusterFS share manually on the client, you could modify /etc/fstab so that the share gets mounted automatically when the client boots.

Invece di montare i GlusterFS share manualmente sul client, è possibile modificare /etc/ fstab in modo che la quota venga  montata automaticamente all’avvio del client.

apri /etc/fstab e aggiungi la seguente linea:

nano /etc/fstab

[...]
server1.example.com:/testvol /mnt/glusterfs glusterfs defaults,_netdev 0 0

(ricordo che questa operazione la puoi fare sia server1.example.com o sul server2.example.com

per testare che e’ tutto ok, fai reboot del client:

reboot

Dopo il reboot, dovresti trovare la condivisione nell’output …

df -h

… e…

mount

 

4 Testiamo la replicazione fatta da GlusterFS

Ora creiamo alcuni file di test sulla condivisione attiva di GlusterFS

client1.example.com:

touch /mnt/glusterfs/test1
touch /mnt/glusterfs/test2

e andiamo a controllare la loro presenza sia su server1.example.com and server2.example.com, 

 

server1.example.com/server2.example.com:

ls -l /data/testvol

root@server1:/# ls -l /data/testvol/
total 0
-rw-r–r– 2 root root 0 Mar 23 2016 test1
-rw-r–r– 2 root root 0 Mar 23 2016 test2

Ora spegniamo il server  server1.example.com e aggiungiamo e/o cancelliamo dei file sulla cartella share di GlusterFS sul  client1.example.com.

server1.example.com:

shutdown -h now

client1.example.com:

touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2

 

I cambiamenti dovrebbero essere visibili nella directory /data/testvol sul server  server2.example.com:

server2.example.com:

ls -l /data/testvol

root@server2:/# ls -l /data/testvol
total 8
-rw-r–r– 2 root root 0 Mar 23 08:06 test1
-rw-r–r– 2 root root 0 Mar 23 08:09 test3
-rw-r–r– 2 root root 0 Mar 23 08:09 test4
root@server2:/#

Facciamo ripartire server1.example.com e controlliamo la directory /data:

server1.example.com:

ls -l /data/testvol

root@server1:/# ls -l /data/testvol
total 0
-rw-r–r– 2 root root 0 Mar 23 08:06 test1
-rw-r–r– 2 root root 0 Mar 23 08:09 test3
-rw-r–r– 2 root root 0 Mar 23 08:09 test4
root@server1:/#

Come possiamo vedere, server1.example.com sincronizzata automaticamente le modifiche. Nel caso in cui non sia avvenuta la sincronizzazione , possiamo risolvere facilmente il problema, tutto quello che dobbiamo fare è richiamare un comando di lettura sulla quota GlusterFS su client1.example.com, ad es .:

client1.example.com:

ls -l /mnt/glusterfs/

root@client1:/# ls -l /mnt/glusterfs/
total 0
-rw-r–r– 1 root root 0 Mar 23 08:06 test1
-rw-r–r– 1 root root 0 Mar 23 08:09 test3
-rw-r–r– 1 root root 0 Mar 23 08:09 test4
root@client1:/#

 

Il tutoria e apparso, su https://www.howtoforge.com/tutorial/high-availability-storage-with-glusterfs-on-debian-8-with-two-nodes/, e’ molto chiaro e le potenzialità di questa soluzione sono di tipo professionale. Ho cercato di tradurlo nel miglio modo possibile……. Ho testato GlusterFS e devo dire che funziona egregiamente !!

G.P.