<?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; lvm</title>
	<atom:link href="http://werk.feub.net/tag/lvm/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>
		<item>
		<title>Ajouter un disque à une pile RAID 1</title>
		<link>http://werk.feub.net/2009/06/ajouter-un-disque-a-une-pile-raid-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajouter-un-disque-a-une-pile-raid-1</link>
		<comments>http://werk.feub.net/2009/06/ajouter-un-disque-a-une-pile-raid-1/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 05:10:12 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[fdish]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[mdadm]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[recovery]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=753</guid>
		<description><![CDATA[Depuis hier edoras ma vieille config qui me sert de serveur fourre-tout sous Fedora 11 ne démarrait plus. J&#8217;avais depuis un certains temps un disque qui jouait du grattoir à faire un bruit pas possible qui normalement devrait alerter n&#8217;importe qui qu&#8217;il est temps de s&#8217;en occuper. Mais bon, j&#8217;ai laissé courir en me disant [...]]]></description>
			<content:encoded><![CDATA[<p>
Depuis hier edoras ma vieille config qui me sert de serveur <em>fourre-tout</em> sous Fedora 11 ne démarrait plus. J&#8217;avais depuis un certains temps un disque qui jouait du grattoir à faire un bruit pas possible qui normalement devrait alerter n&#8217;importe qui qu&#8217;il est temps de s&#8217;en occuper. Mais bon, j&#8217;ai laissé courir en me disant que ça allait bien tenir et que je m&#8217;en inquiéterais plus tard. J&#8217;ai attendu trop longtemps.
</p>
<p>
Je passe sur les détails du comment du pourquoi je m&#8217;en suis dépatouillé pour récupérer mes données (229Go de photos et de musique) sur du <a href="http://fr.wikipedia.org/wiki/LVM" target="_blank" title="Wikipedia : LVM">LVM</a> réparti sur 2 disques avec un disque marqué inexistant. Mais j&#8217;ai réussi.<br />
Edoras est d&#8217;une part un vieux coucou (Sempron 2400+ avec 1Go de RAM), mais reste très bien pour un petit serveur qui démarre en niveau 3, mais c&#8217;est aussi une usine à gaz qui comporte 5 disques : un disque système avec 2 partitions <em>/boot</em> et l&#8217;autre en LVM (<em>swap</em>, <em>root</em> et <em>home</em>), un VGdata de 380Go sur 2 disques et un VGraid qui comme son l&#8217;indique est un RAID1 sur deux disques SATA de 500Go. Non seulement, j&#8217;ai eu ce problème d&#8217;inconsistance du VGdata, mais j&#8217;avais un des disques du RAID déconnecté. Et ne me demandez pas pourquoi, ce deuxième disque avec un identifiant de partition de type Linux LVM (8e) et non pas Linux RAID auto (fd). Je l&#8217;ai donc ré-attribué l&#8217;id du système de fichiers comme étant <em>fd</em>. Et j&#8217;ai du ré-ajouter le disque au RAID pour le resynchroniser.
</p>
<p><span id="more-753"></span></p>
<p>
Ajout du disque à la pile raid <em>md127</em> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mdadm --add /dev/md127 /dev/sde1</span>
mdadm: added <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde1</pre></div></div>

<p>
Voilà, la synchronisation doit commencer toute seule :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>edoras<span style="color: #000000; font-weight: bold;">@</span>edoras ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># cat /proc/mdstat</span>
Personalities : <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
md127 : active raid1 sde1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdd1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
 <span style="color: #000000;">488383936</span> blocks <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>U_<span style="color: #7a0874; font-weight: bold;">&#93;</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> recovery = <span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">13261248</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">488383936</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">finish</span>=137.9min <span style="color: #007800;">speed</span>=57399K<span style="color: #000000; font-weight: bold;">/</span>sec
&nbsp;
unused devices: <span style="color: #000000; font-weight: bold;">&lt;</span>none<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>
Plus qu&#8217;une bonne 130aine de minutes à attendre pour avoir ses données sécurisées de nouveau.</p>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2009/06/ajouter-un-disque-a-une-pile-raid-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modification du schéma de partitionnement d&#8217;edoras</title>
		<link>http://werk.feub.net/2009/01/modification-du-schema-de-partitionnement-dedoras/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=modification-du-schema-de-partitionnement-dedoras</link>
		<comments>http://werk.feub.net/2009/01/modification-du-schema-de-partitionnement-dedoras/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 18:23:45 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[3615 tavie]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[fdisk]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[raid1]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=6</guid>
		<description><![CDATA[Passage en full LVM]]></description>
			<content:encoded><![CDATA[<p>
Cette opération est lourde et longue, mais j&#8217;ai décidé de modifier le partitionnement de mon petit serveur edoras actuellement sous <a href="http://www.fedora-fr.org/" title="Fedora France">Fedora 10</a>.<br />
En effet, depuis de nombreuses années, j&#8217;utilisais un partitionnement <em>classique</em>, et depuis <a href="http://docs.fedoraproject.org/release-notes/f10/fr/" title="Fedora">Cambridge</a>, je suis passé à <a href="http://fr.wikipedia.org/wiki/LVM" title="Wikipedia">LVM</a> (enfin!) et même au <a href="http://feub.net/werk/index.php/tic/commentaires/gerer_une_pile_raid_et_lvm_sous_fedora_10/" title="feub.net">RAID 1</a> pour encore plus sécuriser mes sauvegardes photos. Le RAID a été ajouté avec deux disques non utilisés, mais il me restait deux autres disques avec une seule partition chacun <em>sdb1</em> et <em>sdc1</em> bourrés de données et montés de façon classique, respectivement en /data1 (200Go) et /backup (160Go), ces deux partitions étant utilisés en montages <a href="http://fr.wikipedia.org/wiki/Network_File_System" title="Wikipedia">NFS</a> sur mon réseau (et TRES solicités).
</p>
<p>
<em>Avant :</em>
</p>
<pre lang=bash">
$ df -h
Sys. de fich.         Tail. Occ. Disp. %Occ. Monté sur
/dev/mapper/VG1-LVroot
9,9G  3,7G  5,7G  40% /
/dev/mapper/VG1-LVhome
26G  853M   23G   4% /home
/dev/sdc1             145G   83G   54G  61% /backup
/dev/sdb1             184G  111G   64G  64% /data1
/dev/sda1             236M   29M  195M  13% /boot
/dev/mapper/VGraid-LVraid
459G  216G  220G  50% /raid
</pre>
<p>
D&#8217;une part, cela me faisait beaucoup de montages (NFS) sur mes Mac alors que je pouvais &#8211; théoriquement &#8211; rassembler /backup et /data1 en un seul volume, et d&#8217;autre part, je désirais passer en full LVM pour plus de flexibilité.
</p>
<p>
La limitation des systèmes de fichiers classiques m&#8217;imposait d&#8217;avoir ces deux partitions séparées, celles-ci étant sur deux disques différents. C&#8217;est là que LVM montre sa puissance : la possibilité de créer un groupe de volumes sur les deux disques, soit au final avoir une seule partition <em>virtuelle</em> de 360Go unique sur les deux disques.
</p>
<p>
<em>Après :</em>
</p>
<pre lang=bash">
$ df -h
Sys. de fich.         Tail. Occ. Disp. %Occ. Monté sur
/dev/mapper/VG1-LVroot
9,9G  3,7G  5,7G  40% /
/dev/mapper/VG1-LVhome
26G  855M   23G   4% /home
/dev/mapper/VGdata-LVdata
331G  1,8G  312G   1% /mnt/data
/dev/sda1             236M   29M  195M  13% /boot
/dev/mapper/VGraid-LVraid
459G  275G  162G  63% /mnt/raid
</pre>
<p>
Après avoir déplacé mes données sur un autre disque pour faire la modification, redéfini <em>sdb1</em> et <em>sdc1</em> en partition de type 8e (Linux LVM) dans <a href="http://fr.wikipedia.org/wiki/Fdisk" title="Wikipedia">fdisk</a>, j&#8217;ai opéré comme suit pour ajouter un groupe de volumes VGdata contenant un unique volume logique LVdata de la totalité de l&#8217;espace disponible (je ne détaillerai pas, les étapes ayant été un peu mieux expliquées dans <a href="http://feub.net/werk/index.php/tic/commentaires/gerer_une_pile_raid_et_lvm_sous_fedora_10/" title="feub.net">ce billet</a>) :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># pvcreate /dev/sdb1</span>
<span style="color: #666666; font-style: italic;"># pvcreate /dev/sdc1</span>
<span style="color: #666666; font-style: italic;"># vgcreate -s 16M VGdata /dev/sdb1 /dev/sdc1</span>
<span style="color: #666666; font-style: italic;"># lvcreate -l 21462 VGdata -n LVdata</span>
<span style="color: #666666; font-style: italic;"># mkfs.ext3 /dev/VGdata/LVdata</span>
<span style="color: #666666; font-style: italic;"># mkdir /mnt/data</span>
<span style="color: #666666; font-style: italic;"># mount /dev/VGdata/LVdata /mnt/data</span></pre></div></div>

<p>
Ajout du montage dans <a href="http://fr.wikipedia.org/wiki/Fstab" title="Wikipedia">fstab</a> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VGdata<span style="color: #000000; font-weight: bold;">/</span>LVdata	<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>data		ext3	defaults	<span style="color: #000000;">1</span> <span style="color: #000000;">2</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2009/01/modification-du-schema-de-partitionnement-dedoras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gérer une pile RAID et LVM sous Fedora 10</title>
		<link>http://werk.feub.net/2008/12/gerer-une-pile-raid-et-lvm-sous-fedora-10/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gerer-une-pile-raid-et-lvm-sous-fedora-10</link>
		<comments>http://werk.feub.net/2008/12/gerer-une-pile-raid-et-lvm-sous-fedora-10/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 07:01:21 +0000</pubDate>
		<dc:creator>Fabien</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[fdisk]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[raid]]></category>

		<guid isPermaLink="false">http://werk.feub.net/?p=8</guid>
		<description><![CDATA[Sécuriser ses données avec du RAID logiciel]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://fr.wikipedia.org/wiki/RAID_(informatique)" title="Wikipedia">RAID</a> est l&#8217;acronyme pour Redundant Array of Inexpensive Disks, c&#8217;est-à-dire &laquo;&nbsp;<em>Matrice Redondante de Disques peu Onéreux</em>&laquo;&nbsp;. Il s&#8217;agit d&#8217;une technologie utilisant plusieurs disques durs pour stocker des données afin de les sécuriser, ces données étant copiées sur tous les disques (de façons différentes suivant la configuration RAID utilisée : 1, 5, 1+0, 0+1, 6, etc), en cas de panne d&#8217;un disque, la machine reste opérationnelle et les données sont toujours accessibles. Avec certains pré-requis, il est même possible de changer le disque défaillant à chaud sans arrêter la machine, la couche RAID se chargeant de la reconstruction (synchronisation) des données.<br />
Il existe également le RAID 0, mais qui diffère des autres RAID dans son fonctionnement.
</p>
<p>
Cet article parle du <a href="http://fr.wikipedia.org/wiki/RAID_(informatique)#Le_RAID_logiciel" title="Wikipedia">RAID logiciel</a>, sur une machine en <a href="http://www.fedora-fr.org/" title="Fedora France">Fedora 10</a>.
</p>
<p><span id="more-8"></span></p>
<h4>Mise en place d&#8217;un RAID 1 logiciel</h4>
<p>
Je dispose de deux disques SATA 500Go que je désire utiliser en RAID 1, celui-ci fonctionne avec 2 disques (ou plus). Il s&#8217;agit d&#8217;une <em>simple</em> copie des données d&#8217;un disque sur l&#8217;autre, de façon transparente. Après avoir installé ces deux disques, je vérifie qu&#8217;ils soient reconnus par le système :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sd<span style="color: #000000; font-weight: bold;">*</span>
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>,  <span style="color: #000000;">0</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>,  <span style="color: #000000;">1</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>,  <span style="color: #000000;">2</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>,  <span style="color: #000000;">3</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda3
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">16</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">17</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">32</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">33</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc1
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">48</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd
brw-rw---- <span style="color: #000000;">1</span> root disk <span style="color: #000000;">8</span>, <span style="color: #000000;">64</span> déc. <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">37</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde</pre></div></div>

<p>
Il faut maintenant créer une partition physique sur ces disques et placer l&#8217;identificateur de ces partitions comme étant de type <em>Linux RAID</em>, ceci avec <a href="http://fr.wikipedia.org/wiki/Fdisk" title="Wikipedia">fdisk</a> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># fdisk /dev/sdd</span>
Puis taper ces commandes pour un disque neuf :
n
p
<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">&amp;</span>lt;entrée<span style="color: #000000; font-weight: bold;">&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&amp;</span>lt;entrée<span style="color: #000000; font-weight: bold;">&amp;</span>gt;
t
fd
<span style="color: #c20cb9; font-weight: bold;">w</span></pre></div></div>

<p>
Faire de même pour le deuxième disque. Au final un <code>fdisk -l</code> devrait donner quelque chose comme ça :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Disque <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd: <span style="color: #000000;">500.1</span> Go, <span style="color: #000000;">500107862016</span> octets
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">60801</span> cylinders
Units = cylindres of <span style="color: #000000;">16065</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">512</span> = <span style="color: #000000;">8225280</span> bytes
Disk identifier: 0x000b9726
Périphérique Amorce    Début         Fin      Blocs    Id  Système
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd1               <span style="color: #000000;">1</span>       <span style="color: #000000;">60801</span>   <span style="color: #000000;">488384001</span>   fd  Linux raid autodetect
Disque <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde: <span style="color: #000000;">500.1</span> Go, <span style="color: #000000;">500107862016</span> octets
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">60801</span> cylinders
Units = cylindres of <span style="color: #000000;">16065</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">512</span> = <span style="color: #000000;">8225280</span> bytes
Disk identifier: 0x000b9726
Périphérique Amorce    Début         Fin      Blocs    Id  Système
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde1               <span style="color: #000000;">1</span>       <span style="color: #000000;">60801</span>   <span style="color: #000000;">488384001</span>   fd  Linux raid autodetect</pre></div></div>

<p>
Il est temps de combiner ces deux disques en une seule unité RAID 1, ceci par l&#8217;intermédiaire de la commande à tout faire <a href="http://linux.die.net/man/8/mdadm" title="linux.die.net">mdadm</a> :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1</span></pre></div></div>

<p>
La syntaxe est assez explicite : création d&#8217;une pile RAID qui sera en <code>md0</code>, de niveau 1 utilisant les 2 disques préparés auparavent. Et voilà, le RAID 1 est crée! Petite vérification :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mdadm --detail /dev/md0</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0:
Version : <span style="color: #000000;">0.90</span>
Creation Time : Sun Dec <span style="color: #000000;">28</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">39</span> <span style="color: #000000;">2008</span>
Raid Level : raid1
Array Size : <span style="color: #000000;">488383936</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">465.76</span> GiB <span style="color: #000000;">500.11</span> GB<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Used Dev Size : <span style="color: #000000;">488383936</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">465.76</span> GiB <span style="color: #000000;">500.11</span> GB<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Raid Devices : <span style="color: #000000;">2</span>
Total Devices : <span style="color: #000000;">2</span>
Preferred Minor : <span style="color: #000000;">0</span>
Persistence : Superblock is persistent
Update Time : Mon Dec <span style="color: #000000;">29</span> 08:<span style="color: #000000;">33</span>:06 <span style="color: #000000;">2008</span>
State : clean
Active Devices : <span style="color: #000000;">2</span>
Working Devices : <span style="color: #000000;">2</span>
Failed Devices : <span style="color: #000000;">0</span>
Spare Devices : <span style="color: #000000;">0</span>
UUID : d6b46a36:85a45c5f:5232c6b9:3d8a986e
Events : <span style="color: #000000;">0.8</span>
Number   Major   Minor   RaidDevice State
<span style="color: #000000;">0</span>       <span style="color: #000000;">8</span>       <span style="color: #000000;">49</span>        <span style="color: #000000;">0</span>      active <span style="color: #c20cb9; font-weight: bold;">sync</span>   <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd1
<span style="color: #000000;">1</span>       <span style="color: #000000;">8</span>       <span style="color: #000000;">65</span>        <span style="color: #000000;">1</span>      active <span style="color: #c20cb9; font-weight: bold;">sync</span>   <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde1</pre></div></div>

<p>
Si la ligne <code>State</code> rapporte bien <code>clean</code>, alors tout est en principe bon.
</p>
<h4>LVM sur le RAID</h4>
<p>
Le RAID fonctionne, il faut maintenant l&#8217;utiliser. Nous allons gérer <code>md0</code> avec <a href="http://fr.wikipedia.org/wiki/LVM" title="Wikipedia">LVM</a>, en commencant par créer un volume physique, ce qui va initilaiser <code>md0</code> pour utiliser LVM :
</p>

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

<p>
Ensuite, il faut créer le volume groupe, que j&#8217;appelle <strong>VGraid</strong>. La valeur par défaut du PE (Physical Extent) peut se révéler trop faible pour une grosse matrice RAID. Il est alors possible d&#8217;indiquer une taille de PE plus importante avec l&#8217;option -s. Leur nombre maximal est approximativement de 65000 et leur taille par défaut de 4Mo, partant delà, il faut prendre la taille du volume et de le diviser par 65000, puis de l&#8217;arrondir à l&#8217;entier significatif le plus grand le plus proche. Par exemple, pour un volume RAID de 500Go, grosso-modo 500000Mo cela donne : 500000 / 65000 = 7,69, soit 8Mo. Je vais le mettre à 32 pour être plus à l&#8217;aise.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vgcreate -s 16M VGraid /dev/md0</span></pre></div></div>

<p>
Le VG est désormais crée, il faut maintenant le remplir avec un ou plusieurs volume(s) logique(s). Je vais en ajouter un seul &#8211; <strong>LVraid</strong> &#8211; qui prendra la taille du VG. Pour connaître cette taille en PE :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vgdisplay VGraid</span>
<span style="color: #660033;">---</span> Volume group <span style="color: #660033;">---</span>
VG Name               VGraid
System ID
Format                lvm2
Metadata Areas        <span style="color: #000000;">1</span>
Metadata Sequence No  <span style="color: #000000;">2</span>
VG Access             read<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">write</span>
VG Status             resizable
MAX LV                <span style="color: #000000;">0</span>
Cur LV                <span style="color: #000000;">1</span>
Open LV               <span style="color: #000000;">1</span>
Max PV                <span style="color: #000000;">0</span>
Cur PV                <span style="color: #000000;">1</span>
Act PV                <span style="color: #000000;">1</span>
VG Size               <span style="color: #000000;">465</span>,<span style="color: #000000;">75</span> GB
PE Size               <span style="color: #000000;">32</span>,00 MB
Total PE              <span style="color: #000000;">14904</span>
Alloc PE <span style="color: #000000; font-weight: bold;">/</span> Size       <span style="color: #000000;">14904</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">465</span>,<span style="color: #000000;">75</span> GB
Free  PE <span style="color: #000000; font-weight: bold;">/</span> Size       <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">0</span>
VG UUID               D33fbC-w82v-I83g-TAgG-vZaA-8C52-1aVEfr</pre></div></div>

<p>
Et pour le créer :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># lvcreate -l 14904 VGraid -n LVraid</span></pre></div></div>

<p>
Ceci fait, <code>/dev/VGraid/LVraid</code> (également mappé sous <code>/dev/mapper/VGraid-LVraid</code>) peut être utilisé comme une partition &laquo;&nbsp;normale&nbsp;&raquo;, donc on formate et on monte normalement :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mkfs.ext3 /dev/VGraid/LVraid</span>
<span style="color: #666666; font-style: italic;"># mkdir /mnt/raid</span>
<span style="color: #666666; font-style: italic;"># mount /dev/VGraid/LVraid /mnt/raid</span></pre></div></div>

<p>
Notre filesystem est prêt à l&#8217;emploi et les données présentes dessus seront mirrorées. Pour connaître l&#8217;état de la pile RAID :
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cat /proc/mdstat</span>
Personalities : <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid1<span style="color: #7a0874; font-weight: bold;">&#93;</span>
md0 : active raid1 sdd1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sde1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">488383936</span> blocks <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UU<span style="color: #7a0874; font-weight: bold;">&#93;</span>
unused devices: <span style="color: #000000; font-weight: bold;">&lt;</span>none<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>
On voit qu&#8217;il est actif. [UU] désigne que les deux disques sont OK. En cas de problème sur un disque, cette info ressemblerait à [_U] ou [U_] suivant le disque défaillant.<br />
Il est également possible de surveiller sa matrice et d&#8217;être avertit par email en cas de panne 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;"># mdadm --monitor --mail=root@localhost --delay=1800 /dev/md0 &amp;</span></pre></div></div>

<p>
A noter que <code>--monitor</code> peut même aller plus loin et lancer un programme ou un script au lieu d&#8217;un simple email.</p>
]]></content:encoded>
			<wfw:commentRss>http://werk.feub.net/2008/12/gerer-une-pile-raid-et-lvm-sous-fedora-10/feed/</wfw:commentRss>
		<slash:comments>2</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 394/441 objects using memcached

Served from: werk.feub.net @ 2012-02-05 21:13:27 -->
