informatique:systeme:ha:ceph

Ceci est une ancienne révision du document !


Ceph

Cette méthodologie décris la mise en place d'un cluster de 3 serveurs.

Schéma réseau

Schéma cluster Ceph

  • Les 3 serveurs doivent posséder 2 disques SSD (64Mo minimum) en RAID1 pour le système et les journaux Ceph et deux autres disques (SATA 2To par exemple) pour les données du cluster
  • L'OS des serveurs doit être installé sur un disque utilisant LVM. Partitionnement proposé :
    • /dev/sda
      • /dev/sda1 : Type Linux raid auto, tout l'espace disque disponible
    • /dev/sdb
      • /dev/sdb1 : Type Linux raid auto, tout l'espace disque disponible
    • /dev/sdc : Disque OSD Ceph 1, xfs (formatage durant la procédure)
    • /dev/sdd : Disque OSD Ceph 2, xfs (formatage durant la procédure)
    • /dev/md0 (RAID 1 logiciel de /dev/sda1 et /dev/sdb1) : PV LVM
    • vg_$( hostname -s ) : VG LVM contenant le PV /dev/md0
      • LV root : 4Go, ext4 monté dans /
      • LV tmp : 1Go, ext4 monté dans /tmp
      • LV var : 5Go, ext4 monté dans /var
      • LV swap : 2Go, utilisé en SWAP
      • LV ceph : 30Go, xfs monté dans /var/lib/ceph. La méthodologie du formatage de ce LV est expliqué plus loin.
  • Les 3 serveurs doivent être installés sur Debian Wheezy (architecture amd64)
  • L'authentification par clé SSH entre les serveurs doit être en place pour l'utilisateur root
  • Le nom court des serveurs (exemple : ceph1) doit est connu des serveurs. Vous pouvez simplement mettre dans votre fichier /etc/hosts :
    192.168.0.1  ceph1
    192.168.0.2  ceph2
    192.168.0.3  ceph3
  • Mise en place du dépôt Ceph :
    echo "deb http://ceph.com/debian-dumpling/ wheezy main" > /etc/apt/sources.list.d/ceph.list
    gpg --keyserver pgpkeys.mit.edu --recv-key 7EBFDD5D17ED316D
    gpg -a --export 7EBFDD5D17ED316D|apt-key add -
    apt-get update
  • Création du LV ceph, formatage et montage :
    lvcreate -nceph -L30G vg_`hostname -s`
    mkfs.xfs -n size=64k /dev/vg_$( hostname -s )/ceph
    echo "/dev/mapper/vg_$( hostname -s )-ceph /var/lib/ceph xfs rw,noexec,nodev,noatime,nodiratime,inode64 0 0" >> /etc/fstab
    mount -a
  • Installation de Ceph :
    apt-get install ceph
  • Mise en place des disques OSD :
    mkdir /var/lib/ceph/osd/ceph-0 -p
    mkdir /var/lib/ceph/osd/ceph-1 -p
    mkfs.xfs -f -n size=64k /dev/sdc
    mkfs.xfs -f -n size=64k /dev/sdd
    echo "/dev/sdc /var/lib/ceph/osd/ceph-0 xfs rw,noexec,nodev,noatime,nodiratime,inode64 0 0" >> /etc/fstab
    echo "/dev/sdd /var/lib/ceph/osd/ceph-1 xfs rw,noexec,nodev,noatime,nodiratime,inode64 0 0" >> /etc/fstab
    mount -a
L'ID des OSD (ceph-X = osd.X) dépend du serveur installé. Ce référer au schéma du cluster Ceph.
  • Mettre en place le fichier de configuration principale /etc/ceph/ceph.conf sur les trois serveurs (fichier identique) :
    [global]
            fsid = db22d697-03f5-4122-9f81-8c08ec680fe4
            auth cluster required = cephx
            auth service required = cephx
            auth client required = cephx
            # We may loose one server
            mon osd full ratio = 0.66
            # We may be able to loose two servers
            mon osd nearfull ratio = 0.33
    
    [mon]
            mon initial members = a,b,c
    
    [mon.a]
            host = ceph1
            mon addr = 192.168.0.1
    
    [mon.b]
            host = ceph2
            mon addr = 192.168.0.2
    
    [mon.c]
            host = ceph3
            mon addr = 192.168.0.3
    
    [osd]
            osd journal size = 10000
            osd journal = /var/lib/ceph/journal/$cluster-$id
    
    [osd.0]
            host = ceph1
    [osd.1]
            host = ceph1
    [osd.2]
            host = ceph2
    [osd.3]
            host = ceph2
    [osd.4]
            host = ceph3
    [osd.5]
            host = ceph3

