<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Werk &#187; système de fichiers</title>
	<atom:link href="http://werk.feub.net/tag/systeme-de-fichiers/feed/" rel="self" type="application/rss+xml" />
	<link>http://werk.feub.net</link>
	<description>Pourquoi Werk? ^.^</description>
	<lastBuildDate>Tue, 06 Dec 2011 14:18:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Stockage : réplication en temps réel avec DRBD</title>
		<link>http://werk.feub.net/2011/09/drbd-centos-6/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drbd-centos-6</link>
		<comments>http://werk.feub.net/2011/09/drbd-centos-6/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 09:24:40 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[drbd]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[synchronisation]]></category>
		<category><![CDATA[système de fichiers]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=879</guid>
		<description><![CDATA[DRBD (Distributed Replicated Block Device) est une architecture de stockage distribuée pour GNU/Linux, pour parler rapidement on peut dire qu&#8217;il s&#8217;agit d&#8217;une sorte de RAID 1 au niveau du réseau. Cela permet d&#8217;avoir deux machines avec réplication de données de l&#8217;une vers l&#8217;autre, l&#8217;une étant désignée primaire et l&#8217;autre secondaire (mais il existe un mode [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://werk.feub.net/medias/2011/09/drbd_logo_small.gif" alt="" class="floatleft" /><a href="http://fr.wikipedia.org/wiki/DRBD" title="Wikipedia: DRBD" target="_blank">DRBD</a> (Distributed Replicated Block Device) est une architecture de stockage distribuée pour GNU/Linux, pour parler rapidement on peut dire qu&#8217;il s&#8217;agit d&#8217;une sorte de RAID 1 au niveau du réseau. Cela permet d&#8217;avoir deux machines avec réplication de données de l&#8217;une vers l&#8217;autre, l&#8217;une étant désignée primaire et l&#8217;autre secondaire (mais il existe un mode primaire/primaire également). Il s&#8217;agit d&#8217;un logiciel libre développé par la société <a href="http://www.linbit.com/" title="linbit.com" target="_blank">Linbit</a> qui par ailleurs offre un service de support.
</p>
<p>
DRBD réplique au niveau des périphériques de bloc, pour plus d&#8217;informations sur son fonctionnement, je vous renvoie à la <a href="http://fr.wikipedia.org/wiki/DRBD#Principe_de_fonctionnement" title="Wikipedia : DRBD" target="_blank">page Wikipedia de DRBD</a>.
</p>
<p><span id="more-879"></span></p>
<h4>Pré-requis</h4>
<p>
Ce tutoriel est réalisé avec deux machines sous <a href="http://www.centos.org/" title="centos.org" target="_blank">CentOS 6</a>, celles-ci sont respectivement nommées <code>centos-ha1</code> (IP : 192.168.1.10) et <code>centos-ha2</code> (IP : 192.168.1.11), le terme de nœud sera utilisé pour les désigner.<br />
SELinux est désactivé et le port 7789 ouvert au niveau du firewall.
</p>
<p>
DRBD fonctionnant au niveau bloc, il faut un disque ou une partition dédiée à cela. Dans l&#8217;exemple de ce billet, on part d&#8217;un groupe de volumes LVM nommé <code>vg_storage</code> avec un unique volume logique <code>lv_storage</code> qui est libre pour créer notre ressource DRBD. Un volume logique étant un périphérique de bloc aux yeux de Linux, cela convient parfaitement. Celui-ci n&#8217;a pas besoin (et ne doit pas) d&#8217;être formatté.
</p>
<h4>Installation</h4>
<p>
Depuis CentOS 6, les paquets DRBD ne sont plus dans les dépots de base, il faut donc ajouter ceux de <a href="http://atrpms.net/" title="atRPMS" target="_blank">atRPMS</a>. Pour ce faire, ajouter le fichier <code>atrpms.repo</code> sous <code>/etc/yum.repos.d</code> contenant ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>atrpms<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">name</span>=CentOS <span style="color: #007800;">$releasever</span> - <span style="color: #007800;">$basearch</span> - ATrpms
<span style="color: #007800;">baseurl</span>=http:<span style="color: #000000; font-weight: bold;">//</span>dl.atrpms.net<span style="color: #000000; font-weight: bold;">/</span>el<span style="color: #007800;">$releasever</span>-<span style="color: #007800;">$basearch</span><span style="color: #000000; font-weight: bold;">/</span>atrpms<span style="color: #000000; font-weight: bold;">/</span>stable
<span style="color: #007800;">gpgkey</span>=http:<span style="color: #000000; font-weight: bold;">//</span>atrpms.net<span style="color: #000000; font-weight: bold;">/</span>RPM-GPG-KEY.atrpms
<span style="color: #007800;">gpgcheck</span>=<span style="color: #000000;">1</span></pre></div></div>

<p>
Vérification de la présence de paquets relatifs à DRBD :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># yum search drbd</span>
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
<span style="color: #000000; font-weight: bold;">*</span> base: ftp.plusline.de
<span style="color: #000000; font-weight: bold;">*</span> extras: ftp.plusline.de
<span style="color: #000000; font-weight: bold;">*</span> updates: mirrors.prometeus.net
========================================= Matched: drbd =========================================
drbd.i686 : Distributed Replicated Block Device.
drbd-kmdl-2.6.32-131.0.15.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-131.12.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-131.2.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-131.4.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-131.6.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.14.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.18.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.18.2.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.24.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.29.1.el6.centos.plus.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.29.1.el6.i686.i686 : Distributed Redundant Block Device.
drbd-kmdl-2.6.32-71.7.1.el6.i686.i686 : Distributed Redundant Block Device.</pre></div></div>

<p>
Nous pouvons installer le paquet <code>drbd</code> ainsi que le module du noyau correspondant au noyau en cours. Je vérifie quel noyau j&#8217;ai sur mon système :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># uname -r</span>
2.6.32-71.29.1.el6.i686</pre></div></div>

<p>
J&#8217;installe le module correspondant :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># yum install drbd drbd-kmdl-2.6.32-71.29.1.el6.i686.i686</span></pre></div></div>

<p>
Il faut charger le nouveau module dans le noyau :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># modprobe drbd</span></pre></div></div>

<p>
Et bien sur on veut qu&#8217;il se charge au démarrage de la machine, on ajoute donc cette ligne au fichier <code>/etc/rc.local</code>.
</p>
<h4>Configuration</h4>
<p>
La configuration de DRBD se situe sous <code>/etc/drbd.conf</code>, mais pour plus de lisibilité, ce fichier fait appel à ceux situés sous <code>/etc/drbd.d/</code>, la configuration se fait donc d&#8217;une part dans <code>global_common.conf</code> pour la configuration commune et dans un fichier <code>r0.res</code> que nous allons créer pour notre nouvelle ressource. Ce nom r0 est arbitraire.<br />
Donc pour commencer, vérifier que le fichier <code>global_common.conf</code> possède les options suivantes :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">global <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  usage-count <span style="color: #c20cb9; font-weight: bold;">yes</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
common <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  net <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    protocol C;
    verify-alg sha1;
    csums-alg sha1;
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
L&#8217;option <code>protocol C</code> signifie que la réplication s&#8217;effectue de façon synchrone. Avec ce mode de fonctionnement synchrone, l&#8217;écriture de données n&#8217;est considérée terminée que lorsque le nœud secondaire a terminé d&#8217;écrire, validant ainsi l&#8217;opération. <code>verify-alg sha1</code> <a href="http://www.drbd.org/users-guide/s-online-verify.html" title="drbd.org" target="_blank">vérifie l&#8217;intégrité des données</a> bloc par bloc entre les nœuds. <code>csums-alg sha1</code> active la synchronisation avec somme de contrôle (checksum). Comme expliqué dans la documentation, la synchronisation n&#8217;est pas la même chose que la réplication des périphériques. La seconde se fait en temps réel, c&#8217;est le fonctionnement normal de DRBD, alors que la première s&#8217;effectue lorsqu&#8217;il y a eu perte d&#8217;un des deux nœuds (pour quelque raison que ce soit) et une (re)synchronisation est nécessaire.
</p>
<p>
Il est temps de créer la vraie ressource dans un nouveau fichier <code>r0.res</code> contenant ces informations :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">resource r0 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	on mailsrv-ha1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    	address   192.168.1.10:<span style="color: #000000;">7789</span>;
    	device    <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd1;
		disk      <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>vg_storage-lv_storage;
		meta-disk internal;
  	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
  	on mailsrv-ha2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    	address   192.168.1.11:<span style="color: #000000;">7789</span>;
    	device    <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd1;
		disk      <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>vg_storage-lv_storage;
		meta-disk internal;
  	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>
Petite explication sur la configuration de cette ressource qui dans son ensemble parle d&#8217;elle-même. On définit les deux nœuds avec le mot-clé <code>on</code> suivi du nom de l&#8217;hôte. On spécifie l&#8217;IP du nœud et le port utilisé &#8211; ici 7789. Le périphérique de bloc logique est définit par <code>device</code> suivi du chemin vers celui-ci. Ensuite il faut indiquer la partition de bas niveau sur laquelle le périphérique de bloc logique se posera grace au mot-clé <code>disk</code> suivi de son chemin. <code>meta-disk internal</code> indique que la zone réservée aux données de contrôle sera sur la même partition, toujours au niveau bloc (plus d&#8217;<a href="http://www.drbd.org/users-guide/ch-internals.html" title="http://www.drbd.org/users-guide/ch-internals.html" target="_blank">informations sur ce sujet</a> sur la documentation officielle).
</p>
<p>
On voit que certaines options (presque toutes sauf l&#8217;IP) sont les mêmes, on peut donc simplifier notre fichier <code>r0.res</code> comme ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">resource r0 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	device    <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd1;
    disk      <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>vg_storage-lv_storage;
    meta-disk internal;
	on mailsrv-ha1 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    	address   192.168.137.201:<span style="color: #000000;">7789</span>;
  	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
  	on mailsrv-ha2 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    	address   192.168.137.203:<span style="color: #000000;">7789</span>;
  	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h4>Activation de la ressource</h4>
<p>
Voilà, tout est bien configuré, on peut activer la ressource. Je répète que le système de fichiers de bas niveau <code>/dev/mapper/vg_storage-lv_storage</code> doit être démonté et ne doit pas être formatté. Si tel est le cas, son contenu va de toutes façons être perdu.
</p>
<p>
On commence par créer les meta-données du périphérique :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbdadm create-md r0</span></pre></div></div>

<p>
Si des erreurs sont retournées, c&#8217;est que le système de fichiers existe, on le détruit donc :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># dd if=/dev/zero of=/dev/mapper/vg_storage-lv_storage bs=1M count=128</span></pre></div></div>

<p>
On relance la commande de création des meta-données. Tout devrait bien se passer, on peut activer la ressource :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbdadm up r0</span></pre></div></div>

<p>
Il faut faire de même sur l&#8217;autre nœud. Lorsque la deuxième machine est prête on initialise la première synchronisation par cette commande :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbdadm primary --force r0</span></pre></div></div>

<p>
Alors que se passe-t-il? Lorsque la ressource est activée, les deux nœuds sont marquées comme secondaires, une première synchronisation est nécessaire, on va donc forcer (avec l&#8217;option <code>--force</code>) cette opération sur le nœud que l&#8217;on veut primaire.
</p>
<p>
A ce stade, il est possible de vérifier l&#8217;état de DRBD par la commande :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbd-overview </span>
  <span style="color: #000000;">1</span>:r0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>  SyncSource Primary<span style="color: #000000; font-weight: bold;">/</span>Secondary UpToDate<span style="color: #000000; font-weight: bold;">/</span>Inconsistent C r----- 
	<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">&gt;</span>....................<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #c20cb9; font-weight: bold;">sync</span><span style="color: #ff0000;">'ed:  0.6% (53340/53652)M</span></pre></div></div>

<p>
On voit que la ressource est en cours de synchronisation, suivant la taille de la partition, cela peut être long. On a plus d&#8217;info avec :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cat /proc/drbd </span>
version: 8.4.0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>api:<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>proto:<span style="color: #000000;">86</span>-<span style="color: #000000;">100</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by gardner<span style="color: #000000; font-weight: bold;">@</span>, <span style="color: #000000;">2011</span>-08-<span style="color: #000000;">26</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">30</span>
&nbsp;
 <span style="color: #000000;">1</span>: cs:SyncSource ro:Primary<span style="color: #000000; font-weight: bold;">/</span>Secondary ds:UpToDate<span style="color: #000000; font-weight: bold;">/</span>Inconsistent C r-----
    ns:<span style="color: #000000;">1482108</span> nr:<span style="color: #000000;">0</span> dw:<span style="color: #000000;">0</span> dr:<span style="color: #000000;">1487544</span> al:<span style="color: #000000;">0</span> bm:<span style="color: #000000;">90</span> lo:<span style="color: #000000;">0</span> pe:<span style="color: #000000;">2</span> ua:<span style="color: #000000;">5</span> ap:<span style="color: #000000;">0</span> ep:<span style="color: #000000;">1</span> wo:b oos:<span style="color: #000000;">53461324</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">&gt;</span>....................<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #c20cb9; font-weight: bold;">sync</span><span style="color: #ff0000;">'ed:  2.7% (52208/53652)M
	finish: 0:41:59 speed: 21,216 (22,100) K/sec</span></pre></div></div>

<p>
On voit que le processus de synchronisation est en cours (<code>cs:SyncSource</code>), que le nœud primaire est à jour mais le secondaire est encore dans un étant incohérent (<code>ds:UpToDate/Inconsistent</code>).<br />
Il n&#8217;est pas nécessaire d&#8217;attendre la fin de la synchronisation pour créer le système de fichiers, donc allons-y, créons un système de fichiers <code>ext4</code> et montons-le :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mkfs.ext4 <span style="color: #660033;">-L</span> storage <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd1
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>storage
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd1 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>storage</pre></div></div>

<p>
Le système de fichiers est maintenant utilisable et va être répliqué en temps réel. On peut vérifier l&#8217;état de synchronisation :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cat /proc/drbd </span>
version: 8.4.0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>api:<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>proto:<span style="color: #000000;">86</span>-<span style="color: #000000;">100</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by gardner<span style="color: #000000; font-weight: bold;">@</span>, <span style="color: #000000;">2011</span>-08-<span style="color: #000000;">26</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">30</span>
&nbsp;
 <span style="color: #000000;">1</span>: cs:Connected ro:Primary<span style="color: #000000; font-weight: bold;">/</span>Secondary ds:UpToDate<span style="color: #000000; font-weight: bold;">/</span>UpToDate C r-----
    ns:<span style="color: #000000;">56499808</span> nr:<span style="color: #000000;">36</span> dw:<span style="color: #000000;">1557816</span> dr:<span style="color: #000000;">54944894</span> al:<span style="color: #000000;">422</span> bm:<span style="color: #000000;">3354</span> lo:<span style="color: #000000;">0</span> pe:<span style="color: #000000;">0</span> ua:<span style="color: #000000;">0</span> ap:<span style="color: #000000;">0</span> ep:<span style="color: #000000;">1</span> wo:b oos:<span style="color: #000000;">0</span></pre></div></div>

<p>
Voilà, c&#8217;est fini, notre resource est connectée (<code>cs:Connected</code>), on est sur le noeud primaire (<code>ro:Primary/Secondary</code>) et elle est à jour des deux cotés (<code>ds:UpToDate/UpToDate</code>). Avec <code>drbd-overview</code> on obtient plus d&#8217;informations, en particulier sur la taille du stockage :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbd-overview </span>
  <span style="color: #000000;">1</span>:r0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>  Connected Primary<span style="color: #000000; font-weight: bold;">/</span>Secondary UpToDate<span style="color: #000000; font-weight: bold;">/</span>UpToDate C r----- <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>storage ext4 52G 730M 49G <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">%</span></pre></div></div>

<p>
Toute modification sur la ressource peut se faire en temps réel, après un changement, il faut copier le fichier de configuration sur le second nœud et opérer cette commande (sur les deux nœuds) :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbdadm adjust r0</span></pre></div></div>

<h4>Vérification en ligne automatique</h4>
<p>
Nous avons vu que l&#8217;option <code>verify-alg</code> permet de vérifier l&#8217;intégrité des données en ligne, pour faire ce test il suffit d&#8217;invoquer la commande :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># drbdadm verify r0</span></pre></div></div>

<p>
DRBD commence alors la vérification et s&#8217;il détecte des blocs non synchronisés, il les marque comme tel et l&#8217;inscrit dans le log du noyau. Il est bon d&#8217;automatiser cette tâche en l&#8217;ajoutant dans le <code>cron</code>. Pour ce faire, ajouter un fichier <code>/etc/cron.d/drbd-verify</code> avec &#8211; par exemple &#8211; ce contenu :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">42</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>    root    <span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>drbdadm verify r0</pre></div></div>

<p>
Par ailleurs, si des blocs non synchronisés ont été détectés, il faut les re-synchroniser comme ceci :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">drbdadm disconnect r0
drbdadm connect r0</pre></div></div>

<h4>Restauration manuelle après un split-brain</h4>
<p>
Un <a href="http://fr.wikipedia.org/wiki/Split-brain" title="Wikipedia : Split-brain" target="_blank">split-brain</a> se produit lorsque pour une raison quelconque les deux nœuds se retrouvent déconnectés, lorsque la connectivité revient, DRBD détecte que les 2 nœuds sont en mode primaire, DRBD rompt alors immédiatement la connexion de réplication par sécurité. Après le split-brain, un nœud passe en mode <code>StandAlone</code> et l&#8217;autre passe soit en mode secondaire ou en <code>WFConnection</code>. Il est temps d&#8217;intervenir.
</p>
<p>
Pour repartir sans corrompre les données &#8211; pour que le primaire sache qu&#8217;il est &laquo;&nbsp;maitre&nbsp;&raquo; &#8211; il faut aller sur le (futur) nœud secondaire et le déclarer comme tel, puis on connecte la ressource en lui disant d&#8217;oublier ses données :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">drbdadm secondary r0
drbdadm connect <span style="color: #660033;">--discard-my-data</span> r0</pre></div></div>

<p>
On passe sur le primaire que l&#8217;on connecte et que l&#8217;on déclare primaire :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">drbdadm connect r0
drbdadm primary r0</pre></div></div>

<p>
Notre ressource <code>r0</code> est repartie.
</p>
<h4>Tester la réplication</h4>
<p>
Il est temps de tester un peu le fonctionnement de la réplication. Créons un fichier quelconque de 500Mo sous <code>/mnt/storage</code> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># dd if=/dev/zero of=/mnt/storage/toto.dat bs=10M count=50</span>
<span style="color: #000000;">50</span>+<span style="color: #000000;">0</span> records <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000;">50</span>+<span style="color: #000000;">0</span> records out
<span style="color: #000000;">524288000</span> bytes <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">524</span> MB<span style="color: #7a0874; font-weight: bold;">&#41;</span> copied, <span style="color: #000000;">31.4183</span> s, <span style="color: #000000;">16.7</span> MB<span style="color: #000000; font-weight: bold;">/</span>s
<span style="color: #666666; font-style: italic;"># ls -l /mnt/storage/</span>
<span style="color: #660033;">-rw-r--r--</span>  <span style="color: #000000;">1</span> root root <span style="color: #000000;">524288000</span> Sep <span style="color: #000000;">22</span> <span style="color: #000000;">11</span>:04 toto.dat</pre></div></div>

<p>
Celui-ci devrait maintenant exister également sur <code>centos-ha2</code>, pour le vérifier il faut suivre les étapes suivantes, sur le primaire : démonter le système de fichiers, le passer en secondaire, et sur le secondaire : le passer en primaire et monter le système de fichiers. Cela donne :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>centos-ha1 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># umount /mnt/storage</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>centos-ha1 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># drbdadm secondary r0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>centos-ha2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># drbdadm primary r0</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>centos-ha2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># mount /dev/drbd1 /mnt/storage</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>centos-ha2 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ls -l /mnt/storage</span>
<span style="color: #660033;">-rw-r--r--</span>  <span style="color: #000000;">1</span> root root <span style="color: #000000;">524288000</span> Sep <span style="color: #000000;">22</span> <span style="color: #000000;">11</span>:04 toto.dat</pre></div></div>

<p>
Tout est parfait, même si cela semble un peu long. Il ne faut pas oublier que le système de fichiers sur le nœud secondaire n&#8217;est pas accessible en l&#8217;état (il n&#8217;est d&#8217;ailleurs pas monté). Dans un environnement de production, la manipulation est un peu fastidieuse, c&#8217;est pourquoi il vaut mieux utiliser un CRM (Cluster Resource management) &#8211; comme <a href="http://www.clusterlabs.org/wiki/Pacemaker" title="clusterlabs.org" target="_blank">Pacemaker</a> &#8211; qui fera ce travail automatiquement. Ce sera l&#8217;objet d&#8217;un prochain article.
</p>
<p style="text-align:right">
^.^
</p>
<hr />
<p><strong>Ressources :</strong></p>
<ul>
<li><a href="http://www.drbd.org/users-guide/drbd-users-guide.html" title="drbd.org" target="_blank">The DRBD User&#8217;s Guide</a></li>
<li><a href="http://fr.wikipedia.org/wiki/DRBD" title="Wikipedia : DRBD" target="_blank">Wikipedia : DRBD</a></li>
<li><a href="http://www.centos.org/" title="centos.org" target="_blank">CentOS 6</a></li>
<li><a href="http://atrpms.net/" title="atRPMS" target="_blank">Dépôt atRPMS</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2011/09/drbd-centos-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc (Feed is rejected)
Page Caching using apc
Object Caching 228/245 objects using memcached

Served from: werk.feub.net @ 2012-02-09 01:06:02 -->
