NFS 文件共享能解决在集群环境下图片、附件等文件共享的问题。
现在假设有两台机器192.168.1.10和192.168.1.11
我们将192.168.1.10做为服务端,192.168.1.11作为客户端。
一、服务端操作
1. 检查安装nfs服务
rpm -qa|grep nfs rpm -qa|grep rpcbind
若没有这安装nfs-utils和rpcbind
yum install nfs-utils rpcbind


如上图就是安装成功了。
2.设置开机自动启动服务
chkconfig nfs on chkconfig rpcbind on
3.启动服务
service rpcbind start service nfs start
4.创建共享目录
mkdir /usr/local/jsp/www
5.打开/etc/exports文件
vi /etc/exports
加入
/usr/local/jsp/www *(rw,sync,no_root_squash)
* :允许所有的网段访问
rw :读写权限
sync:资料同步写入内在和硬盘
no_root_squash:nfs客户端共享目录使用者权限
如果需要指定只对某个网段(如192.168.1.1~192.168.1.192)可以这样设置
/usr/local/www/ 192.168.1.*(rw,sync,no_root_squash,no_subtree_check)
也可以手动指定多个网段
/usr/local/www/ 192.168.1.10(rw,sync,no_root_squash,no_subtree_check) 192.168.1.11(rw,sync,no_root_squash,no_subtree_check)
多目录共享添加多行即可。
6.刷新配置立即生效
exportfs -a
此时可用showmount -e 服务端ip来查看可mount目录
showmount -e 192.168.1.10
二、客户端端操作(前四步和服务端一样)
1.检查安装nfs
yum install nfs-utils rpcbind
2.设置开机自动启动服务
chkconfig nfs on chkconfig rpcbind on
3.启动服务
service rpcbind start service nfs start
4.创建共享目录
mkdir /usr/local/jsp/www
5.挂载目录
1)查看可挂载目录
showmount -e 192.168.1.10
2)挂载
mount -t nfs 192.168.1.10:/usr/local/jsp/www /usr/local/jsp/www
这一命令就已经将10上的/usr/local/jsp/www 目录挂载到客户机的/usr/local/jsp/www目录上了
挂载超时的话就检查防火墙配置,可 service iptables stop临时关闭防火墙进行测试。
3)查看已已挂载目录
df -h
4)卸载已挂载目录
umount /usr/local/jsp/www








