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 line:/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, read/write; RO: Read-only, read-only; Sync: The file is written to the hard disk and memory at the same time; async: files are saved in the memory instead of directly written into the 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: regardless of the users used by the NFS client to connect to the server, the shared directory on the server has anonymous user permissions. anonuid: uid value of anonymous users, usually nobody or nfsnobody, you can set it here; anongid: the GID value of anonymous users.
3. Start:
Centos6:
[[Email protected]/] # service rpcbind start
Starting 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
[[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 1011/udp # rpc. mountd rquotad 1012/tcp # rpc. 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
How to install, configure, start, and mount NFS in centos 6.3