Mudanças entre as edições de "Minicluster:NFS"

De WikiLICC
Ir para: navegação, pesquisa
m
m (Cliente NFS)
 
(52 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 4: Linha 4:
  
 
= Servidor NFS =
 
= Servidor NFS =
This is part two of a three page tutorial on setting up NFS.  The full tutorial includes
+
== Instalando o servidor NFS ==
 
+
Instalar no servidor NFS
* [[Mounted File System: NFS]]
+
[root@one]$ dnf install nfs-utils rpcbind
* [[NFS Server]]
 
* [[NFS Client]]
 
 
 
== Supporting Packages for the NFS Server ==
 
Any machines that will act as NFS servers need to
 
:'''<code>apt-get install nfs-common nfs-kernel-server</code>'''
 
Included in the dependencies for these is <code>portmap</code>, which is responsible for communicating on the proper ports and passing connections over.
 
  
 
== /etc/exports ==
 
== /etc/exports ==
  
Next, <code>/etc/exports</code> needs to be configuredThis file, automatically installed, controls which part of the server's file system will be shared with the other machines. Comments can be added with the <code>#</code> sign. The format of the file is
+
* Criar no servidor o diretório para colocar os usuários a serem exportados (não usar o próprio <code>/home</code> pois ele já existe nas máquinas clientes, pois assim arquivos não serão montados sobre os arquivos locais).
 
+
  [root@one] $ cd /home
:<code>'''<directory to share> <allowed machines>(options)'''</code>
+
  [root@one] $ mkdir /home/export
 +
  [root@one] $ mkdir /home/export/alunos
 +
[root@one] $ mkdir /home/export/docentes
 +
[root@one] $ mkdir /share
  
(Notice that there's no space between the allow client machine specification and the opening parentheses for the options.)
 
  
For mounting users' home directories (more about this with [[User Authentication: LDAP|LDAP]]), it's often wise to mount the directory some place other than <code>/home</code> because all of the Debian machines will already have a <code>/home</code> directory.  For instance, I'm using <code>/shared</code> because it doesn't already exist on all of my NFS clients, and there won't be confusion with mounting over files already in that directory.
 
  
The clients can be specified a variety of ways: by IP address, domain name, or CIDR mask. Below in my example, I'm allowing all machines with an IP in my network range (192.168.1.1 - 192.168.1.254) to mount this file. Since I'll also be configuring them with [[Name Service: DNS and BIND | DNS]] to be <code>X.raptor.loc</code>, I could also use <code>*.raptor.loc</code> for my clients.  (However, using IP addresses doesn't require DNS to be up and running, taking out one possible point of failure, and so is generally more stable.)  Multiple specifications for a given mount point may be space-separated with parentheses immediately following each client specification, like the following.
+
* Configurar o arquivo
 +
[root@one] $ vi /etc/exports
 +
Este arquivo contém quais arquivos serão compartilhados. (Usando endereços IP não requer que DNS esteja de pé e rodando)
 +
  # <dir a ser compartilho> <clientes permitidos>(opções)
 +
/home/export 192.168.0.0/24(rw,no_root_squash,sync,subtree_check,no_wdelay)
 +
/share      192.168.0.100(ro)
 +
#
 +
  # /home/export 192.168.0.101(rw)  # um endereço IP
 +
  # /home/export cell101(rw)        # uma maquina
 +
# /home/export .matrix.net(rw)     # um dominio
 +
  # /home/export 192.1680.0.1/24(rw) # um dominio
  
:<code>'''<directory to share> <allowed machines #1>(options for #1) <allowed machines #2>(options for #2)'''</code>
+
* Ver [LDAP]
  
=== Options for /etc/exports include ===
+
=== Opções para /etc/exports ===
* <code>rw/ro</code> - <code>rw</code> allows both reads and writes to the filesystem.  NFS acts read only (<code>ro</code>) by default.
+
* <code>rw</code> - permite read e write ao sistema de arquivos.
* <code>async/sync</code> - The asynchronous option allows the NFS server to respond to requests before committing changes.  According to <code>man</code>, this can improve performance but can corrupt data in the event of a crash.  Synchronous is the default.
+
* <code>ro</code> - read only é o default do NFS.
 +
* <code>async/sync</code> - Assíncrona perminte que o servidor NFS respond to requests before committing changes.  According to <code>man</code>, this can improve performance but can corrupt data in the event of a crash.  Synchronous is the default.
 
* <code>wdelay/no_wdelay</code> - Write delay allows the NFS server to put off committing changes to disk if it suspects that another write is coming shortly.
 
* <code>wdelay/no_wdelay</code> - Write delay allows the NFS server to put off committing changes to disk if it suspects that another write is coming shortly.
 
* <code>subtree_check/no_subtree_check</code> - Subtree checking improves security by checking not just that the client has rights to mount a directory, but all of the directory's subdirectories as well.  Subtree checking is enabled by default, but the NFS server will complain if you don't specifically indicate it.
 
* <code>subtree_check/no_subtree_check</code> - Subtree checking improves security by checking not just that the client has rights to mount a directory, but all of the directory's subdirectories as well.  Subtree checking is enabled by default, but the NFS server will complain if you don't specifically indicate it.
 
* <code>root_squash/no_root_squash</code> - Root squashing prevents a root user on a machine using the filesystem to act as it if is the root user on the actual filesystem; this is more secure.  It is on by default.
 
* <code>root_squash/no_root_squash</code> - Root squashing prevents a root user on a machine using the filesystem to act as it if is the root user on the actual filesystem; this is more secure.  It is on by default.
  
My <code>/etc/exports</code> file looks like this:
+
== Reiniciando o servidor NFS ==
  /shared   192.168.1.0/24(sync,no_wdelay,subtree_check,rw,root_squash)
+
[root@one]$ systemctl start  nfs
 
+
  [root@one]$ systemctl stop  rpcbind   # portmap para versões antigas
I am mounting gyrfalcon's <code>/shared</code> directory for any machines within my internal IP range. Sync is enabled, so the NFS server finishes writing changes to disk before responding to new requests. I do not have a write delay, so changes will be immediately written. Any subdirectories will also be checked for proper permissions before being mounted.  The directory will be readable and writable, and root on any NFS clients will not have the same rights as root on gyrfalcon itself.
+
  [root@one]$ systemctl start rpcbind  # portmap para versões antigas
 
+
ou na ordem contrária.
== Restarting the NFS Server (Learning to Share) ==
+
Para modificar outras diretivas NFS não padrões, modifique /etc/sysconfig/nfs
 
 
Go ahead and restart the nfs-kernel with
 
: <code>'''/etc/init.d/nfs-kernel-server restart</code>'''
 
or with
 
: '''<code>exportfs -var</code>'''
 
Both methods restart the NFS server.  <code>exportfs</code> can also be used to restart the behavior just towards a specific client.  Just to eyrie, for example, would be
 
  
  gyrfalcon:~# exportfs 192.168.1.254:/shared
+
Para verificar que o mount esta sendo compartilhado,
 +
  [root@one]$  showmount -e
 +
Export list for one:
 +
/home/export 192.168.0.100
  
To make sure that the mount is being shared, use <code>showmount -e</code>.  You should see the shared directories listed:
 
<pre>
 
gyrfalcon:/user# showmount -e
 
Export list for gyrfalcon:
 
/shared 192.168.1/17
 
</pre>
 
  
= Cliente NFS =
+
* http://techgurulive.com/2008/09/15/fedora-9-quick-nfs-server-howto/
 +
=== Monitoração ===
 +
Para monitorar o sistema
 +
[root@one]$ nfsstat
 +
[root@one]$ nfsstat -o net
  
This is part three of a three page tutorial on NFS.  The full tutorial includes
+
= Cliente NFS (usando DRBL) =
  
* [[Mounted File System: NFS]]
+
== Pacotes para o cliente NFS ==
* [[NFS Server]]
+
Instalar nos clientes NFS  
* [[NFS Client]]
+
[root@cell100]$ yum install nfs-utils rpcbind
  
== NFS Client Packages ==
+
* Criar no cliente um diretório para colocar os diretórios a serem importados
Any machines that will act as NFS clients and will be using the shared filesystem need to
+
[root@cell100] $ cd /home
:'''<code>apt-get install nfs-common</code>'''
+
  [root@cell100] $ mkdir /home/export
Again, <code>portmap</code> is included with <code>nfs-common</code>, so it doesn't need to be installed separately. Then <code>/etc/fstab</code> needs to be configured.
 
  
 
== /etc/fstab ==
 
== /etc/fstab ==
<code>/etc/fstab</code> provides the opposite functionality as <code>/etc/exports</code> - rather than telling what to export, this file tells the machine what to import and where to mount it.  In other words, this includes eventhing it needs to mount, even its own hard drives, floppy drives, cdrom drives, and such.  The format of this file is as follows:
+
Este arquivo fornece a funcionalidade oposta ao <code>/etc/exports</code> - ao invés de contar o que exportar, informa o que importar.  
 
 
<source to mount from> <local mount point> <type of filesystem> <options> <dump> <pass>
 
 
 
You'll want to add the NFS line under any existing lines, so that it gets mounted after your local drives.  When you specify an NFS mount, use
 
 
 
:<code><NFS server>:<remote location></code>
 
 
 
You should be able to use the <code>defaults</code> option, which uses the options you set up in <code>/etc/exports</code> on the NFS server, and <code>dump</code> and <code>pass</code> don't need to enabled, so they can have <code>0's</code>.
 
  
My <code>/etc/fstab</code> looks like this.
+
Adicione a última linha ao arquivo (será montado automaticamente quando a máquina é iniciada)
 +
[root@cell100] $ vi /etc/fstab
 +
#
 +
UUID=4410482b-b774-4129-8df7-e91bced7206d /     ext4    defaults        1 1
 +
UUID=4083cf64-0477-476c-a116-a39c7f47847b /boot  ext3    defaults        1 2
 +
UUID=1d1ee881-d431-46df-b387-d180f239f388 swap  swap    defaults        0 0
 +
tmpfs                      /dev/shm            tmpfs  defaults        0 0
 +
devpts                      /dev/pts            devpts  gid=5,mode=620  0 0
 +
sysfs                      /sys                sysfs  defaults        0 0
 +
proc                        /proc                proc    defaults        0 0
 +
192.168.0.99:/home/export  /home/export        nfs    defaults        0 0
  
<pre>
+
Usando defaults utiliza as opções setadas no servidor NFS em <code>/etc/exports</code>.
# /etc/fstab: static file system information.
 
#
 
# <file system> <mount point>  <type> <options>      <dump>  <pass>
 
proc            /proc          proc    defaults        0      0
 
/dev/sda1      /              ext3    defaults,errors=remount-ro 0      1
 
/dev/sda2      none            swap    sw              0      0
 
/dev/hdb        /media/cdrom0  udf,iso9660 user,noauto    0      0
 
/dev/fd0        /media/floppy0  auto    rw,user,noauto  0      0
 
192.168.1.200:/shared    /shared  nfs    defaults        0      0
 
</pre>
 
  
After specifying it in <code>/etc/fstab</code>, it will automatically be mounted when the machine starts up, if the mount point exists. (If you're using <code>/shared</code> or another directory that isn't automatically created as part of Debian, you'll need to create the directory.)  To mount it without having to reboot, use
+
Para montar o diretório NFS sem resetar a máquina use
 +
[root@cell100 /]# mount -v 192.168.0.99:/share /share
  
: '''<code>mount <mount point></code>'''
+
Usando mount é possível ver os diretórios montados.
 +
[root@cell100 /]# mount
  
For instance, mine would be <code>mount /shared</code>. Similarly, you can also do <code>umount <mount point></code> to unmount a filesystem.
+
=== Criar link simbólico===
 +
[root@cell100] $ mkdir /share
 +
[root@cell100] $ cd /share
 +
  [root@cell100] $ ln -s /home/dago /share/dago
  
 
== Troubleshooting: NFS Mounts not Loading at Boot ==
 
== Troubleshooting: NFS Mounts not Loading at Boot ==
 
I had a problem with my firewall not automatically mounting the NFS systems at boot, for whatever reason.  I could issue <code>mount -a</code> as root as soon as the system booted up, but it wouldn't boot at load time, despite the <code>/etc/fstab</code> file.  To "hack fix" it, I added my own script at <code>/etc/rcS.d/S46mymount</code>.  (46 runs right after S45mountnfs.sh and S46mountnfs-bootclean.sh.)  It needs to be executable (<code>chmod +x nfshack</code>), but the file itself is simply:
 
I had a problem with my firewall not automatically mounting the NFS systems at boot, for whatever reason.  I could issue <code>mount -a</code> as root as soon as the system booted up, but it wouldn't boot at load time, despite the <code>/etc/fstab</code> file.  To "hack fix" it, I added my own script at <code>/etc/rcS.d/S46mymount</code>.  (46 runs right after S45mountnfs.sh and S46mountnfs-bootclean.sh.)  It needs to be executable (<code>chmod +x nfshack</code>), but the file itself is simply:
  
<pre>
+
#!/bin/bash
#!/bin/bash
+
mount -a
 
 
mount -a
 
</pre>
 
 
 
If anyone knows of a better fix for this, please contact me at kwanous <at> debianclusters <dot> org.
 
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Linha 124: Linha 115:
 
  Starting portmap daemon....
 
  Starting portmap daemon....
 
  [maquina~] $ mount /shared
 
  [maquina~] $ mount /shared
 +
 +
 +
Ferramentas:
 +
[root]$ chkconfig
 +
[root]$ system-config-services
 +
[root]$ rpcinfo -p
 +
[root]$ /usr/sbin/ntsysv        # servicos inicicializados.
 +
Tudo que é importante é logged em /var/log/messages.
 +
 +
;Erros:
 +
[root@cell100 etc]# mount -v 192.168.0.99:/home/export2 /home/export2/
 +
mount.nfs: trying text-based options 'vers=4,addr=192.168.0.99,clientaddr=192.168.0.100'
 +
mount.nfs: mount(2): No route to host
 +
Causa: Provavelmente firewall ativa. Desativar iptables ou consertar.
  
 
== Veja ==
 
== Veja ==
 
* http://www.debianhelp.co.uk/nfs.htm
 
* http://www.debianhelp.co.uk/nfs.htm
 
* http://uwsg.indiana.edu/usail/network/nfs/tips.html
 
* http://uwsg.indiana.edu/usail/network/nfs/tips.html
 +
 +
*http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch04_:_Simple_Network_Troubleshooting
 +
*http://tldp.org/HOWTO/NFS-HOWTO/troubleshooting.html, Dicas
 +
*http://www.linuxconfig.org/HowTo_configure_NFS

Edição atual tal como às 22h05min de 27 de junho de 2017

O Network File System (NFS) permite que todo o cluster compartilhe parte de seu sistema de arquivos. Neste paradigma, uma ou mais máquinas guardam os arquivos no seu disco físico e agem como um servidor NFS enquanto que os outros "mount" o sistema de arquivos localmente. Para o usuário, parece que seus arquivos existem em todas as máquinas de uma só vez.

Se houver mais de um servidor de arquivos (digamos MESTRE1 e MESTRE2), eles não podem compartilhar o mesmo diretório /home (mas um poder compartilhar o /home/students e o outro pode compartilhar /home/faculty.)

Servidor NFS

Instalando o servidor NFS

Instalar no servidor NFS

[root@one]$ dnf install nfs-utils rpcbind

/etc/exports

  • Criar no servidor o diretório para colocar os usuários a serem exportados (não usar o próprio /home pois ele já existe nas máquinas clientes, pois assim arquivos não serão montados sobre os arquivos locais).
[root@one] $ cd /home
[root@one] $ mkdir /home/export
[root@one] $ mkdir /home/export/alunos
[root@one] $ mkdir /home/export/docentes
[root@one] $ mkdir /share


  • Configurar o arquivo
[root@one] $ vi /etc/exports

Este arquivo contém quais arquivos serão compartilhados. (Usando endereços IP não requer que DNS esteja de pé e rodando)

# <dir a ser compartilho> <clientes permitidos>(opções)
/home/export 192.168.0.0/24(rw,no_root_squash,sync,subtree_check,no_wdelay)
/share       192.168.0.100(ro)
#
# /home/export 192.168.0.101(rw)   # um endereço IP
# /home/export cell101(rw)         # uma maquina
# /home/export .matrix.net(rw)     # um dominio
# /home/export 192.1680.0.1/24(rw) # um dominio
  • Ver [LDAP]

Opções para /etc/exports

  • rw - permite read e write ao sistema de arquivos.
  • ro - read only é o default do NFS.
  • async/sync - Assíncrona perminte que o servidor NFS respond to requests before committing changes. According to man, this can improve performance but can corrupt data in the event of a crash. Synchronous is the default.
  • wdelay/no_wdelay - Write delay allows the NFS server to put off committing changes to disk if it suspects that another write is coming shortly.
  • subtree_check/no_subtree_check - Subtree checking improves security by checking not just that the client has rights to mount a directory, but all of the directory's subdirectories as well. Subtree checking is enabled by default, but the NFS server will complain if you don't specifically indicate it.
  • root_squash/no_root_squash - Root squashing prevents a root user on a machine using the filesystem to act as it if is the root user on the actual filesystem; this is more secure. It is on by default.

Reiniciando o servidor NFS

[root@one]$ systemctl start  nfs
[root@one]$ systemctl stop   rpcbind   # portmap para versões antigas
[root@one]$ systemctl start  rpcbind   # portmap para versões antigas

ou na ordem contrária. Para modificar outras diretivas NFS não padrões, modifique /etc/sysconfig/nfs

Para verificar que o mount esta sendo compartilhado,

[root@one]$  showmount -e
Export list for one:
/home/export 192.168.0.100


Monitoração

Para monitorar o sistema

[root@one]$ nfsstat
[root@one]$ nfsstat -o net

Cliente NFS (usando DRBL)

Pacotes para o cliente NFS

Instalar nos clientes NFS

[root@cell100]$ yum install nfs-utils rpcbind
  • Criar no cliente um diretório para colocar os diretórios a serem importados
[root@cell100] $ cd /home
[root@cell100] $ mkdir /home/export

/etc/fstab

Este arquivo fornece a funcionalidade oposta ao /etc/exports - ao invés de contar o que exportar, informa o que importar.

Adicione a última linha ao arquivo (será montado automaticamente quando a máquina é iniciada)

[root@cell100] $ vi /etc/fstab
#
UUID=4410482b-b774-4129-8df7-e91bced7206d /      ext4    defaults        1 1
UUID=4083cf64-0477-476c-a116-a39c7f47847b /boot  ext3    defaults        1 2
UUID=1d1ee881-d431-46df-b387-d180f239f388 swap   swap    defaults        0 0
tmpfs                       /dev/shm             tmpfs   defaults        0 0
devpts                      /dev/pts             devpts  gid=5,mode=620  0 0
sysfs                       /sys                 sysfs   defaults        0 0
proc                        /proc                proc    defaults        0 0
192.168.0.99:/home/export   /home/export         nfs     defaults        0 0

Usando defaults utiliza as opções setadas no servidor NFS em /etc/exports.

Para montar o diretório NFS sem resetar a máquina use

[root@cell100 /]# mount -v 192.168.0.99:/share /share

Usando mount é possível ver os diretórios montados.

[root@cell100 /]# mount

Criar link simbólico

[root@cell100] $ mkdir /share
[root@cell100] $ cd /share
[root@cell100] $ ln -s /home/dago /share/dago

Troubleshooting: NFS Mounts not Loading at Boot

I had a problem with my firewall not automatically mounting the NFS systems at boot, for whatever reason. I could issue mount -a as root as soon as the system booted up, but it wouldn't boot at load time, despite the /etc/fstab file. To "hack fix" it, I added my own script at /etc/rcS.d/S46mymount. (46 runs right after S45mountnfs.sh and S46mountnfs-bootclean.sh.) It needs to be executable (chmod +x nfshack), but the file itself is simply:

#!/bin/bash
mount -a

Troubleshooting

Algumas vezes um erro ocorre:

[maquina~] $ mount /shared
mount: RPC: Timed out

Reiniciando o serviço portmap funcionou para o autor:

[maquina~] $ /etc/init.d/portmap stop
Stopping portmap daemon....
[maquina~] $ /etc/init.d/portmap start
Starting portmap daemon....
[maquina~] $ mount /shared


Ferramentas:

[root]$ chkconfig
[root]$ system-config-services
[root]$ rpcinfo -p
[root]$ /usr/sbin/ntsysv        # servicos inicicializados.

Tudo que é importante é logged em /var/log/messages.

Erros
[root@cell100 etc]# mount -v 192.168.0.99:/home/export2 /home/export2/
mount.nfs: trying text-based options 'vers=4,addr=192.168.0.99,clientaddr=192.168.0.100'
mount.nfs: mount(2): No route to host

Causa: Provavelmente firewall ativa. Desativar iptables ou consertar.

Veja