实验环境
Ubuntu 14.04
简介
NFS是一种分布式的文件系统协议, NFS适合accessed regularly场景下。
前提条件
创建一个具有sudo权限的账户nfs
例如我们有如下两台机器
* Host:1.2.3.4
* Client:111.111.111.111
下载和安装组件
在Host和Client端安装必要的组件
在Host端需要安装nfs-kernel-server
sudo apt-get install nfs-kernel-server
Client端nfs-common
sudo apt-get install nfs-common
在Host端创建共享目录
假如共享目录是/var/nfs
创建目录
sudo mkdir /var/nfs
对此目录的权限进行设置
sudo chown nobody:nogroup /var/nfs
配置NFS Expors在Host Server
打开/etc/exports
配置如下:
/var/nfs 111.111.111.111(rw,sync,no_subtree_check)
上述参数说明如下:
* rw: This option gives the client computer both read and write access to the volume
* sync: This option forces NFS to write changes to disk before replying. This results in a more stable and consistent environment, since the reply reflects the actual state of the remote volume.
* nosubtreecheck: This option prevents subtree checking, which is a process where the host must check whether the file is actually still available in the exported tree for every request. This can cause many problems when a file is renamed while the client has it opened. In almost all cases, it is better to disable subtree checking.
* norootsquash: By default, NFS translates requests from a root user remotely into a non-privileged user on the server. This was supposed to be a security feature by not allowing a root account on the client to use the filesystem of the host as root. This directive disables this for certain shares.
下一步export
sudo exportfs -a
运行下列命令启动共享
sudo service nfs-kernel-server start
客户端创建挂载点并挂载相关目录
在客户端创建挂载点
sudo mkdir -p /mnt/nfs/var
挂载
sudo mount 192.168.100.176:/var/nfs /mnt/nfs/var
查看所有的挂载目录
mount -t nfs
启动nfs目录自动挂载
可以使用client的fstab文件来自动挂载文件系统
编辑/etc/fstab文件
1.2.3.4:/var/nfs /mnt/nfs/var/nfs nfs defaults 0 0
取消挂载
sudo umount /mnt/nfs/var