NFS file sharing service

Posted by dan90joe on Thu, 06 Jan 2022 03:00:31 +0100

NFS file sharing service

Introduction:

NFS is a network file system

A general sharing solution for sharing file system through network developed by sun company;

The NFS listening port is tcp 2049 port;

RPC service records port information, ip address, etc

RPC: remote procedure call protocol;

Use nfs file sharing and enable rpcbind service;

NFS configuration explanation

/Rules for writing etc/exports files

  • Blank lines can be ignored
  • #Is the content of the comment
  • You can use \ escape characters
  • Shared files and directories need to be written on a new line
  • The host list needs to be separated by spaces
  • Wildcards are supported

The format is as follows:

Shared path client host (option)
Shared path client host 1 (option) client host 2 (option)
[root@master ~]# vim /etc/exports 
/ks     192.168.75.0/255.255.255.0(ro)
/mnt/cdrom      192.168.75.0/255.255.255.0)(ro)


Type of option:

  • ro: read only
  • rw: writable
  • sync: synchronize write operations
  • async: asynchronous write operation; This option means that the user can be prompted when the client writes, but the data is actually in the memory of the server
  • wdelay: delay write operation; Put all the information into the memory first, and then put it into the hard disk at the same time to reduce the number of I/O to the hard disk;
  • root_squash: Mask remote root permissions
  • no_root_squash: do not mask remote root permissions
  • all_ Square: block all remote user permissions

NFS file share setup

plan:

192.168.75.40 is the nfs server

192.168.75.41 is the client

nfs deployment

#install
[root@master ~]# yum -y install nfs-utils rpcbind
[root@master ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-12.el6.x86_64
nfs-utils-1.2.3-70.el6.x86_64

#Prepare two shared directories
[root@master ~]# mkdir /data/nfs
[root@master ~]# mkdir /data/read
[root@master ~]# chmod a+w /data/nfs/ /data/read/

#Add user
[root@master ~]# useradd liangjiawei
useradd: User“ liangjiawei"Already exists

#Write shared information
[root@master ~]# vim /etc/exports
/data/nfs       192.168.75.41(rw,async,no_root_squash)
/data/read      192.168.75.41(ro,sync)

#Start nfs service
#rpcbind must be started before startup
[root@master ~]# service rpcbind start
[root@master ~]# service nfs start
 start-up NFS Services: exportfs: Invalid netmask `255.255.255.0)' for 192.168.75.0/255.255.255.0)
exportfs: Invalid netmask `255.255.255.0)' for 192.168.75.0/255.255.255.0)
                                                           [determine]
start-up NFS mountd:                                           [determine]
start-up NFS Daemons:                                        [determine]
Starting RPC idmapd:                                       [determine]

Client authentication

#First, take a look at the shared files of the nfs client
[root@Node1 ~]# showmount -e 192.168.75.140
Export list for 192.168.75.140:
/data/read 192.168.75.141/24
/data/nfs  192.168.75.140/24


#Create mount point
[root@Node1 ~]# mkdir -p /data/nfs-client
[root@Node1 ~]# mkdir -p /data/nfs-read

#Mount test
[root@Node1 ~]# mount 192.168.75.140:/data/nfs /data/nfs-client/
[root@Node1 ~]# mount 192.168.75.140:/data/read /data/nfs-read/

#Write content
[root@Node1 ~]# cd /data/nfs-client/
[root@Node1 nfs-client]# touch node1.txt
[root@Node1 nfs-client]# ls
node1.txt

[root@Node1 nfs-client]# cd ../nfs-read/
[root@Node1 nfs-read]# touch haha
touch: could not be built"haha": Read-only file system 


#If the client has an ordinary user and the nfs server also has the same permissions to mount and create
[root@Node1 nfs-read]# useradd liangjiawei
[root@Node1 nfs-read]# passwd  liangjiawei
 Change user liangjiawei Your password.
New password:
Re enter the new password:
passwd:  All authentication tokens have been successfully updated.
[root@Node1 nfs-read]# su - liangjiawei
[liangjiawei@Node1 ~]$ cd /data/nfs-client/
[liangjiawei@Node1 nfs-client]$ touch liangjiawei.txt
[liangjiawei@Node1 nfs-client]$ ll
 Total consumption 0
-rw-rw-r-- 1 liangjiawei liangjiawei 0 9 April 22:47 liangjiawei.txt
-rw-r--r-- 1 root        root        0 9 April 22:45 node1.txt

Services required by nfs

  • nfs: This is the main program
  • nfslock: provides a locking mechanism
  • rpcbind: provides address and port registration services
  • rpc.mountd: handle other NFSv2 and NFSv3 requests
  • bockd: kernel thread
  • rpc.statd: implement network monitoring NSM protocol
  • rpc.rquotad: quota related
  • rpc.idmapd: provide NFSv4 name mapping, / etc / idmapd Conf must be configured;

nfs client configuration

If everything in Linux is a file, the nfs client configuration command is as follows:

mount -t nfs -o option server host: shared directory local mount directory

The options for mounting are as follows:

  • intr: when the server allows terminal NFS requests in time
  • nfsvers=version: Specifies the protocol used by nfs
  • noacl: close ACL
  • nolock: turns off the file locking mechanism
  • noexec: Mask executable binaries in mounted file systems
  • port=num: Specifies the port number of NFS
  • rsize=num: Specifies the speed at which nfs reads data
  • wsize=num: set the maximum data block size and adjust the write speed of NFS
  • tcp: tcp protocol mount is used
  • UDP: Mount using UDP protocol

exportfs command

Function: view the NFS open mount information in the LAN

Syntax: exportfs + option

Options:

  • -r: Reread the / etc/exports file
  • -a: Share all or cancel sharing all
  • -u: Cancel sharing, usually with - a
  • -v: Displays nfs version information
[root@Node0 /]# exportfs -r
exportfs: No options for /data *: suggest *(sync) to avoid warning

rpcinfo command

Function: generate RPC information report

Syntax: rpcinfo + option

Options:

  • -m: Displays the rpcbind operation information table of the specified host
  • -p: Displays RPC registration information for the specified host
  • -s: Displays all registered RPC information programs of the specified host, and does not display local information of the specified host
[root@Node0 /]# rpcinfo  -p 127.0.0.1
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
............

nfsstat command

Role: view the loading of NFS shares

Syntax: nfsstat + option

option

  • -s: Display server status
  • -n: Show nfs status only
  • -c: Show client status
  • -n: N is a number, 234. View the version status information of nfs
  • -m: Display mount information
  • -l: Displays information about registered RPC s for the specified host

Topics: Linux network server