工作点滴/

Ubuntu Server 18.04安装NFS

Configure NFS Server

[1] Configure NFS Server.

root@dlp:~# apt -y install nfs-kernel-server
root@dlp:~# vi /etc/idmapd.conf
# line 6: uncomment and change to your domain name
Domain = srv.world
root@dlp:~# vi /etc/exports
# write settings for NFS exports
/home 10.0.0.0/24(rw,no_root_squash)
root@dlp:~# systemctl restart nfs-server

For basic options of exports

OptionDescription
rwAllow both read and write requests on a NFS volume.
roAllow only read requests on a NFS volume.
syncReply to requests only after the changes have been committed to stable storage. (Default)
asyncThis option allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage.
secureThis option requires that requests originate on an Internet port less than IPPORT_RESERVED (1024). (Default)
insecureThis option accepts all ports.
wdelayDelay committing a write request to disc slightly if it suspects that another related write request may be in progress or may arrive soon. (Default)
no_wdelayThis option has no effect if async is also set. The NFS server will normally delay committing a write request to disc slightly if it suspects that another related write request may be in progress or may arrive soon. This allows multiple write requests to be committed to disc with the one operation which can improve performance. If an NFS server received mainly small unrelated requests, this behaviour could actually reduce performance, so no_wdelay is available to turn it off.
subtree_checkThis option enables subtree checking. (Default)
no_subtree_checkThis option disables subtree checking, which has mild security implications, but can improve reliability in some circumstances.
root_squashMap requests from uid/gid 0 to the anonymous uid/gid. Note that this does not apply to any other uids or gids that might be equally sensitive, such as user bin or group staff.
no_root_squashTurn off root squashing. This option is mainly useful for disk-less clients.
all_squashMap all uids and gids to the anonymous user. Useful for NFS exported public FTP directories, news spool directories, etc.
no_all_squashTurn off all squashing. (Default)
anonuid=UIDThese options explicitly set the uid and gid of the anonymous account. This option is primarily useful for PC/NFS clients, where you might want all requests appear to be from one user. As an example, consider the export entry for /home/joe in the example section below, which maps all requests to uid 150.
anongid=GIDRead above (anonuid=UID)

Configure NFS Client

Configure NFS Client.
This example is based on the environment below.

+----------------------+          |          +----------------------+
| [    NFS Server    ] |10.0.0.30 | 10.0.0.31| [    NFS Client    ] |
|     dlp.srv.world    +----------+----------+    client.srv.world  |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1] Configure NFS Client.

root@client:~# apt -y install nfs-common
root@client:~# vi /etc/idmapd.conf
# line 6: uncomment and change to your domain name
Domain = srv.world
root@client:~# mount -t nfs dlp.srv.world:/home /home 
root@client:~# df -hT 
Filesystem                  Type      Size  Used Avail Use% Mounted on
udev                        devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                       tmpfs     395M  600K  394M   1% /run
/dev/mapper/ubuntu--vg-root ext4       29G  1.7G   26G   7% /
tmpfs                       tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                       tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs                       tmpfs     395M     0  395M   0% /run/user/0
dlp.srv.world:/home         nfs4       29G  1.7G   26G   7% /home
# /home from NFS server is mounted

# if you'd like to mount with NFSv3, add '-o vers=3' option
root@client:~# mount -t nfs -o vers=3 dlp.srv.world:/home /home

[2] Configure NFS mounting on fstab to mount it when the system boot.

root@client:~# vi /etc/fstab
# add like follows
 dlp.srv.world:/home   /home  nfs     defaults        0       0

[3] Configure auto-mounting if you need. For example, set NFS directory on /mntdir.

root@client:~# apt -y install autofs
root@client:~# vi /etc/auto.master
# add follows to the end
 /-    /etc/auto.mount

root@client:~# vi /etc/auto.mount
# create new : [mount point] [option] [location]
 /mntdir -fstype=nfs,rw  dlp.srv.world:/home

root@client:~# mkdir /mntdir 
root@client:~# systemctl restart autofs
# move to the mount point to verify it works normally
root@client:~# cd /mntdir 
root@client:/mntdir# ll 
total 12
drwxr-xr-x  3 root   root   4096 Apr 27 10:47 ./
drwxr-xr-x 24 root   root   4096 May 10 12:39 ../
drwxr-xr-x  4 ubuntu ubuntu 4096 Apr 27 11:00 ubuntu/

root@client:/mntdir# cat /proc/mounts | grep mntdir 
/etc/auto.mount /mntdir autofs rw,relatime,fd=6,pgrp=13749,timeout=300,minproto=5,maxproto=5,
direct,pipe_ino=36330 0 0
dlp.srv.world:/home /mntdir nfs4 rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,
hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.31,local_lock=none,addr=10.0.0.30 0 0

NFS 4 ACL Tool

https://www.server-world.info/en/note?os=Ubuntu_18.04&p=nfs&f=3

留下一条评论

暂无评论