Setting Up an NFS server on CentOS 7 - saviovettoor/DevOps-wiki GitHub Wiki
Setting Up an NFS server on CentOS 7
NFS mounts will help you to share a directory between several servers. This has the advantage of saving disk space, as the home directory is only kept on one server, and others can connect to it over the network.
An NFS mount is set up between at least two servers. Master: 10.150.18.229 (who share the file) Client: 10.150.17.38 (Which connect to/use file)
Setting Up the NFS Server
Installing necessary packages in the server
yum install nfs-utils nfs-utils-lib
Subsequently, run several startup scripts for the NFS server:
]#chkconfig nfs on
]#service rpcbind start
]#service nfs start
Export the Shared Directory The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.
Suppose you want share /opt/shared_folder
We need to export the directory:
]#vi /etc/exports
/opt/shared_folder 10.150.17.38(rw,sync,no_root_squash,no_subtree_check)
rw --> Read Write permission sync --> synchronized mode no_root_squash --> the remote root user will be treated as a root and will be able to change any file and directory. no_subtree_check --> When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
Now let Mount remote file system on client Discover NFS shares from the client showmount -e 10.150.18.229
mount -t nfs 10.150.18.229:/opt/shared_folder /mnt/
Configure automount
To make this completely transparent to end users, you can automount the NFS file system every time when Linux system boot.
Add the following entry in /etc/fstab 10.150.18.229:/opt/shared_folder /mnt/ nfs defaults 0 0
How to Unmount NFS Suppose you want unmount the mounted folder in client run the following command
]$umount -f -l /mnt/
-f – Force unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or later.) -l – Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore