Set NFS server on CentOS/RHEL/ScientificLinux6.3/6.4/6.5

Source: Internet
Author: User

Set NFS server on CentOS/RHEL/ScientificLinux6.3/6.4/6.5
Http://www.tecmint.com/how-to-setup-nfs-server-in-linux/ in this tutorial, let's see how to install and configure the NFS server and how to share files between the NFS server and the client. Although I have tested these steps on CentOS 6.5 32-bit, it can also work on RHEL/Scientific Linux 6.x.
Scenario NFS Server Operating System: CentOS 6.5 32 bit (Minimal server install) NFS Client Operating System: CentOS 6.5 32 bit (Minimal Desktop install) NFS Server IP Address: 192.168.1.200/24 NFS Client IP Address: 192.168.1.29/241. install NFS on the server

[root@server ~]# yum install nfs* -y
2. Start the NFS service
[root@server ~]# /etc/init.d/nfs startStarting NFS services:                                     [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ][root@server ~]# chkconfig nfs on
3. Install NFS on the client
[root@vpn client]# yum install nfs* -y
4. Start the NFS service on the client
[root@vpn client]# /etc/init.d/nfs startStarting NFS services:                                     [  OK  ]Starting NFS quotas:                                       [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ][root@vpn client]# chkconfig nfs on
5. create a shared directory on the server. Create a shared directory named "/home/ostechnix" on the server, allow the client user to read and write files to the '/home/ostechnix' directory.
[root@server ~]# mkdir /home/ostechnix[root@server ~]# chmod 755 /home/ostechnix/
6. Export the shared directory on the server to open the/etc/exports file, as shown in add entries:
[root@server ~]# vi /etc/exports/home/ostechnix 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
Where, /home/ostechnix-shared directory 192.168.1.0/24-IP address range for client access to shared folders rw-set shared folder write sync-Synchronize shared directory no_root_squash-enable root permission (users can read, write and delete files in the shared directory) no_all_squash-allows the user to restart the NFS service now.
[root@server ~]# /etc/init.d/nfs restartShutting down NFS daemon:                                  [  OK  ]Shutting down NFS mountd:                                  [  OK  ]Shutting down NFS services:                                [  OK  ]Starting NFS services:                                     [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ]       -
7. Create a mount point in the client ing shared directory to mount the shared directory of the server. To do this, create a directory named "/nfs/shared" (you can create your own mount point)
[root@vpn client]# mkdir -p /nfs/shared
Now map the shared directory on the server, as shown in
[root@vpn client]# mount -t nfs 192.168.1.200:/home/ostechnix/ /nfs/shared/
This takes some time and displays the connection timeout error. Okay, don't be alarmed. The firewall may restrict the client from mounting and sharing from the server. Disable iptables to solve the problem. You can also set iptables to allow the NFS service port. To do this, open the/etc/sysconfig/nfs file and remove the comments marked in bold.
[root@server ~]# vi /etc/sysconfig/nfs## Define which protocol versions mountd # will advertise. The values are "no" or "yes"# with yes being the default#MOUNTD_NFS_V2="no"#MOUNTD_NFS_V3="no"### Path to remote quota server. See rquotad(8)#RQUOTAD="/usr/sbin/rpc.rquotad"# Port rquotad should listen on.RQUOTAD_PORT=875# Optinal options passed to rquotad#RPCRQUOTADOPTS=""### Optional arguments passed to in-kernel lockd#LOCKDARG=# TCP port rpc.lockd should listen on.LOCKD_TCPPORT=32803# UDP port rpc.lockd should listen on.LOCKD_UDPPORT=32769### Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)# Turn off v2 and v3 protocol support#RPCNFSDARGS="-N 2 -N 3"# Turn off v4 protocol support#RPCNFSDARGS="-N 4"# Number of nfs server processes to be started.# The default is 8. #RPCNFSDCOUNT=8# Stop the nfsd module from being pre-loaded#NFSD_MODULE="noload"# Set V4 grace period in seconds#NFSD_V4_GRACE=90#### Optional arguments passed to rpc.mountd. See rpc.mountd(8)#RPCMOUNTDOPTS=""# Port rpc.mountd should listen on.MOUNTD_PORT=892### Optional arguments passed to rpc.statd. See rpc.statd(8)#STATDARG=""# Port rpc.statd should listen on.STATD_PORT=662# Outgoing port statd should used. The default is port# is randomSTATD_OUTGOING_PORT=2020# Specify callout program #STATD_HA_CALLOUT="/usr/local/bin/foo"### Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)#RPCIDMAPDARGS=""## Set to turn on Secure NFS mounts. #SECURE_NFS="yes"# Optional arguments passed to rpc.gssd. See rpc.gssd(8)#RPCGSSDARGS=""# Optional arguments passed to rpc.svcgssd. See rpc.svcgssd(8)#RPCSVCGSSDARGS=""## To enable RDMA support on the server by setting this to# the port the server should listen on#RDMA_PORT=20049
Restart the NFS service.
[root@server ~]# /etc/init.d/nfs restartShutting down NFS daemon:                                  [  OK  ]Shutting down NFS mountd:                                  [  OK  ]Shutting down NFS services:                                [  OK  ]Starting NFS services:                                     [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ]
In '/Etc/sysconfig/iptables'Add rows in bold.
[root@server ~]# vi /etc/sysconfig/iptables# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 875 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
Restart the iptables service.
[root@server ~]# service iptables restartiptables: Flushing firewall rules:                         [  OK  ]iptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Unloading modules:                               [  OK  ]iptables: Applying firewall rules:                         [  OK  ]
Ing and sharing from the client again
[root@vpn client]# mount -t nfs 192.168.1.200:/home/ostechnix/ /nfs/shared/
Finally, the NFS share is mapped and there is no connection timeout error. To verify whether the shared directory is installed, run the mount command on the client.
[root@vpn client]# mount/dev/mapper/vg_vpn-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)192.168.1.200:/home/ostechnix/ on /nfs/shared type nfs (rw,vers=4,addr=192.168.1.200,clientaddr=192.168.1.29)
8. Test NFS now, in '/Nfs/shared'Directory to create some files or folders.
[root@vpn shared]# mkdir test[root@vpn shared]# touch file1 file2 file3
Now go to the server and change to" /Home/ostechnix"Directory.
[root@server ~]# cd /home/ostechnix/[root@server ostechnix]# lsfile1  file2  file3  test[root@server ostechnix]#
List the files and directories created by the client. You can also share files from the server to the client, and vice versa. 9. Automatic Mount sharing if you want to automatically mount the shares, instead of manually mount them at each restart, use the following client: '/Etc/fstab'Bold rows.
[root@vpn client]# vi /etc/fstab ## /etc/fstab# Created by anaconda on Wed Feb 27 15:35:14 2013## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/vg_vpn-lv_root /                       ext4    defaults        1 1UUID=59411b1a-d116-4e52-9382-51ff6e252cfb /boot                   ext4    defaults        1 2/dev/mapper/vg_vpn-lv_swap swap                    swap    defaults        0 0tmpfs                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0192.168.1.200:/home/ostechnix/nfs/sharednfsrw,sync,hard,intr0 0
10. Verify that sharing restarts your client and whether the sharing is automatically mounted.
[root@vpn client]# mount/dev/mapper/vg_vpn-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)192.168.1.200:/home/ostechnix on /nfs/shared type nfs (rw,sync,hard,intr,vers=4,addr=192.168.1.200,clientaddr=192.168.1.29)nfsd on /proc/fs/nfsd type nfsd (rw)
That's all. Have a wonderful day!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.