Linux mount remote nfs

Chapter 3. Mounting NFS shares

As a system administrator, you can mount remote NFS shares on your system to access shared data.

3.1. Introduction to NFS

This section explains the basic concepts of the NFS service.

A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. This enables you to consolidate resources onto centralized servers on the network.

The NFS server refers to the /etc/exports configuration file to determine whether the client is allowed to access any exported file systems. Once verified, all file and directory operations are available to the user.

3.2. Supported NFS versions

This section lists versions of NFS supported in Red Hat Enterprise Linux and their features.

Currently, Red Hat Enterprise Linux 8 supports the following major versions of NFS:

  • NFS version 3 (NFSv3) supports safe asynchronous writes and is more robust at error handling than the previous NFSv2; it also supports 64-bit file sizes and offsets, allowing clients to access more than 2 GB of file data.
  • NFS version 4 (NFSv4) works through firewalls and on the Internet, no longer requires an rpcbind service, supports Access Control Lists (ACLs), and utilizes stateful operations.

NFS version 2 (NFSv2) is no longer supported by Red Hat.

Default NFS version

The default NFS version in Red Hat Enterprise Linux 8 is 4.2. NFS clients attempt to mount using NFSv4.2 by default, and fall back to NFSv4.1 when the server does not support NFSv4.2. The mount later falls back to NFSv4.0 and then to NFSv3.

Features of minor NFS versions

Following are the features of NFSv4.2 in Red Hat Enterprise Linux 8:

Server-side copy Enables the NFS client to efficiently copy data without wasting network resources using the copy_file_range() system call. Sparse files Enables files to have one or more holes , which are unallocated or uninitialized data blocks consisting only of zeroes. The lseek() operation in NFSv4.2 supports seek_hole() and seek_data() , which enables applications to map out the location of holes in the sparse file. Space reservation Permits storage servers to reserve free space, which prohibits servers to run out of space. NFSv4.2 supports the allocate() operation to reserve space, the deallocate() operation to unreserve space, and the fallocate() operation to preallocate or deallocate space in a file. Labeled NFS Enforces data access rights and enables SELinux labels between a client and a server for individual files on an NFS file system. Layout enhancements Provides the layoutstats() operation, which enables some Parallel NFS (pNFS) servers to collect better performance statistics.

Читайте также:  Locate any file in linux

Following are the features of NFSv4.1:

  • Enhances performance and security of network, and also includes client-side support for pNFS.
  • No longer requires a separate TCP connection for callbacks, which allows an NFS server to grant delegations even when it cannot contact the client: for example, when NAT or a firewall interferes.
  • Provides exactly once semantics (except for reboot operations), preventing a previous issue whereby certain operations sometimes returned an inaccurate result if a reply was lost and the operation was sent twice.

3.3. Services required by NFS

This section lists system services that are required for running an NFS server or mounting NFS shares. Red Hat Enterprise Linux starts these services automatically.

Red Hat Enterprise Linux uses a combination of kernel-level support and service processes to provide NFS file sharing. All NFS versions rely on Remote Procedure Calls (RPC) between clients and servers. To share or mount NFS file systems, the following services work together depending on which version of NFS is implemented:

nfsd The NFS server kernel module that services requests for shared NFS file systems. rpcbind Accepts port reservations from local RPC services. These ports are then made available (or advertised) so the corresponding remote RPC services can access them. The rpcbind service responds to requests for RPC services and sets up connections to the requested RPC service. This is not used with NFSv4. rpc.mountd This process is used by an NFS server to process MOUNT requests from NFSv3 clients. It checks that the requested NFS share is currently exported by the NFS server, and that the client is allowed to access it. If the mount request is allowed, the nfs-mountd service replies with a Success status and provides the File-Handle for this NFS share back to the NFS client. rpc.nfsd This process enables explicit NFS versions and protocols the server advertises to be defined. It works with the Linux kernel to meet the dynamic demands of NFS clients, such as providing server threads each time an NFS client connects. This process corresponds to the nfs-server service. lockd This is a kernel thread that runs on both clients and servers. It implements the Network Lock Manager (NLM) protocol, which enables NFSv3 clients to lock files on the server. It is started automatically whenever the NFS server is run and whenever an NFS file system is mounted. rpc.statd This process implements the Network Status Monitor (NSM) RPC protocol, which notifies NFS clients when an NFS server is restarted without being gracefully brought down. The rpc-statd service is started automatically by the nfs-server service, and does not require user configuration. This is not used with NFSv4. rpc.rquotad This process provides user quota information for remote users. The rpc-rquotad service, which is provided by the quota-rpc package, has to be started by user when the nfs-server is started. rpc.idmapd

Читайте также:  Linux shared memory limit

This process provides NFSv4 client and server upcalls, which map between on-the-wire NFSv4 names (strings in the form of user @ domain ) and local UIDs and GIDs. For idmapd to function with NFSv4, the /etc/idmapd.conf file must be configured. At a minimum, the Domain parameter should be specified, which defines the NFSv4 mapping domain. If the NFSv4 mapping domain is the same as the DNS domain name, this parameter can be skipped. The client and server must agree on the NFSv4 mapping domain for ID mapping to function properly.

