搭建NFS

实验环境

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值