Setup NFS server
Step1: Packages Needed
Ensure that NFS packages are installed.
Packages needed by NFS services (based on
Centos 5.3) are:-
nfs-utils-1.0.9-40.el5
nfs-utils-lib-1.0.8-7.2.z2
portmap-4.0-65.2.2.1
|
Step2: Start the NFS services
[root@srv1 ~]#
service nfs status
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@srv1
demo]#
service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
|
Step 3: Check and Verify the NFS
process and Portmap
[root@srv1 demo]# ps aux |
grep nfs
root 5900 0.0 0.0 0 0 ? S< 17:34 0:00 [nfsd4]
root 5901 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5902 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5903 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5904 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5905 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5906 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5907 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5908 0.0 0.0 0 0 ? S 17:34 0:00 [nfsd]
root 5930 0.0 0.0 3912 688 pts/3 S+ 17:34 0:00 grep nfs[root@srv1 demo]# ps aux |
grep portmap
rpc 2580 0.0 0.0 1808 560 ? Ss 08:11 0:00 portmap
root 5932 0.0 0.0 3912 672 pts/3 R+ 17:34 0:00 grep portmap
[root@srv1 demo]#
ps aux | grep
rpc
rpc 2580 0.0 0.0 1808 560 ? Ss 08:11 0:00 portmap
root 2605 0.0 0.0 1852 740 ? Ss 08:11 0:00 rpc.statd
root 2638 0.0 0.0 0 0 ? S< 08:11 0:00 [rpciod/0]
root 2645 0.0 0.0 5508 596 ? Ss 08:11 0:01 rpc.idmapd
root 5896 0.0 0.0 3932 244 ? Ss 17:34 0:00 rpc.rquotad
root 5911 0.0 0.0 1908 280 ? Ss 17:34 0:00 rpc.mountd
root 5936 0.0 0.0 3912 672 pts/3 R+ 17:36 0:00 grep rpc
[root@srv1 ~]#
rpcinfo -p | grep nfs
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
|
Step 3 (optional) : if you wish to use
nfslock
[root@srv1 ~]# service nfslock start
Starting NFS statd: [ OK ]
[root@srv1 ~]# service nfslock status
rpc.statd (pid 5484) is running...
|
Step 4: Make NFS service start when
server boot.
|
[root@srv1 ~]#
chkconfig nfs on |
Step 5: Using netstat command to
check NFS active ports
[root@srv1 ~]#
netstat -lnptu | grep rpc
tcp 0 0 0.0.0.0:1002 0.0.0.0:* LISTEN 5484/rpc.statd
tcp 0 0 0.0.0.0:817 0.0.0.0:* LISTEN 5301/rpc.rquotad
tcp 0 0 0.0.0.0:831 0.0.0.0:* LISTEN 5316/rpc.mountd
udp 0 0 0.0.0.0:814 0.0.0.0:* 5301/rpc.rquotad
udp 0 0 0.0.0.0:828 0.0.0.0:* 5316/rpc.mountd
udp 0 0 0.0.0.0:996 0.0.0.0:* 5484/rpc.statd
udp 0 0 0.0.0.0:999 0.0.0.0:* 5484/rpc.statd
[root@srv1 ~]# netstat -lnptu | grep portmap
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2725/portmap
udp 0 0 0.0.0.0:111 0.0.0.0:* 2725/portmap
|
Step 6: Checking current sharing
we are using the following command
"showmount -a" or "showmount --all"
The command list both the client hostname
or IP address and mounted directory in host, since we don not have any
sharing mount point (share folders or directories), no data is shown
[root@srv1 ~]#
showmount -a
All mount points on srv1.example.local:
[root@srv1 ~]# showmount --all
All mount points on srv1.example.local:
[root@srv1 ~]#
|
"showmount -e" or "showmount -exports"
This will show the list of mount point
that server exported. since we don not have any sharing mount point
(share folders or directories), no data is shown
Export list for
srv1.example.local:
[root@srv1 ~]# showmount --exports
Export list for srv1.example.local:
[root@srv1 ~]#
|
Step 7: Creating share folders/
directories
In this example we are making two folders
[root@srv1 ~]# mkdir /public_folder
[root@srv1 ~]# mkdir /group_folder
|
Step 8: Edit /etc/exports
configuration files
/etc/exports
is a file controls which file systems (folder or directories) are
exported to remote hosts and specifies options.
A line for an exported file system has the following
structure:
<local server folder to export> <nfs client hostname
or ip address or wildcard> (options)
Please take note when you are not specified rw option
for sharing folder the folder is read-only. In the following example: /public_folder
shared to everyone in example.local (*.example.local) as read-only.
While /group_folder is only shared to 192.168.1.7 with read and write
permission all transfers to disk are committed to the disk before the
write request by the client is completed.
[root@srv1 ~]# vim /etc/exports
/public_folder *.example.local
/group_folder 192.168.1.7(rw,sync) |
Step 9: Exporting NFS sharinfto nfs
clients
The exportfs command is used to maintain
the current table of exported file systems for NFS.
The following command are useful for your
NFS export
-a
Export or unexport all directories.
-r
Re-export all directories.
-u
Unexport one or more directories.
-v
When exporting or unexporting, show what
is going on. When displaying the current export list, also display the
list of export options.
The warning below can be ignore as we are
only share it as read permission only. Your NFS is now available to
share across the network.
[root@srv1 ~]# exportfs -arv
exportfs: No options for /public_folder *.example.local: suggest *.example.local(sync)
to avoid warning
exporting 192.168.1.7:/group_folder
exporting *.example.local:/public_folder
[root@srv1 ~]# showmount -e
Export list for srv1.example.local:
/public_folder *.example.local
/group_folder 192.168.1.7
|
Option : To un-export all NFS sharing
To un-export all NFS sharing we must use
exportfs together with "a" and "u"
[root@srv1 ~]# exportfs -auv
[root@srv1 ~]# showmount -e
Export list for srv1.example.local:
|
|