Remarque : Le fsid peut-être généré avec la commande uuidgen (paquet Debian uuid-runtime).

Configuration des monitors

  • Sur ceph1 :
    mkdir -p /var/lib/ceph/mon/ceph-a
    ceph-authtool --create-keyring  /etc/ceph/ceph.client.admin.keyring --gen-key -n client.admin
    ceph-authtool --create-keyring /var/lib/ceph/mon/ceph-a/keyring --gen-key -n mon.
    cp -a /var/lib/ceph/mon/ceph-a/keyring /etc/ceph/ceph.mon.a.keyring
    cat /etc/ceph/ceph.client.admin.keyring >> /var/lib/ceph/mon/ceph-a/keyring
    ceph-authtool /var/lib/ceph/mon/ceph-a/keyring -n client.admin --cap mds 'allow' --cap osd 'allow *' --cap mon 'allow *'
    ceph-mon -i a -f -c /etc/ceph/ceph.conf --mkfs
  • Sur ceph2 :
    mkdir -p /var/lib/ceph/mon/ceph-b
    scp 192.168.0.1:/var/lib/ceph/mon/ceph-a/keyring /var/lib/ceph/mon/ceph-b/keyring
    scp 192.168.0.1:/etc/ceph/ceph.mon.a.keyring /etc/ceph/ceph.mon.b.keyring
    scp 192.168.0.1:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring
    ceph-mon -i b -f -c /etc/ceph/ceph.conf --mkfs
  • Sur ceph3 :
    mkdir -p /var/lib/ceph/mon/ceph-c
    scp 192.168.0.1:/var/lib/ceph/mon/ceph-a/keyring /var/lib/ceph/mon/ceph-c/keyring
    scp 192.168.0.1:/etc/ceph/ceph.mon.a.keyring /etc/ceph/ceph.mon.c.keyring
    scp 192.168.0.1:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring
    ceph-mon -i c -f -c /etc/ceph/ceph.conf --mkfs
    /etc/init.d/ceph -a start mon.c
    ssh 192.168.0.2 "/etc/init.d/ceph -a start mon.b"
    ssh 192.168.0.1 "/etc/init.d/ceph -a start mon.a"

Configuration des OSD

  • Sur ceph1 :
    mkdir /var/lib/ceph/journal/
    ceph osd create
    ceph-osd -i 0 --mkfs --mkkey
    ceph auth add osd.0 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-0/keyring
    service ceph -a start osd.0
    ceph osd crush set 0 2.0 root=default host=ceph1
      
    ceph osd create
    ceph-osd -i 1 --mkfs --mkkey
    ceph auth add osd.1 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-1/keyring
    service ceph -a start osd.1  
    ceph osd crush set 1 2.0 root=default host=ceph1
  • Sur ceph2 :
    mkdir /var/lib/ceph/journal/
    ceph osd create
    ceph-osd -i 2 --mkfs --mkkey
    ceph auth add osd.2 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-2/keyring
    service ceph -a start osd.2
    ceph osd crush set 2 2.0 root=default host=ceph2
      
    ceph osd create
    ceph-osd -i 3 --mkfs --mkkey
    ceph auth add osd.3 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-3/keyring
    service ceph -a start osd.3
    ceph osd crush set 3 2.0 root=default host=ceph2
  • Sur ceph3 :
    mkdir /var/lib/ceph/journal/
    ceph osd create
    ceph-osd -i 4 --mkfs --mkkey
    ceph auth add osd.4 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-4/keyring
    service ceph -a start osd.4
    ceph osd crush set 4 2.0 root=default host=ceph3
      
    ceph osd create
    ceph-osd -i 5 --mkfs --mkkey
    ceph auth add osd.5 osd 'allow *' mon 'allow rwx' -i /var/lib/ceph/osd/ceph-5/keyring
    service ceph -a start osd.5
    ceph osd crush set 5 2.0 root=default host=ceph3
  • Création d'un LV libvirt, formatage ext4 et montage :
    lvcreate -L 5G -n libvirt vg_$( hostname -s )
    mkfs.ext4 /dev/vg_$( hostname -s )/libvirt 
    tune2fs -i0 -c0 /dev/vg_$( hostname -s )/libvirt
    echo "/dev/mapper/vg_$( hostname -s )-libvirt /var/lib/libvirt ext4    defaults             0       0" >> /etc/fstab
    mount -a
  • Installation de libvirt et ses dépendances :
    apt-get install libvirt-bin qemu-kvm netcat-openbsd qemu-utils

