Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

12.2 NFS network file system


May 24, 2021 That's what Linux should learn



If you think the configuration of Theamba service program is too cumbersome, and it happens that the hosts that need to share files are Linux systems, Mr. Liu is very recommended that you deploy NFS services on the client side to share files. The NFS (Network File System) service can mount file-sharing resources on a remote Linux system to the directory of the local host, enabling the local host (Linux client) to read and write shared files on the remote Linux system as if using resources on the local host, based on the TCP/IP protocol.

Since the NFS service is already installed by default in the RHEL 7 system, plus the configuration steps for the NFS service are simple, Mr. Liu will joke about NFS as Need For Speed when teaching. N ext, we're going to configure the NFS service. First, use the Yum repository to check if NFS packages are installed in your RHEL 7 system:

[root@linuxprobe ~]# yum install nfs-utils Loaded plugins: langpacks, product-id, subscription-manager (1/2): rhel7/group_gz | 1 34 kB 00:00 (2/2): rhel7/primary_db | 3.4 MB 00:00 Package 1:nfs-utils-1.3.0-0.el7.x86_64 already installed and latest version to do Step 1: In order to verify the effectiveness of the NFS service configuration, we need to use two Linux hosts (one as an NFS server, one as an NFS client) and set the IP address address they use in accordance with Table 12-6.

Table 12-6 The operating system and IP address used by the two Linux hosts

Host Name Operating System IP Address NFS Service Side RHEL 7 192.168.10.10 NFS Client RHEL 7 192.168.10.20 Also, don't forget to empty the default policy of the iptables firewall above the NFS server to prevent the default firewall policy from blocking normal NFS sharing services.

root@linuxprobe step 2: Build a directory for NFS file root@linuxprobe sharing on the NFS server and set sufficient permissions to ensure that others also have write permissions.

root@linuxprobe s/nfsfile s/root@linuxprobe s/s linuxprobe.com root@linuxprobe/s We can define the directory to share with the appropriate permissions in the format of "Shared Directory Path Allows Access to NFS Clients (Shared Permission Parameters).

For example, if you want to share the /nfsfile directory with all hosts in the 192.168.10.0/24 segment, have them have read and write permissions before writing data to the NFS server The hard disk will not end until the operation is completed, to ensure maximum data loss, and to map the visiting client root administrator to an anonymous local user, etc., you can write the parameters in Table 12-7 to the profile of the NFS service program in the following command format.

Table 12-7 is used to configure the parameters of the NFS service program profile

Parameter action ro read-only rw read and write root_squash When the NFS client is accessed by the root administrator, the anonymous user mapped to the NFS server no_root_squash when the NFS client is accessed by the root administrator, the root administrator mapped to the NFS server all_squash the anonymous sync user mapped to the NFS server writes data to both the memory and the hard disk To ensure that data is not lost async takes precedence over saving data to memory and then writing to the hard disk;

step root@linuxprobe 4: Start and enable the N root_squash FS service program. B ecause before you can share files with the NFS service, you need to use the RPC (Remote Procedure Call, Remote Procedure Call) service to send information such as the IP address and port number of the NFS server to the client. Therefore, before you can start an NFS service, you also need to reboot and enable the rpcbind service program and add the two services to the boot item.

(root@linuxprobe root@linuxprobe root@linuxprobe root@linuxprobe. Server ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service' NFS client configuration steps are also simple. The remote sharing information of the NFS server is queried first using the showmount command (and the necessary parameters, see Table 12-8), and its output format is "Shared directory name allows client addresses to be used".

The parameters and effects available in the Table 12-8 showmount command

Parameter Action - e Show a shared list of NFS servers -a Show the situation of the file resources mounted on the machine NFS resources -v Show version number ( root@linuxprobe . . . showmount - e 192.168.10. 10 Export list for 192.168.10.10: /nfsfile 192.168.10. then create an mount directory on the NFS client. Use the mount command and combine the -t parameter to specify the type of file system to mount, and write the IP address of the server, the shared directory on the server, and the directory to mount to the local system (i.e. the client) after the command.

the root@linuxprobe s/nfsfile s/nfsfile s/root@linuxprobe snfsfile snfs 192.168.10.10:/nfsfile should be able to see the contents of the file written when the previous operation is performed. If you want the NFS file sharing service to be valid all the time, you need to write it to the fstab file:

[root@linuxprobe ~]# cat /nfsfile/readme welcome to linuxprobe.com [root@linuxprobe ~]# vim /etc/fstab #

/etc/fstab

  1. # Created by anaconda on Wed May 4 19:26:23 2017
  2. #
  3. # Accessible filesystems, by reference, are maintained under '/dev/disk'
  4. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  5. #
  6. /dev/mapper/rhel-root / xfs defaults 1 1
  7. UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2
  8. /dev/mapper/rhel-swap swap swap defaults 0 0
  9. /dev/cdrom /media/cdrom iso9660 defaults 0 0
  10. 192.168.10.10:/nfsfile /nfsfile nfs defaults 0 0