Sharing NFS filesystem in linux
-------------------------------
1. Source server - standalone2
2. Target server- rhel11gr2rac1
Sharing NFS file system will be very helpful in real time environment, its enables a particular
file-system to be mounted across the servers for easy access.
Lets see an example on show to share the NFS.
On Source server.
-----------------
1. Set up the yum repository environment.
2. Install the NFS rpm's using yum
[root@standalone2 ~]# yum -y install nfs-utils nfs-utils-lib
Loaded plugins: security
Setting up Install Process
Package 1:nfs-utils-1.0.9-54.el5.x86_64 already installed and latest version
Package nfs-utils-lib-1.0.8-7.6.el5.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils-lib.i386 0:1.0.8-7.6.el5 set to be updated
--> Processing Dependency: libgssapi.so.2(libgssapi_CITI_2) for package: nfs-utils-lib
--> Processing Dependency: libgssapi.so.2 for package: nfs-utils-lib
--> Running transaction check
---> Package libgssapi.i386 0:0.10-2 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
nfs-utils-lib i386 1.0.8-7.6.el5 Server 55 k
Installing for dependencies:
libgssapi i386 0.10-2 Server 22 k
Transaction Summary
========================================================================================================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 77 k
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 652 kB/s | 77 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libgssapi 1/2
Installing : nfs-utils-lib 2/2
Installed:
nfs-utils-lib.i386 0:1.0.8-7.6.el5
Dependency Installed:
libgssapi.i386 0:0.10-2
Complete!
3. Create an directory and create some sample files.
[root@standalone2 public]# mkdir /shared_nfs
[root@standalone2 public]# cd /shared_nfs/
[root@standalone2 shared_nfs]# echo "File1" > file1.txt
[root@standalone2 shared_nfs]# echo "File2" > file2.txt
[root@standalone2 shared_nfs]# echo "File3" > file3.txt
[root@standalone2 shared_nfs]# ls -lrt
total 12
-rw-r--r-- 1 root root 6 Jun 9 03:35 file1.txt
-rw-r--r-- 1 root root 6 Jun 9 03:35 file2.txt
-rw-r--r-- 1 root root 6 Jun 9 03:35 file3.txt
4. Now we need to make the /shared_nfs directory to be shared, we need to update that in export file.
[root@standalone2 shared_nfs]# vi /etc/exports
/shared_nfs 192.168.0.20(rw,sync)
There /shared_nfs is the directory which we are going to share, 192.68.0.20 is the ip address of the target server,
(rw is read / write , or you can update as ro for read only , sync is for sync).
5. Start or restart the NFS service on the server.
[root@standalone2 public]# service nfs restart
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
if rhel6 if you get below error then start the rpcbind
[root@apache-datnd1 shared_nfs]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]
[root@apache-datnd1 shared_nfs]# service rpcbind start
Starting rpcbind: [ OK ]
[root@apache-datnd1 shared_nfs]#
[root@apache-datnd1 shared_nfs]#
[root@apache-datnd1 shared_nfs]#
[root@apache-datnd1 shared_nfs]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
On Target Server
----------------
1. Install the NFS related rpm on the target server.
[root@rhel11gr2rac1 pub]# yum -y install nfs-utils nfs-utils-lib
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Package nfs-utils-lib-1.0.8-7.6.el5.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.0.9-54.el5 set to be updated
---> Package nfs-utils-lib.i386 0:1.0.8-7.6.el5 set to be updated
--> Processing Dependency: libgssapi.so.2(libgssapi_CITI_2) for package: nfs-utils-lib
--> Processing Dependency: libgssapi.so.2 for package: nfs-utils-lib
--> Running transaction check
---> Package libgssapi.i386 0:0.10-2 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
nfs-utils-lib i386 1.0.8-7.6.el5 ser 55 k
Updating:
nfs-utils x86_64 1:1.0.9-54.el5 ser 404 k
Installing for dependencies:
libgssapi i386 0.10-2 ser 22 k
Transaction Summary
========================================================================================================================================================================
Install 2 Package(s)
Upgrade 1 Package(s)
Total download size: 480 k
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 23 MB/s | 480 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libgssapi 1/4
Installing : nfs-utils-lib 2/4
Updating : nfs-utils 3/4
Cleanup : nfs-utils 4/4
Installed:
nfs-utils-lib.i386 0:1.0.8-7.6.el5
Dependency Installed:
libgssapi.i386 0:0.10-2
Updated:
nfs-utils.x86_64 1:1.0.9-54.el5
Complete!
2. You can display the nfs which are shared from the source server using below.
[root@rhel11gr2rac1 shared_from_192.168.0.30]# showmount -e 192.168.0.30
Export list for 192.168.0.30:
/public 192.168.0.20
/shared_nfs 192.168.0.20
-- We could see that 2 file systems are shared from the source server.
3. Create a new directory on the taret server and you can use that to mount the filesystem.
[root@rhel11gr2rac1 shared_from_192.168.0.30]# mkdir /shared_file_nfs
[root@rhel11gr2rac1 shared_from_192.168.0.30]# mount 192.168.0.30:/shared_nfs /shared_file_nfs
[root@rhel11gr2rac1 shared_from_192.168.0.30]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 21G 18G 2.7G 87% /
/dev/sda1 289M 17M 258M 6% /boot
tmpfs 816M 0 816M 0% /dev/shm
/dev/sdb1 25G 14G 9.8G 59% /oracle
192.168.0.30:/shared_nfs
21G 14G 6.4G 68% /shared_file_nfs
-- Now we could see that the NFS is mounted on the target server.