Monday, December 23, 2024
HomeLinuxHow to install and configure NFS in RHEL 7/ CentOS 7

How to install and configure NFS in RHEL 7/ CentOS 7

NFS, stands for Network File System, helps you to share files and folders between Linux / Unix systems, developed by SUN Microsystems in 1990. NFS enables you to mount a remote share locally. This guide helps you to setup NFS server on CentOS 7 / RHEL 7. Here will see how to install and configure NFS in RHEL 7/CentOS 7

Step 1: Verify a package

Before start installing NFS package make sure it’s not install in a server

# rpm –qa nfs

If there is no output you can proceed step 2, or skip step 2 and move to step 3

Step 2: installing NFS-Server

To install NFS packages in NFS Server, use following commend

# yum install nfs-utils libnfsidmap –y

Once we installed NFS, now we need to start and enable the NFS service

For Enable

# systemctl enable rpcbind

# systemctl enable nfs-server

To Start, make sure you are starting in this order, or you will get error

# systemctl start rpcbind

# systemctl start nfs-server

# systemctl start rpc-statd

# systemctl start nfs-idmapd

 Services:

rpcbind : The rpcbind server converts RPC program numbers into universal addresses.

nfs-server :  It enables the clients to access NFS shares.

nfs-lock / rpc-statd : NFS file locking. Implement file lock recovery when an NFS server crashes and reboots.

nfs-idmap : It translates user and group ids into names, and to translate user and group names
into ids

Step 3: Creating NFS-Share

Here let we create share folder under / partition

# mkdir /NFSSHARE

Allow the client to read and write in created share folder

# chmod 777 /NFSSHARE

Now we need give entry in “/etc/exports”, to share the folder via NFS

# vim /etc/exports

/NFSSHARE xx.xx.xxx.xxx(rw,sync,no_root_squash)

Here,

/NFSSHARE – is a share folder

xx.xx.xxx.xxx   You can replace this with any IP

rw – read/write permission to the shared folder

sync – all changes to the according filesystem are immediately flushed to disk;

no_root_squash : By default, any file request made by user root on the client machine is treated as by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user “nobody” on the server, not the client.) If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server.

Step 4: Export the share folder

For exporting share folder

# exportfs –r

More,

exportfs -v : Displays a list of shares files and export options on a server

exportfs -a : Exports all directories listed in /etc/exports

exportfs -u : Unexport one or more directories

exportfs -r : Reexport all directories after modifying /etc/exports

Configure Firewall:

We need to configure firewall on NFS server to allow client servers to access NFS shares

firewall-cmd –permanent –zone public –add-service mountd

firewall-cmd –permanent –zone public –add-service rpc-bind

firewall-cmd –permanent –zone public –add-service nfs

firewall-cmd –reload

Step 5: Install NFS in Client

Install and start the NFS service in client (RHEL 6)

To install NFS

# yum install nfs* –y

To enable NFS

# chkconfig nfs on

# chkconfig rpcbind on

To start the service

# /etc/init.d/nfs start

# /etc/init.d/rpcbind start

 Step 6: Mounting share in Client

Before mounting share folder, let check the available shares using

# showmount –e IP

Export list for xxx.xxx.xxx.xxx

/NFSSHARE yyy.yyy.yyy.yyy

Replace with valid IPs

Now we can mount the nfs share in client, to mount create /mnt/myshare folder

# mkdir /mnt/myshare

# mount <Server.IP>:/NFSSHARE /mnt/myshare

Now share folder mounted successfully. This is temporary mount only, it will went of after reboot, for permanent mount we need to make entries in /etc/fstab

# vim /etc/fstab

<Server IP>:/NFSSHARE/ /mnt/myshare nfs rw,sync,hard,intr 0 0

Note: this is sample entry only.

Once you make entry now you can reboot the client and check.

To UnMount:

# umount /mnt/myshare

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments