NFS Setup on CentOS 6.x

1. Required packages for NFS installation;

Need nfs-utils and rpcbind;

2. Use the following commands to check if the above packages are already installed on the system:

  rpm -qa|grep nfs

  rpm -qa|grep rpcbind  

  If already installed, proceed directly to step 3; if not, run the following command to install:

  yum install nfs-utils rpcbind

3. Configure the server side

  Create the mount directory and mount it, use the following commands:

  mkdir /opt/data

  cd /opt/data

  mkdir test

  Then edit the /etc/exports file, which defines the shared directories and sharing rules:

  vi /etc/exports

  Add the following line to the file:

  /opt/data 192.168.1.0/24(rw,no_root_squash)

  This line means the NFS shared directory is /opt/data, accessible by IPs in the 192.168.1.0/24 subnet, with read-write access, and clients can access as root user;

  After making changes, save and exit;

  Then run service nfs restart to restart the NFS service;

4. Disable the firewall, use the following command:

  service iptables stop

5. Configure the client side

  The operating system on the client is the same as on the server; nfs-utils and rpcbind also need to be installed;

  After installation, check whether you can access the NFS service normally:

  showmount -e 192.168.1.104

  The following result indicates normal access:

  Export list for 192.168.1.104  
/opt/
data 192.168.1.104

  Then use the following command to create an association between the local directory and the server mount point:

  mkdir /opt/dataltest

  mount -t nfs 10.0.113.237:/opt/data/  /opt/data/

  Then run ls /opt/data to see the files in the shared directory on the server from the client side, and you can read from and write to the files in the shared directory.
6. Configure automatic mounting at boot as follows:
vi /etc/fstab
Add the following line at the end of the file:
192.168.0.104:/opt/data /opt/data nfs  rw  0 2

Leave a Comment

Your email address will not be published.