Installation configuration and mount Method for centos5 and 6 NFS

Source: Internet
Author: User
Tags nfsd
 

I. Environment Introduction:

Server: centos 192.168.1.225

Client: centos 192.168.1.226

 

Ii. installation:

NFS installation Configuration:
Centos 5:

yum -y install nfs-utils portmap

Centos 6 (in centos 6.3, The Portmap service is undertaken by rpcbind ):

yum -y install nfs-utils rpcbind

 

Iii. Server Configuration:

1. Create a shared directory:

[[email protected] /]# mkdir /usr/local/test

2. NFS file Configuration:

[[Email protected]/] # vi/etc/exports
# Add a row:
/Usr/local/test/192.168.1.226 (RW, no_root_squash, no_all_squash, sync)

: X save and exit;

Make the configuration take effect:

[[email protected] /]# exportfs -r

Note: configuration file description:

/Usr/local/test/is the shared directory. Use the absolute path.
192.168.1.226 (RW, no_root_squash, no_all_squash, sync) is the client address and permission. The address can be a network segment, an IP address or a domain name. The domain name supports wildcards, such as * .youxia.com, there is no space between the address and permission. Permission description:
RW: read-write, which can be read and written;
RO: Read-only, read-only;
Sync: writes files to both the hard disk and memory;
Async: files are stored in memory instead of directly written into memory;
No_root_squash: If the NFS client uses root to connect to the server, it also has root permissions for the Directory shared by the server. It is obviously not safe to enable this feature.
Root_squash: If the NFS client uses root to connect to the server, it has anonymous user permissions for the Directory shared by the server. Generally, it uses nobody or nfsnobody;
All_squash: No matter which user the NFS client uses to connect to the server, the directory shared by the server is anonymous;
Anonuid: uid value of an anonymous user, usually nobody or nfsnobody, which can be set here;
Anongid: the GID value of an anonymous user.

3. Start:

Centos6:

 

[[email protected] /]# service rpcbind startStarting rpcbind:                                          [  OK  ][[email protected] /]# service 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  ][[email protected] /]# 

 

Centos 5

[[email protected] /]# service portmap start[[email protected] /]# service nfs start[[email protected] /]# 

 

4. Client mounting:

1. Create a directory to be mounted:

[[email protected] ~]# mkdir /usr/local/test[[email protected] ~]# 

2. Test mounting:

[[email protected] ~]# showmount -e 192.168.1.225Export list for 192.168.1.225:/usr/local/test 192.168.1.226[[email protected] ~]# 

If: RPC Mount export: RPC: unable to receive; errno = No route to host is displayed, disable the firewall on the server (which will be detailed later ).

3. Mount:

[[email protected] ~]# mount -t nfs 192.168.1.225:/usr/local/test /usr/local/test[[email protected] ~]# mount/dev/mapper/VolGroup-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)/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.225:/usr/local/test on /usr/local/test type nfs (rw,vers=4,addr=192.168.1.225,clientaddr=192.168.1.226)[[email protected] ~]# 

If the information above is displayed, the mounting is successful!

4. test:

The client generates a file:

[[email protected] /]# cd /usr/local/test/[[email protected] test]# echo "hello nfs test">>test[[email protected] test]# lltotal 4-rw-r--r-- 1 root root 15 Apr  9 13:24 test[[email protected] test]# 

Server check:

[[email protected] /]# cd /usr/local/test/[[email protected] test]# lltotal 4-rw-r--r-- 1 root root 15 Apr  9 13:24 test[[email protected] test]# 

Mounted successfully!

 

5. unmount:

[[email protected] ~]# umount /usr/local/test[[email protected] ~]# mount/dev/mapper/VolGroup-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)/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)[[email protected] ~]# 

If: umount. NFS:/usr/local/test: device is busy

You may use the following command:

[[Email protected]/] # Fuser-m-V/usr/local/test user Process Code permission command/usr/local/test/: Root 2798 .. c .. bash root 2996 .. c .. su [[email protected]/] # Kill-9 2798 [[email protected]/] # Kill-9 2996 [[email protected]/] # umount/usr/local/test [[email protected]/] #

 

Vi. server-side firewall settings (enable firewall protection for NFS ):

1. Modify/etc/service and add the following content (the port number must be less than 1024 and is not in use)

# Local services
MOUNTD 1011/tcp # rpc. mountd
MOUNTD 1011/udp # rpc. mountd
Rquotad 1012/tcp # rpc. rquotad
Rquotad 1012/udp # rpc. rquotad

2. Restart the Linux NFS service

Service NFS restart

 

3. Now the RPC-related port has been fixed. You can add firewall rules for Linux NFS.

# Portmap
/Sbin/iptables-A input-s 192.168.1.0/254-p tcp -- dport 111-J accept
/Sbin/iptables-A input-s 192.168.1.0/254-p udp -- dport 111-J accept
# Nfsd
/Sbin/iptables-A input-s 192.168.1.0/254-p tcp -- dport 2049-J accept
/Sbin/iptables-A input-s 192.168.1.0/254-p udp -- dport 2049-J accept
# Mountd
/Sbin/iptables-A input-s 192.168.1.0/254-p tcp -- dport 1011-J accept
/Sbin/iptables-A input-s 192.168.1.0/254-p udp -- dport 1011-J accept
# Rquotad
/Sbin/iptables-A input-s 192.168.1.0/254-p tcp -- dport 1012-J accept
/Sbin/iptables-A input-s 192.168.1.0/254-p udp -- dport 1012-J accept
# Rpc. statd
/Sbin/iptables-A input-s 192.168.1.0/254-p tcp -- dport 32768-J accept
/Sbin/iptables-A input-s 192.168.1.0/254-p udp -- dport 32768-J accept

--- TCP method success -------------------------------------------
-A input-M state -- state new-m tcp-p tcp -- dport 111-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 2049-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 1011-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 1012-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 32768-J accept

 

When the client is mounted, the following problem occurs: the network may be unstable. By default, NFS uses the UDP protocol instead of the TCP protocol:

 

Mount-t nfs 192.168.1.225:/usr/local/test-O proto = TCP-O nolock

Installation configuration and mount Method for centos5 and 6 NFS

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.