作用:
网络文件共享,主要实现linux与linux之间的文件共享
原理:
nfs在启动的时候会先去找rpc注册,把自己监听的端口信息等进行注册,因此nfs在启动或安装前要先安装并启动rpc,rpc监听111端口号;客户端首先会去连接rpc,然后rpc把nfs的相关信息告诉客户端,客户端通过这些信息去连接nfs,然后与nfs进行文件共享
参考:
http://blog.chinaunix.net/uid-26284318-id-3111651.html
(rw,no_root_squash,sync)
ro 该主机对该共享目录有只读权限 rw 该主机对该共享目录有读写权限 root_squash 客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户 no_root_squash 客户机用root访问该共享文件夹时,将依然是root用户 all_squash 客户机上的任何用户访问该共享目录时都映射成匿名用户 anonuid 将客户机上的用户映射成指定的本地用户ID的用户 anongid 将客户机上的用户映射成属于指定的本地用户组ID sync 资料同步写入到内存与硬盘中 async 资料会先暂存于内存中,而非直接写入硬盘 insecure 允许从这台机器过来的非授权访问
nfslock:多个客户端同时写入时锁定:
参考:http://linux.vbird.org/linux_server/0330nfs.php#nfsserver_security
nfs相关服务:
* rpc.mountd - 这个进程接受来自NFS客户端的加载请求和验证请求的文件系统正在被输出.这个进程由NFS服务自动启动,不需要用户的配置.
* rpc.nfsd - 这个进程是NFS服务器.它和Linux核心一起工作来满足NFS客户端的动态需求,例如提供为每个NFS客户端的每次请求服务器线程.这个进程对应于nfs服务.
* rpc.lockd - 一个可选的进程,它允许NFS客户端在服务器上对文件加锁.这个进程对应于nfslock服务.
* rpc.statd - 这个进程实现了网络状态监控(NSM)RPC协议,通知NFS客户端什么时候一个NFS服务器非正常重启动.这个进程被nfslock服务自动启动,不需要用户的配置.
* rpc.rquotad - 这个进程对于远程用户提供用户配额信息. 这个进程被nfs服务自动启动,不需要用户的配置.
注意:
nfs服务端down机重启后要确定 nfs 服务是否起来,并到客户端机器确定挂载的目录是否mount成功以免影响生产使用。
NFS的安装配置:
centos 5 :
yum -y install nfs-utils portmap
centos 6 :
yum -y install nfs-utils rpcbind
本节是使用centos 6的配置过程:
首先,让两台机器都安装NFS的 软件包,如下显示的是服务器端:
[root@roothomes /home]$ yum -y install nfs-utils rpcbind
服务器端:
###(建立挂载的目录,并且挂载目录。)
[root@roothomes /etc]$ mkdir /opt/centos6
[root@roothomes /etc]$ cd /opt/centos6/
[root@roothomes /opt/centos6]$ mkdir thisISnfsFile
[root@roothomes /opt/centos6]$ ls
thisISnfsFile
[root@roothomes /etc]$ vim /etc/exports
[root@roothomes /opt/centos6]$ cat /etc/exports
/opt/centos6 192.168.1.0/24(rw,no_root_squash,sync)
### 备注:/opt/centos6表示nfs共享的目录 192.168.1.0-192.168.1.254区间的IP可以访问,访问权限是可读可写,root 用户
###(启动对应的服务)
[root@roothomes /opt/centos6]$ chkconfig nfs on
[root@roothomes /opt/centos6]$ /etc/init.d/rpcbind start
[root@roothomes /opt/centos6]$ /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@roothomes /opt/centos6]$ service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
客户端:
[root@roothomes /home]$ yum -y install nfs-utils
安装完毕!
[root@vmBS00 ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
###查看是否能访问nfs服务
[root@vmBS00 ~]# showmount -e 192.168.1.75
Export list for 192.168.1.75:
/opt/centos6 192.168.1.0/24
[root@vmBS00 ~]# mkdir /opt/centos6
[root@vmBS00 ~]# mount -t nfs 192.168.1.75:/opt/centos6/ /opt/centos6/
[root@vmBS00 ~]# ls /opt/centos6/
thisISnfsFile
###配置开机自动挂载
[root@vmBS00 ~]# vim /etc/fstab
### 添加 #192.168.1.75:/opt/centos6/ /opt/centos6/ nfs nodev,ro,rsize=32768,wsize=32768 0 0
[root@vmBS00 ~]# mount -a
>
>
转载于:https://blog.51cto.com/732233048/1616862