NFS server: xuegod63.cn IP: 192.168.1.63
NFS client: xuegod64.cn IP: 192.168.1.64
NFS server Overview:
NFS , Network File System is short for that network file system . Network File System FreeBSD is a supported file system, also known as NFS. NFS allows a system to share directories and files with others on the network. By using NFS, users and programs can access the same files as access to local files on the remote system.
Mode: C / S Mode
port:
RHEL6 is NFSv4 as the default version, NFSv4 uses TCP protocol (port number 2049) to establish a connection and NFS server
Install nfs
1 , install the NFS packages
[root@xue63 ~]#rpm -vih /mnt/Packages/nfs-utils-1.2.3-15.el6.x86_64.rpm
yum -y install nfs-utils
Install the client:
Command: mount showmount
Profile Location:
[root@xue63 ~]# ls /etc/exports
Start the NFS Services
First check whether port 2049 is open:
[root@xue63 ~]#netstat -anutp | grep 2049
[root@xue63 ~]# service nfs start
Startingntpd: [ OK ]
[root@xue63 ~]# chkconfig nfs on
View:
[root@xue63 ~]#netstat -anutp | grep 2049
View nfs service:
showmount -e NFSIP
Example:
[Root @ xuegod64 ~] #showmount 192.168.1.63 -e
Mount:
mount 192.168.1.63:/tmp/a /mnt
Modify the configuration file
[root@xue63 a]# cat /etc/exports
/media *(rw)
[root@xue63 a]# service nfs restart
Client View:
[root@localhost nfs]# showmount -e 192.168.1.63 [root@localhost nfs]# mount 192.168.1.63:/media /opt/ [root@localhost nfs]# cd /opt/ [root@localhost mnt]# touch a.txt [root@xuegod64 opt]# touch a.txt touch: cannot touch `a.txt': Permission denied
Start automatically mount nfs file system
[root@xuegod64 opt]#vim /etc/fstab [root@xuegod64 ~]#umount /opt/ [root@xuegod64 ~]#mount -a [root@xuegod64 ~]#ls /opt/ a.txt passwd
NFS server configuration:
[root@xuegod63tmp]# cat /etc/exports /media *(rw) /tmp/a/no_root_squash *(rw,no_root_squash) /tmp/a/sync 192.168.1.0/24(rw,sync) /tmp/a/ro 192.168.1.64(ro) /tmp/a/all_squash 192.168.1.0/24(rw,all_squash,anonuid=500,anongid=500) /tmp/a/async 192.168.3.0/255.255.255.0(async) /tmp/a/rw 192.168.3.0/255.255.255.0(rw) 192.168.4.0/255.255.255.0(rw) /tmp/a/root_squash *(rw,root_squash)
[root @ xuegod63tmp] # service nfs restart # restart
test:
[root@xuegod64 ~]#umount /opt/ [root@xuegod64 ~]#mount 192.168.1.63:/tmp/a/no_root_squash /opt/ [root@xuegod64 ~]#touch /opt/no_root_squash.txt [root@xuegod64 ~]#ll !$ ll/opt/no_root_squash.txt -rw-r--r-- 1 root root 0 Mar 6 22:15 /opt/no_root_squash.tx
Automatically mount
Implementation: when executed on xuegod64 CD / tmp / a / nfs command, automatically nfs share on the xuegod63 / tmp / a / root_squash directory automatically mounted to the lower xuegod64 / tmp / a / nfs directory
autofs service to mount automatically involves two files, configuration files auto.master primary and secondary profiles auto.misc
/etc/auto.master file defines the local mount point.
/etc/auto.misc configuration file is used to set the file system type and mount options need
[root@xuegod64 ~]#mkdir/tmp/a
[root@xuegod64 ~]#vim /etc/auto.master
/tmp/a /etc/auto.nfs --timeout=60
# -Timeout = 60 mount timeout seconds. You can modify this parameter.
[root@xuegod64 ~]#vim /etc/auto.nfs
nfs -fstype=nfs 192.168.1.63:/tmp/a/root_squash
Note: nfs the name of free to play
Start autofs service:
[root@xuegod64 ~]#/etc/init.d/autofs restart
Stoppingautomount: [ OK ]
Startingautomount: [ OK ]
Note: Only cd / tmp / a / nfs into it, triggering it to automatically mount. In addition nfs directory can not be created in advance, automatically mount, the system automatically creates nfs directory.