Imaginons un environnement de développement web avec des serveurs LAMP virtuels sous VMWare.
Mon premier reflexe a été d’installer un serveur FTP sur le serveur LAMP.
Utile, mais pas flexible.
Imaginons justement pour plus de flexibiltié, qu’on veuille modifier les fichiers directement sur un répertoire partagé.
C’est là que NFS entre en jeux !
La procédure suivante est pour Ubuntu Server 9.10 et un client OpenSuse 11.2.
Sources : http://doc.ubuntu-fr.org/nfs – http://doc.ubuntu-fr.org/tutoriel/un_simple_partage_nfs – http://smhteam.info/wiki/index.linux.php5?wiki=NFS
Installation de NFS :
1 |
<span style="vertical-align: top;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nfs-kernel-server nfs-common</span> |
Dans le répertoire qui sera partagé, noter l’utilisateur et le groupe utilisé :
1 |
<span style="vertical-align: top;">root<span style="color: #000000; font-weight: bold;">@</span>ub-lamp-<span style="color: #000000;">1</span>:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #666666; font-style: italic;"># ll</span></span><br /><span style="vertical-align: top;"><span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> geeko www-data <span style="color: #000000;">135</span> <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">28</span> <span style="color: #000000;">22</span>:<span style="color: #000000;">38</span> index.html</span><span style="vertical-align: top;"> </span><span style="vertical-align: top;"> </span><span style="vertical-align: top;"> <br /></span> |
Dans l’exemple ci-dessus, l’utilisateur est geeko et le groupe est www-data.
Sur le serveur, récupérer l’id de l’utilisateur et du groupe pour la modification et la création des fichiers et répertoires :
1 |
<span style="vertical-align: top;">root<span style="color: #000000; font-weight: bold;">@</span>ub-lamp-<span style="color: #000000;">1</span>:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #666666; font-style: italic;"># su - geeko</span></span><br /><span style="vertical-align: top;">geeko<span style="color: #000000; font-weight: bold;">@</span>ub-lamp-<span style="color: #000000;">1</span>:~$ <span style="color: #c20cb9; font-weight: bold;">id</span></span><br /><span style="vertical-align: top;"><span style="color: #007800;">uid</span>=<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">(</span>geeko<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">(</span>geeko<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #007800;">groupes</span>=<span style="color: #000000;">33</span><span style="color: #7a0874; font-weight: bold;">(</span>www-data<span style="color: #7a0874; font-weight: bold;">)</span>,<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">(</span>geeko<span style="color: #7a0874; font-weight: bold;">)</span></span> |
Dans l’exemple ci-dessus, l’id de l’utilisateur est 1000 et celui du groupe est 33.
Modification du fichier /etc/exports
1 |
<span style="vertical-align: top;"><span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www 192.168.46.1<span style="color: #7a0874; font-weight: bold;">(</span>rw,<span style="color: #c20cb9; font-weight: bold;">sync</span>,all_squash,<span style="color: #007800;">anonuid</span>=<span style="color: #000000;">1000</span>,<span style="color: #007800;">anongid</span>=<span style="color: #000000;">33</span><span style="color: #7a0874; font-weight: bold;">)</span></span> |
Il faut remplacer les valeurs anonuid et anongid par celle que vous avez notées plus haut;
Démarrer le serveur :
1 |
<span style="vertical-align: top;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nfs-kernel-server start</span> |
Coté client, j’ai une OpenSuse 11.2.
Je vais dans Yast > Client NFS
- Bouton « Ajouter »
- Nom de machine du serveur NFS : 192.168.46.128 (modifier l’adresse ip en fonction)
- Cliquer sur le bouton « Sélectionner » le plus à droite.
- Sélectionner le répertoire puis valider.
- Indiquer le point de montage et valider.
Dans Yast > Pare-feu
- Sélectionner « Services autorisés » dans la liste à gauche.
- Dans la liste à autoriser : Client NFS
- Cliquer sur le bouton « Ajouter »
- Ciquer sur le bouton « Suivant »
Utiliser Nautilus pour parcourir le répertoire de montage NFS (dans mon cas : /media/partage)