A faire sur ceph1 :

  • Création d'un utilisateur dédié pour libvirt au niveau de ceph :
     ceph auth get-or-create client.libvirt mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool'
  • Création d'un secret Libvirt pour stocker les informations d'authentification auprès du cluster Ceph :
    echo "<secret ephemeral='no' private='no'><uuid>`uuidgen`</uuid><usage type='ceph'><name>client.libvirt secret</name></usage></secret>" > /tmp/secret.xml
    scp /tmp/secret.xml 192.168.0.2:/tmp/
    scp /tmp/secret.xml 192.168.0.3:/tmp/
    virsh secret-define /tmp/secret.xml
    ssh 192.168.0.2 "virsh secret-define /tmp/secret.xml"
    ssh 192.168.0.3 "virsh secret-define /tmp/secret.xml"
  • Définition du secret :
    • On commance par récupèré l'UUID du secret libvirt affiché lors de la création du secret à l'étape précedente :
      Secret 9b*******************************27e created
    • On récupère la clé de l'utilisateur *ceph* *client.libvirt* au format *base64* :
      root@ceph1:~# ceph auth get client.libvirt
      [client.libvirt]
            key = AQ**********************************0A==
            caps mon = "allow r"
            caps osd = "allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool"
    • On peut maintenant définir à partir des deux informations récupérées :
      virsh secret-set-value --secret 9b*******************************27e --base64 'AQ**********************************0A=='
      ssh 192.168.0.2 "virsh secret-set-value --secret 9b*******************************27e --base64 'AQ**********************************0A=='"
      ssh 192.168.0.3 "virsh secret-set-value --secret 9b*******************************27e --base64 'AQ**********************************0A=='"
  • Création d'un pool ceph pour libvirt :
    ceph osd pool create libvirt 200
Le nombre 200 utilisé lors de la création du pool libvirt correspond aux nombres de Placement Group calculé selon la méthode officielle expliqué ici.
  • On créé un fichier XML /tmp/rbd-pool.xml qui nous permettra de définir le pool au niveau de libvirt :
    <pool type="rbd">
          <name>rbd</name>
          <source>
            <name>libvirt</name>
              <host name='192.168.0.1' port='6789'/>
              <host name='192.168.0.2' port='6789'/>
              <host name='192.168.0.3' port='6789'/>
              <auth username='libvirt' type='ceph'>
                <secret uuid='9b*******************************27e'/>
              </auth>
          </source>
    </pool>
  • On créé le pool dans libvirt à partir du fichier *XML* :
    virsh pool-define /tmp/rbd-pool.xml
    scp /tmp/rbd-pool.xml 192.168.0.2:/tmp/
    ssh 192.168.0.2 "virsh pool-define /tmp/rbd-pool.xml"
    scp /tmp/rbd-pool.xml 192.168.0.3:/tmp/
    ssh 192.168.0.3 "virsh pool-define /tmp/rbd-pool.xml"

On peut désormais utiliser un volume ceph en tant que disque d'une machine virtuelle. Pour cela, voila un exemple de configuration d'un disque ceph d'une machine virtuelle :

    <disk type='network' device='disk'>
      <driver name='qemu' cache='none'/>
      <auth username='libvirt'>
        <secret type='ceph' uuid='9b*******************************27e'/>
      </auth>
      <source protocol='rbd' name='libvirt/[nom volume]'>
        <host name='192.168.0.1' port='6789'/>
        <host name='192.168.0.2' port='6789'/>
        <host name='192.168.0.3' port='6789'/>
      </source>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
  • informatique/systeme/ha/ceph.1385494677.txt.gz
  • Dernière modification : 2013/11/26 19:37
  • de bn8