Only the NFSv4 server uses rpc.idmapd , which is started by the nfs-idmapd service. The NFSv4 client uses the keyring-based nfsidmap utility, which is called by the kernel on-demand to perform ID mapping. If there is a problem with nfsidmap , the client falls back to using rpc.idmapd .

The RPC services with NFSv4

The mounting and locking protocols have been incorporated into the NFSv4 protocol. The server also listens on the well-known TCP port 2049. As such, NFSv4 does not need to interact with rpcbind , lockd , and rpc-statd services. The nfs-mountd service is still required on the NFS server to set up the exports, but is not involved in any over-the-wire operations.

Additional resources

Источник

Как смонтировать общий ресурс NFS в Linux

Сетевая файловая система (NFS) — это протокол распределенной файловой системы, который позволяет вам обмениваться удаленными каталогами по сети. С помощью NFS вы можете монтировать удаленные каталоги в своей системе и работать с удаленными файлами, как если бы они были локальными файлами.

В операционных системах Linux и UNIX вы можете использовать команду mount для монтирования общего каталога NFS в определенной точке монтирования в локальном дереве каталогов.

В этом руководстве мы покажем вам, как вручную и автоматически смонтировать общий ресурс NFS на машинах Linux.

Установка клиентских пакетов NFS

Чтобы смонтировать общий ресурс NFS в системе Linux, сначала необходимо установить клиентский пакет NFS. Название пакета отличается в разных дистрибутивах Linux.

Читайте также:  Linux serial port terminal gui

    Установка клиента NFS в Ubuntu и Debian:

sudo apt update sudo apt install nfs-common
sudo yum install nfs-utils

Монтирование файловых систем NFS вручную

Подключение удаленного общего ресурса NFS аналогично монтированию обычных файловых систем.

Чтобы смонтировать файловую систему NFS в заданной точке монтирования, используйте команду mount в следующей форме:

mount [OPTION. ] NFS_SERVER:EXPORTED_DIRECTORY MOUNT_POINT 

Выполните следующие действия, чтобы вручную смонтировать удаленный общий ресурс NFS в вашей системе Linux:

    Сначала создайте каталог, который будет точкой монтирования для удаленного общего ресурса NFS:

sudo mount -t nfs 10.10.0.10:/backups /var/backups

После монтирования общего ресурса точка монтирования становится корневым каталогом смонтированной файловой системы.

Когда вы монтируете общий ресурс вручную, подключение общего ресурса NFS не сохраняется после перезагрузки.

Автоматическое монтирование файловых систем NFS с помощью /etc/fstab

Как правило, вы хотите автоматически монтировать удаленный каталог NFS при загрузке системы.

Файл /etc/fstab содержит список записей, определяющих, где, как и какая файловая система будет монтироваться при запуске системы.

Чтобы автоматически монтировать общий ресурс NFS при запуске системы Linux, добавьте строку в файл /etc/fstab . Строка должна включать имя хоста или IP-адрес сервера NFS, экспортированный каталог и точку монтирования на локальном компьютере.

Используйте следующую процедуру для автоматического монтирования общего ресурса NFS в системах Linux:

    Настройте точку монтирования для удаленного общего ресурса NFS:

#     10.10.0.10:/backups /var/backups nfs defaults 0 0
mount /var/backups mount 10.10.0.10:/backups

Размонтирование файловых систем NFS

Команда umount отсоединяет (размонтирует) смонтированную файловую систему от дерева каталогов.

Чтобы отсоединить смонтированный общий ресурс NFS, используйте команду umount за которой следует либо каталог, в котором он был смонтирован, либо удаленный общий ресурс:

umount 10.10.0.10:/backups umount /var/backups

Если для монтирования NFS есть запись в fstab , удалите ее.

Команда umount не сможет отсоединить общий ресурс, когда смонтированный том используется. Чтобы узнать, какие процессы обращаются к общему ресурсу NFS, используйте команду fuser :

Как только вы найдете процессы, вы можете остановить их с помощью команды kill и отключить общий ресурс NFS.

Если у вас все еще есть проблемы с —lazy ресурса, используйте параметр -l ( —lazy ), который позволяет вам отключать загруженную файловую систему, как только она больше не занята.

Если удаленная система NFS недоступна, используйте параметр -f ( —force ) для принудительного размонтирования.

Как правило, не рекомендуется использовать опцию принудительного выполнения, так как это может повредить данные в файловой системе.

Выводы

Мы показали вам, как подключать и отключать удаленный общий ресурс NFS. Те же команды применимы для любого дистрибутива Linux, включая Ubuntu, CentOS, RHEL, Debian и Linux Mint.

Не стесняйтесь оставлять комментарии, если у вас есть вопросы.

Источник

Оцените статью
Adblock
detector