linux系统之间共享文件(CentOS6)

Server IP: 192.168.2.128

nfs, rpcbind(portmap) installed

Client IP: 192.168.2.254

nfs, rpcbind(portmap) installed

<pre style="background-color: rgb(255,250,233);">

[root@rhel6 tmp]# rpm -qa rpcbind

rpcbind-0.2.0-13.el6.x86_64

[root@rhel6 tmp]# rpm -qa nfs*

nfsometer-1.6-1.el6.noarch

nfs-ganesha-proxy-2.3.2-1.el6.x86_64

nfs-ganesha-mount-9P-2.3.2-1.el6.x86_64

nfs4-acl-tools-0.3.3-8.el6.x86_64

nfs-ganesha-utils-2.3.2-1.el6.x86_64

nfs-utils-lib-1.1.5-13.el6.x86_64

nfs-ganesha-vfs-2.3.2-1.el6.x86_64

nfs-ganesha-2.3.2-1.el6.x86_64

nfs-ganesha-nullfs-2.3.2-1.el6.x86_64

nfs-utils-1.2.3-75.el6.x86_64

</pre>

## 启动服务

service rpcbind start

service nfs start

## 可以查看NFS服务端服务状态

service rpcbind status

service nfs status

## Edit shared configuration on Server

[Filname: /etc/exports]

add line as below:

/path/to/shared/dir client-ip(option)

* 访问权限选项

设置输出目录只读:ro

设置输出目录读写:rw

* 用户映射选项

all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);

no_all_squash:与all_squash取反(默认设置);

root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);

no_root_squash:与rootsquash取反;

anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);

anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);

* 其它选项

secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置);

insecure:允许客户端从大于1024的tcp/ip端口连接服务器;

sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;

async:将数据先保存在内存缓冲区中,必要时才写入磁盘;

wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置);

no_wdelay:若有写操作则立即执行,应与sync配合使用;

subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);

no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;

## Check out shared directory on Server

<pre style="background-color: rgb(255,250,233);">

[root@rhel6 tmp]# exportfs

/tmp/shared 192.168.2.254

[root@rhel6 tmp]# showmount -e

clnt_create: RPC: Unknown host

</pre>

but #1 problem occurs, and then edit the "/etc/hosts" file to specific the sever-ip pointing to itself's hostname, like

[Filename: /etc/hosts]

add line as below

server-ip server's hostname

<pre style="background-color: rgb(255,250,233);">

[root@rhel6 tmp]# showmount -e

Export list for rhel6.9.1:

/tmp/shared 192.168.2.254

[root@rhel6 tmp]# exportfs

/tmp/shared 192.168.2.254

</pre>

# Client

mount -t nfs server-ip:/path/to/share /mnt/specific-dir

客户端在挂载的时候遇到的一个问题如下,可能是网络不太稳定,NFS默认是用UDP协议,换成TCP协议即可:

mount -t nfs 192.168.2.128:/usr/local/test /usr/local/test -o proto=tcp -o nolock

---

Related Blog

[linux系统之间共享文件](https://blog.csdn.net/lizhou828/article/details/79197848)

[NFS挂载时出现"access denied by server while mounting"的解决方法](http://www.heminjie.com/system/linux/2998.html)

猜你喜欢

转载自www.cnblogs.com/MimiSnowing/p/10495478.html