Depuis 4 ans maintenant, j'utilise OpenSVC pour gérer mes services sur des serveurs du Cloud Gandi.
Depuis peu je m'intéresse au système de stockage distribué CEPH.
Je vais vous présenter aujourd'hui une façon de gérer ses disques CEPH dans un service OpenSVC
Pré-requis
Nous avons besoin d'un cluster CEPH opérationnel et une clef d'admin déployée (ceph.client.admin.keyring) sur notre serveur de test condor ainsi qu'un fichier de conf ceph.conf
root@condor:/etc/ceph# ls -l ceph.client.admin.keyring -rw-r--r-- 1 root root 63 Feb 8 21:06 ceph.client.admin.keyring root@condor:/etc/ceph# ls -l ceph.conf -rw-r--r-- 1 root root 331 Jan 31 10:18 ceph.conf
Création du service OpenSVC
Nous allons désormais créer un fichier de configuration OpenSVC pour le service flaprdsvc03.flox-arts.net
Ce service s'occupera de gérer un disque CEPH RBD avec un FS EXT4 dans /srv/flaprdsvc03
Voilà le fichier de configuration :
root@condor:/opt/opensvc/etc# cat flaprdsvc03.flox-arts.net.env [DEFAULT] app = FLA comment = FLA SVC PRD service mode = hosted cluster_type = failover service_type = PRD nodes = condor.flox-arts.net autostart_node = condor.flox-arts.net [fs#0] dev = /dev/rbd/rbdpartigsanmdev01/flaprdsvc03_lun001 mnt = /srv/flaprdsvc03 type = ext4 pre_start = /opt/opensvc/extern/ceph-action.py --action map --pool rbdpartigsanmdev01 --lun flaprdsvc03_lun001 post_stop = /opt/opensvc/extern/ceph-action.py --action unmap --pool rbdpartigsanmdev01 --lun flaprdsvc03_lun001
Il ne nous reste plus qu'à créer le script ceph-action.py qui s'occupera pour le démarrage du service :
- de vérifier que l'image RBD CEPH ne possède pas de lock exclusif
- de mapper l'image sur le serveur
- de placer un lock exclusif sur l'image RBD avec comme "cookie" le hostname de la machine
Et pour le stop du service :
- de démapper l'image sur le serveur
- de supprimer le lock exclusif sur l'image RBD
Le script /opt/opensvc/extern/ceph-action.py fait 60 lignes et le voilà disponible ici :
#!/usr/bin/env python2.6 # # Copyright (c) 2015 Florent Monthel# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # import sys import os import socket import optparse import rados import rbd import time import re # Options parser parser = optparse.OptionParser(usage="usage: %prog -a map|unmap -p ceph_pool_name -l ceph_lun_name") parser.add_option("-a", "--action", dest="action", type="string", help="specify action to do [map or unmap]") parser.add_option("-p", "--pool", dest="pool", type="string", help="specify ceph pool name to run on") parser.add_option("-l", "--lun", dest="lun", type="string", help="specify ceph lun name to run on") (options, args) = parser.parse_args() if not options.action or (options.action != "map" and options.action != "unmap") or not options.pool or not options.lun : parser.print_help() sys.exit(1) # Variable hostname_long = socket.gethostname() hostname_short = re.search('^([0-9a-z]+)',socket.gethostname()).group(0) # Connect to cluster cluster = rados.Rados(conffile = '/etc/ceph/ceph.conf') try : cluster.connect() # Pool exists ? if not cluster.pool_exists(options.pool) : print "Pool "+options.pool+" doesn't exist !" sys.exit(1) # Lun exists ? try : ioctx = cluster.open_ioctx(options.pool) with rbd.Image(ioctx,options.lun) as pool_lun : if options.action == 'map' : # Mapping # Lock on LUN on another server ? if pool_lun.list_lockers() and pool_lun.list_lockers()['lockers'][0][1] != hostname_long : print "LUN "+options.lun+" of pool "+options.pool+" is locked by server "+pool_lun.list_lockers()['lockers'][0][1] sys.exit(2) elif not pool_lun.list_lockers() : # No lock pool_lun.lock_exclusive(hostname_long) # Map device if not os.path.exists("/dev/rbd/"+options.pool+"/"+options.lun) : os.system("rbd map "+options.pool+"/"+options.lun) # Test device if not os.path.exists("/dev/rbd/"+options.pool+"/"+options.lun) : print "Unable to map LUN "+options.lun+" of pool "+options.pool+" on server "+hostname_long sys.exit(2) else : sys.exit(0) if options.action == 'unmap' : # Unmapping # Unlock device if pool_lun.list_lockers() and pool_lun.list_lockers()['lockers'][0][1] == hostname_long : pool_lun.break_lock(pool_lun.list_lockers()['lockers'][0][0],hostname_long) # Unmap device if os.path.exists("/dev/rbd/"+options.pool+"/"+options.lun) : os.system("rbd unmap /dev/rbd/"+options.pool+"/"+options.lun) # Test device if os.path.exists("/dev/rbd/"+options.pool+"/"+options.lun) : print "Unable to unmap LUN "+options.lun+" of pool "+options.pool+" from server "+hostname_long sys.exit(2) finally : ioctx.close() finally : cluster.shutdown()
Démarrage et stop du service OpenSVC
Nous pouvons désormais démarrer notre service flaprdsvc03 :
root@condor:/opt/opensvc/etc# /opt/opensvc/etc/flaprdsvc03.flox-arts.net start 21:28:04 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 /opt/opensvc/extern/ceph-action.py --action map --pool rbdpartigsanmdev01 --lun flaprdsvc03_lun001 21:28:13 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 e2fsck -p /dev/rbd/rbdpartigsanmdev01/flaprdsvc03_lun001 21:28:13 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 output: /dev/rbd/rbdpartigsanmdev01/flaprdsvc03_lun001: clean, 12/655360 files, 79664/2621440 blocks 21:28:13 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 mount -t ext4 /dev/rbd/rbdpartigsanmdev01/flaprdsvc03_lun001 /srv/flaprdsvc03
Vérifions que le lock est bien positionné et que le device est bien monté :
root@condor:/opt/opensvc/etc# rbd showmapped id pool image snap device 11 rbdpartigsanmdev01 flaprdsvc03_lun001 - /dev/rbd11
Avons nous un lock sur l'image RBD ?
root@condor:/opt/opensvc/etc# rbd lock list rbdpartigsanmdev01/flaprdsvc03_lun001 There is 1 exclusive lock on this image. Locker ID Address client.58398 condor.flox-arts.net 217.70.189.101:0/1006391
Quel est le statut du service OpenSVC ?
root@condor:/opt/opensvc/etc# /opt/opensvc/bin/svcmon service service container container ip disk fs share app hb sync avail overall name type type status status status status status status status status status status frozen ------- ------- --------- --------- ------ ------ ------ ------ ------ ------ ------ ------ ------- ------ flaprdsvc03.flox-arts.net PRD hosted n/a n/a n/a up n/a n/a n/a n/a up up False
Stoppons désormais le service flaprdsvc03 :
root@condor:/opt/opensvc/etc# /opt/opensvc/etc/flaprdsvc03.flox-arts.net stop 21:34:32 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 umount /srv/flaprdsvc03 21:34:32 INFO FLAPRDSVC03.FLOX-ARTS.NET.FS#0 /opt/opensvc/extern/ceph-action.py --action unmap --pool rbdpartigsanmdev01 --lun flaprdsvc03_lun001
Vérifions que le lock est bien supprimé et que l'image est bien démappée :
root@condor:/opt/opensvc/etc# rbd lock list rbdpartigsanmdev01/flaprdsvc03_lun001 root@condor:/opt/opensvc/etc# rbd showmapped root@condor:/opt/opensvc/etc#
C'est très bien tout ça mais c'est un peu artisanal avec ces directives OpenSVC pre_start et post_stop.
Du coup Christophe VAROQUI a intégré CEPH RBD dans OpenSVC comme il l'avait fait il y a quelques temps pour le Cloud Gandi.
Gestion des snapshots et clones RBD sont au programme mais présentation de tout ça au prochain épisode !
Tutoriel terminé, plus d'informations via :
- OpenSVC via http://www.opensvc.com
- Stockage distribué et saclable CEPH via ceph.com
- Gandi hébergement via http://www.gandi.net/hebergement
Bonjour,
j'ai crée un fichier de configuration OpenSVC pour un service mais par contre j’utilise Linux LVM comme système de stockage et quand j'essaye de demander le service en utilisant la commande ça ne marche pas.
Merci