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

De WikiLICC
Ir para: navegação, pesquisa
m (/etc/exports)
m (Cliente NFS)
 
(47 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 4: Linha 4:
  
 
= Servidor NFS =
 
= Servidor NFS =
== Supporting Packages for the NFS Server ==
+
== Instalando o servidor NFS ==
Any machines that will act as NFS servers need to
+
Instalar no servidor NFS
:'''<code>apt-get install nfs-common nfs-kernel-server</code>'''
+
[root@one]$ dnf install nfs-utils rpcbind
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 ==
  
* Criar no servidor o diretório para colocar os usuários a serem exportados
+
* 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
 
  [root@one] $ cd /home
 
  [root@one] $ mkdir /home/export
 
  [root@one] $ mkdir /home/export
(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] $ mkdir /home/export/alunos
 +
[root@one] $ mkdir /home/export/docentes
 +
[root@one] $ mkdir /share
 +
 
 +
 
  
 
* Configurar o arquivo
 
* Configurar o arquivo
 
  [root@one] $ vi /etc/exports
 
  [root@one] $ vi /etc/exports
Este arquivo contém quais arquivos serão compartilhados. Para comentários use o sinal <code>#</code>.  O formato é
+
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)
 
  # <dir a ser compartilho> <clientes permitidos>(opções)
  /home/export 192.168.0.0/24(rw,no_root_squash,no_subtree_check,sync)
+
  /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 192.168.0.101(rw)  # um endereço IP
Linha 26: Linha 30:
 
  # /home/export .matrix.net(rw)    # um dominio
 
  # /home/export .matrix.net(rw)    # um dominio
 
  # /home/export 192.1680.0.1/24(rw) # um dominio
 
  # /home/export 192.1680.0.1/24(rw) # um dominio
 
(Usando endereços IP não requer que DNS esteja de pé e rodando)
 
  
 
* Ver [LDAP]
 
* Ver [LDAP]
  
 
=== Opções para /etc/exports ===
 
=== 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
 +
  [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
  
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.
+
Para verificar que o mount esta sendo compartilhado,
 +
  [root@one]$ showmount -e
 +
  Export list for one:
 +
/home/export 192.168.0.100
  
== Restarting the NFS Server (Learning to Share) ==
 
  
Go ahead and restart the nfs-kernel with
+
* http://techgurulive.com/2008/09/15/fedora-9-quick-nfs-server-howto/
: <code>'''/etc/init.d/nfs-kernel-server restart</code>'''
+
=== Monitoração ===
or with
+
Para monitorar o sistema
: '''<code>exportfs -var</code>'''
+
  [root@one]$ nfsstat
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
+
  [root@one]$ nfsstat -o net
  
gyrfalcon:~# exportfs 192.168.1.254:/shared
+
= Cliente NFS (usando DRBL) =
  
To make sure that the mount is being shared, use <code>showmount -e</code>.  You should see the shared directories listed:
+
== Pacotes para o cliente NFS ==
<pre>
+
Instalar nos clientes NFS
gyrfalcon:/user# showmount -e
+
[root@cell100]$ yum install nfs-utils rpcbind
Export list for gyrfalcon:
 
/shared 192.168.1/17
 
</pre>
 
  
= Cliente NFS =
+
* Criar no cliente um diretório para colocar os diretórios a serem importados
 
+
  [root@cell100] $ cd /home
This is part three of a three page tutorial on NFS. The full tutorial includes
+
[root@cell100] $ mkdir /home/export
 
 
* [[Mounted File System: NFS]]
 
* [[NFS Server]]
 
* [[NFS Client]]
 
 
 
== NFS Client Packages ==
 
Any machines that will act as NFS clients and will be using the shared filesystem need to
 
:'''<code>apt-get install nfs-common</code>'''
 
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>
+
Adicione a última linha ao arquivo (será montado automaticamente quando a máquina é iniciada)
 
+
[root@cell100] $ vi /etc/fstab
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
+
#
 +
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
  
:<code><NFS server>:<remote location></code>
+
Usando defaults utiliza as opções setadas no servidor NFS em <code>/etc/exports</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>.
+
Para montar o diretório NFS sem resetar a máquina use
 +
[root@cell100 /]# mount -v 192.168.0.99:/share /share
  
My <code>/etc/fstab</code> looks like this.
+
Usando mount é possível ver os diretórios montados.
 +
[root@cell100 /]# mount
  
<pre>
+
=== Criar link simbólico===
# /etc/fstab: static file system information.
+
  [root@cell100] $ mkdir /share
#
+
  [root@cell100] $ cd /share
# <file system> <mount point>  <type> <options>      <dump>  <pass>
+
  [root@cell100] $ ln -s /home/dago /share/dago
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
 
 
 
: '''<code>mount <mount point></code>'''
 
 
 
For instance, mine would be <code>mount /shared</code>.  Similarly, you can also do <code>umount <mount point></code> to unmount a filesystem.
 
  
 
== 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 126: 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