I. Environment Introduction:
Server: centos 6.4 _ 64nfs_server_ip
Server: centos 6.4 _ 64 nfs_client_ip
Ii. installation:
NFS installation Configuration:
Centos 5.x:
Yum install nfs-utils Portmap
Centos 6.x (in centos 6.3 and centos 6.4, the Portmap service is undertaken by rpcbind ):
Yum 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/nfs_client_ip (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.
Nfs_client_ip (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, for example, * .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:
Centos 6.x:
[[Email protected]/] # service rpcbind start
Starting rpcbind: [OK]
[[Email protected]/] # service NFS start
Starting NFS services: [OK]
Starting NFS quotas: [OK]
Starting NFS mountd: [OK]
Starting RPC idmapd: [OK]
Starting NFS daemon: [OK]
[[Email protected]/] #
Centos 5.x:
[[Email protected] localhost/] # service Portmap start
[[Email protected] localhost/] # service NFS start
[[Email protected] localhost/] #
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 nfs_server_ip
[[Email protected] ~] #
If: RPC Mount export: RPC: unable to receive; errno = No route to host is displayed, disable the firewall on the server.
3. Mount:
[[Email protected] ~] # Mount-t nfs nfs_server_ip:/usr/local/test
[[Email protected] ~] # Mount
/Dev/mapper/VolGroup-lv_root on/type ext4 (RW)
Nfs_server_ip:/usr/local/test on/usr/local/testtype NFS (RW, Vers = 4, ADDR = nfs_server_ip, clientaddr = nfs_client_ip)
[[Email protected] ~] #
If the information above is displayed, the mounting is successful!
4. test:
Create a file on the client:
[[Email protected]/] # cd/usr/local/test/
[[Email protected] # echo "NFS test"> test.txt
[[Email protected] # ll
-RW-r -- 1 Root 16 Apr 10 15:24 test.txt
[[Email protected] Test] #
5. Server check:
[[Email protected]/] # cd/usr/local/test/
[[Email protected] Test] # ll
-RW-r -- 1 Root 16 Apr 10 15: 24test.txt
[[Email protected] localhost/test] #
Mounted successfully!
5. unmount:
[[Email protected] ~] # Umount/usr/local/test
[[Email protected] ~] # Mount
/Dev/mapper/VolGroup-lv_root on/type ext4 (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-ptcp -- 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
This article from the "Lin Xi" blog, please be sure to keep this source http://lutaoxu.blog.51cto.com/4224602/1571858
Deploy NFS and test NFS