广告
返回顶部
首页 > 资讯 > 精选 >Ubuntu如何配置NFS
  • 698
分享到

Ubuntu如何配置NFS

2023-06-09 16:06:57 698人浏览 薄情痞子
摘要

这篇文章主要介绍了ubuntu如何配置NFS,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。NFS 是Network File System的缩写,即网络文件系统,一种使用于分

这篇文章主要介绍了ubuntu如何配置NFS,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

NFS 是Network File System的缩写,即网络文件系统,一种使用于分散式文件系统的协定

NFS通过网络让不同的机器、不同的操作系统能够彼此分享个别的数据,例如将/home设置为共享目录,然后共享给网络中的其它服务器,这样每台机器就不必单独建立自己的/home路径了,NFS独立于操作系统,容许不同硬件及操作系统的系统共同进行文件的分享,是在类Unix系统间实现磁盘文件共享的一种方法

NFS本身没有提供信息传输的协议和功能,而是使用rpc服务完成这部分功能。可以说NFS本身就是使用RPC服务的一个程序,或者说NFS也是一个RPC SERVER。所以只要用到NFS的地方都要启动RPC服务,不论是NFS server还是NFS client,可以这么理解RPC和NFS之间的关系:NFS是一个文件系统,而RPC负责信息的传输

一,系统环境

linux Distribution:Ubuntu 14

二,安装Linux NFS

sean@sean:~$ sudo apt-get install nfs-kernel-server[sudo] passWord for sean: Reading package lists... DoneBuilding dependency tree    Reading state infORMation... DoneThe following extra packages will be installed: keyutils libgssglue1 libnfsidmap2 libtirpc1 nfs-common rpcbindSuggested packages: open-iscsi watchdogThe following NEW packages will be installed: keyutils libgssglue1 libnfsidmap2 libtirpc1 nfs-common nfs-kernel-server rpcbind0 upgraded, 7 newly installed, 0 to remove and 159 not upgraded.Need to get 460 kB of arcHives.After this operation, 2,049 kB of additional disk space will be used.Do you want to continue? [Y/n] YGet:1 Http://cn.archive.ubuntu.com/ubuntu/ trusty/main libgssglue1 amd64 0.4-2ubuntu1 [19.7 kB]Get:2 http://cn.archive.ubuntu.com/ubuntu/ trusty/main libnfsidmap2 amd64 0.25-5 [32.2 kB]Get:3 http://cn.archive.ubuntu.com/ubuntu/ trusty/main libtirpc1 amd64 0.2.2-5ubuntu2 [71.3 kB]Get:4 http://cn.archive.ubuntu.com/ubuntu/ trusty/main keyutils amd64 1.5.6-1 [33.6 kB]Get:5 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main rpcbind amd64 0.2.1-2ubuntu2.2 [37.1 kB]Get:6 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main nfs-common amd64 1:1.2.8-6ubuntu1.2 [181 kB]Get:7 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main nfs-kernel-server amd64 1:1.2.8-6ubuntu1.2 [85.8 kB]Fetched 460 kB in 16s (27.2 kB/s)                       Selecting previously unselected package libgssglue1:amd64.(Reading database ... 168701 files and directories currently installed.)Preparing to unpack .../libgssglue1_0.4-2ubuntu1_amd64.deb ...Unpacking libgssglue1:amd64 (0.4-2ubuntu1) ...Selecting previously unselected package libnfsidmap2:amd64.Preparing to unpack .../libnfsidmap2_0.25-5_amd64.deb ...Unpacking libnfsidmap2:amd64 (0.25-5) ...Selecting previously unselected package libtirpc1:amd64.Preparing to unpack .../libtirpc1_0.2.2-5ubuntu2_amd64.deb ...Unpacking libtirpc1:amd64 (0.2.2-5ubuntu2) ...Selecting previously unselected package keyutils.Preparing to unpack .../keyutils_1.5.6-1_amd64.deb ...Unpacking keyutils (1.5.6-1) ...Selecting previously unselected package rpcbind.Preparing to unpack .../rpcbind_0.2.1-2ubuntu2.2_amd64.deb ...Unpacking rpcbind (0.2.1-2ubuntu2.2) ...Selecting previously unselected package nfs-common.Preparing to unpack .../nfs-common_1%3a1.2.8-6ubuntu1.2_amd64.deb ...Unpacking nfs-common (1:1.2.8-6ubuntu1.2) ...Selecting previously unselected package nfs-kernel-server.Preparing to unpack .../nfs-kernel-server_1%3a1.2.8-6ubuntu1.2_amd64.deb ...Unpacking nfs-kernel-server (1:1.2.8-6ubuntu1.2) ...Processing triggers for man-db (2.6.7.1-1ubuntu1) ...Processing triggers for ureadahead (0.100.0-16) ...ureadahead will be reprofiled on next rebootSetting up libgssglue1:amd64 (0.4-2ubuntu1) ...Setting up libnfsidmap2:amd64 (0.25-5) ...Setting up libtirpc1:amd64 (0.2.2-5ubuntu2) ...Setting up keyutils (1.5.6-1) ...Setting up rpcbind (0.2.1-2ubuntu2.2) ... Removing any system startup links for /etc/init.d/rpcbind ...rpcbind start/running, process 12074Processing triggers for ureadahead (0.100.0-16) ...Setting up nfs-common (1:1.2.8-6ubuntu1.2) ...Creating config file /etc/idmapd.conf with new versionCreating config file /etc/default/nfs-common with new versionAdding system user `statd' (UID 118) ...Adding new user `statd' (UID 118) with group `nogroup' ...Not creating home directory `/var/lib/nfs'.statd start/running, process 12307gssd stop/pre-start, process 12341idmapd start/running, process 12399Processing triggers for ureadahead (0.100.0-16) ...Setting up nfs-kernel-server (1:1.2.8-6ubuntu1.2) ...Creating config file /etc/exports with new versionCreating config file /etc/default/nfs-kernel-server with new version * Not starting NFS kernel daemon: no exports.Processing triggers for libc-bin (2.19-0ubuntu6.7) ...Processing triggers for ureadahead (0.100.0-16) ...

通过安装日志可以发现总共会安装keyutils,libgssglue1,libnfsidmap2,libtirpc1,nfs-common,nfs-kernel-server,rpcbind这7个包

很多文档中安装的包为portmap,但是这个包已经被rpcbind替代

sean@sean:~$ sudo apt-get install portmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'rpcbind' instead of 'portmap'
rpcbind is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 164 not upgraded.
rpcbind包安装完成后会自动启动rpcbind服务

sean@sean:~$ ps -ef|grep rpcbind
root 807 1 0 22:27 ? 00:00:00 rpcbind
sean 10215 9528 0 22:48 pts/6 00:00:00 grep --color=auto rpcbind
但是由于目前NFS的配置文件为空,NFS服务并没有启动

三,配置NFS服务

Ubuntu如何配置NFS

从安装日志中我们可以发现NFS服务的配置文件为/etc/exports,并且这个文件在安装过程中已经生成好了,我们所要做的就是将NFS配置信息添加到这个文件中

sean@sean:~$ sudo vi /etc/exports# /etc/exports: the access control list for filesystems which may be exported#        to NFS clients. See exports(5).## Example for NFSv2 and NFSv3:# /srv/homes    hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)## Example for NFSv4:# /srv/nfs4    gss/krb5i(rw,sync,fsid=0,croSSMnt,no_subtree_check)# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)/home/sean/shareDir 192.168.137.129(rw,no_root_squash,async)

其中中的最后一行为新添加的NFS配置,NFS配置信息格式如下:

<共享目录> [客户端1 选项(访问权限,用户映射,其他)] [客户端2 选项(访问权限,用户映射,其他)]

1,共享目录:

共享目录是指NFS系统中需要共享给客户机使用的目录

2,客户端:

客户端是指网络中可以访问NFS共享目录的计算机

客户端常用的指定方式:

(1)指定ip地址的主机:192.168.0.1
(2)指定子网中的所有主机:192.168.0.0/255.255.255.0
(3)指定域名的主机:www.sean.com
(4)指定域中的所有主机:*.sean.com
(5)所有主机:*

3,选项:

选项用来设置输出目录的访问权限、用户映射等,NFS主要有3类选项:

访问权限选项:

(1)设置输出目录只读:ro
(2)设置输出目录读写:rw

用户映射选项:

(1)all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody)
(2)no_all_squash:与all_squash取反(默认设置)
(3)root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置)
(4)no_root_squash:与rootsquash取反
(5)anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx)
(6)anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx)

其它选项:

(1)secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置)
(2)insecure:允许客户端从大于1024的tcp/ip端口连接服务器
(3)sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性
(4)async:将数据先保存在内存缓冲区中,必要时才写入磁盘
(5)wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置)
(6)no_wdelay:若有写操作则立即执行,应与sync配合使用
(7)subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置)
(8)no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率

四,启动NFS服务

sean@sean:~$ sudo service nfs-kernel-server start * Exporting directories for NFS kernel daemon...                                                                exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.137.129:/home/sean/shareDir". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x * Starting NFS kernel daemon  sean@sean:~$ sudo service nfs-kernel-server statusnfsd runningsean@sean:~$ ps -ef|grep nfsdroot   10536   2 0 23:40 ?    00:00:00 [nfsd4]root   10537   2 0 23:40 ?    00:00:00 [nfsd4_callbacks]root   10539   2 0 23:40 ?    00:00:00 [nfsd]root   10540   2 0 23:40 ?    00:00:00 [nfsd]root   10541   2 0 23:40 ?    00:00:00 [nfsd]root   10542   2 0 23:40 ?    00:00:00 [nfsd]root   10543   2 0 23:40 ?    00:00:00 [nfsd]root   10544   2 0 23:40 ?    00:00:00 [nfsd]root   10545   2 0 23:40 ?    00:00:00 [nfsd]root   10546   2 0 23:40 ?    00:00:00 [nfsd]sean   10566  9528 0 23:41 pts/6  00:00:00 grep --color=auto nfsd

通过命令可以看到文件夹已经被共享

sean@sean:~$ showmount -e
Export list for sean:
/home/sean/shareDir 192.168.137.129

五,客户端挂载NFS共享目录

sean@ubuntu:~$ sudo mount 192.168.137.128:/home/sean/shareDir /home/sean/sharedmount: wrong fs type, bad option, bad superblock on 192.168.137.128:/home/sean/shareDir,    missing codepage or helper program, or other error    (for several filesystems (e.g. nfs, cifs) you might    need a /sbin/mount.<type> helper program)    In some cases useful info is found in syslog - try    dmesg | tail or so

上网查看了一下错误原因,是因为客户端没有安装nfs-common包

sean@ubuntu:~$ sudo apt-get install nfs-common
之后再次使用挂载命令即可,此时如果我们再次查看客户端挂载的磁盘,就可以看到NFS共享目录已经被挂载上了

sean@ubuntu:~$ dfFilesystem             1K-blocks  Used Available Use% Mounted onudev                  488800    4  488796  1% /devtmpfs                  99904  1456   98448  2% /run/dev/sda1              19478204 3745568 14720156 21% /none                    4    0     4  0% /sys/fs/cgroupnone                   5120    0   5120  0% /run/locknone                  499512   152  499360  1% /run/shmnone                  102400   40  102360  1% /run/user/dev/sr0               1044480 1044480     0 100% /media/sean/Ubuntu 14.04.4 LTS amd64192.168.137.128:/home/sean/shareDir 19478272 4288896 14176896 24% /home/sean/shared

此时如果我们在128的/home/sean/shareDir目录下创建一个文件,在129的/home/sean/shared目录下可以看到一个名称相同的文件,并且文件的内容也相同

六,开机启动NFS服务

安装完成之后查看系统服务

sean@sean:~$ runlevel
N 2
sean@sean:~$ ll /etc/rc2.d
total 20
drwxr-xr-x 2 root root 4096 6月 20 23:25 ./
drwxr-xr-x 132 root root 12288 6月 26 20:16 ../
-rw-r--r-- 1 root root 677 2月 17 12:59 README
lrwxrwxrwx 1 root root 20 2月 22 06:33 S20kerneloops -> ../init.d/kerneloops*
lrwxrwxrwx 1 root root 27 6月 20 23:25 S20nfs-kernel-server -> ../init.d/nfs-kernel-server*
lrwxrwxrwx 1 root root 15 2月 22 06:33 S20rsync -> ../init.d/rsync*
lrwxrwxrwx 1 root root 27 2月 22 06:33 S20speech-dispatcher -> ../init.d/speech-dispatcher*
lrwxrwxrwx 1 root root 15 2月 22 06:33 S50saned -> ../init.d/saned*
lrwxrwxrwx 1 root root 19 2月 22 06:33 S70dns-clean -> ../init.d/dns-clean*
lrwxrwxrwx 1 root root 18 2月 22 06:33 S70pppd-dns -> ../init.d/pppd-dns*
lrwxrwxrwx 1 root root 21 2月 22 06:33 S99grub-common -> ../init.d/grub-common*
lrwxrwxrwx 1 root root 18 2月 22 06:33 S99ondemand -> ../init.d/ondemand*
lrwxrwxrwx 1 root root 18 2月 22 06:33 S99rc.local -> ../init.d/rc.local*
nfs-kernel-server是自动启动,就不需要再进行修改了,而rpcbind就比较麻烦了,找了半天才找到vi /etc/init/rpcbind-boot.conf

# portmap-boot

description "Upstart job to start rpcbind on boot only"
author "Clint Byrum"

emits start-rpcbind

start on virtual-filesystems and net-device-up IFACE=lo

task

exec initctl emit --no-wait start-rpcbind ON_BOOT=y
可以见到这个服务设为开机启动了

七,开机自动挂载共享盘

这时候我们需要修改的文件是/etc/fstab,命令格式如下:

<NFS服务端>:<共享目录> <本地目录> <文件系统类型> <选项> <dump> <pass>每个字段的具体含义这里就不详细解释了,vi /etc/fstab,在文件中添加下面这行配置

192.168.137.128:/home/sean/shareDir /home/sean/shared nfs defaults 0 0系统每次启动时即会自动挂载共享盘

感谢你能够认真阅读完这篇文章,希望小编分享的“Ubuntu如何配置NFS”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网精选频道,更多相关知识等着你来学习!

--结束END--

本文标题: Ubuntu如何配置NFS

本文链接: https://www.lsjlt.com/news/256837.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Ubuntu如何配置NFS
    这篇文章主要介绍了Ubuntu如何配置NFS,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。NFS 是Network File System的缩写,即网络文件系统,一种使用于分...
    99+
    2023-06-09
  • 如何安装Ubuntu nfs配置系统
    这篇文章主要讲解了“如何安装Ubuntu nfs配置系统”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何安装Ubuntu nfs配置系统”吧!对大家推荐很好使用的nfs服务系统之前,像让大...
    99+
    2023-06-16
  • 如何在Ubuntu上安装配置NFS
    文章目录 1. 在服务器端安装NFS内核服务器:2. 配置NFS共享目录:3. 在客户端安装NFS客户端并挂载NFS共享: 1. 在服务器端安装NFS内核服务器: 首先,确保您的Ubunt...
    99+
    2023-09-01
    ubuntu linux 服务器
  • 如何配置Ubuntu nfs安装服务版
    这篇文章给大家分享的是有关如何配置Ubuntu nfs安装服务版的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。安装Ubuntu nfs服务版apt-get install Ubuntu nfs-kernel-se...
    99+
    2023-06-16
  • Ubuntu中怎么配置NFS服务
    这篇文章主要介绍了Ubuntu中怎么配置NFS服务的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Ubuntu中怎么配置NFS服务文章都会有所收获,下面我们一起来看看吧。NFS(Network File Syst...
    99+
    2023-06-27
  • nfs如何配置
    这篇文章主要为大家展示了“nfs如何配置”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“nfs如何配置”这篇文章吧。最近配置了一台nfs主机,使用中有几点心得,写下来备忘 一是如果server和c...
    99+
    2023-06-10
  • linux如何配置NFS
    Linux 环境下 NFS 服务安装及配置使用 NFS 服务安装 yum install nfs-utils rpcbind 2.NFS 配置及使用 2.1添加hosts解析 vim /etc/hosts192.168.200.1...
    99+
    2023-09-24
    linux 运维 服务器 Powered by 金山文档
  • Ubuntu配置NFS的具体流程(推荐)
    NFS 是Network File System的缩写,即网络文件系统,一种使用于分散式文件系统的协定 NFS通过网络让不同的机器、不同的操作系统能够彼此分享个别的数据,例如将/home设置为共享目录,然后...
    99+
    2022-06-04
    流程 Ubuntu NFS
  • 如何在 Ubuntu 18.04 上安装和配置 NFS 服务器
    网络文件系统(NFS)是一种分布式文件系统协议,允许您通过网络共享远程目录。 使用 NFS ,您可以在系统上安装远程目录,并使用远程计算机上的文件,就像它们是本地文件一样。 默认情况下,NFS 协议未...
    99+
    2023-09-15
    服务器 ubuntu linux 运维
  • Linux系统如何配置NFS
    这篇文章将为大家详细讲解有关Linux系统如何配置NFS,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。NFS简介:NFS 是Network File System的缩写,即网络文件系统。一种使用于分散式文...
    99+
    2023-06-28
  • Linux服务器如何配置nfs
    这篇文章主要介绍了Linux服务器如何配置nfs,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。配置nfsNFS服务的主要配置文件为/etc/exports。/etc/expo...
    99+
    2023-06-05
  • 如何利用ceph rbd配置nfs
    小编给大家分享一下如何利用ceph rbd配置nfs,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!利用ceph rbd配置nfs一种简单实用的存储方法,具体如下:...
    99+
    2023-06-27
  • Linux如何配置nfs共享目录
    要在Linux上配置NFS共享目录,需要按照以下步骤进行操作:1. 确保NFS服务器已经安装:使用以下命令安装NFS服务器软件包:`...
    99+
    2023-09-27
    linux
  • Linux系统如何配置NFS服务
    小编给大家分享一下Linux系统如何配置NFS服务,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!NFS(Network File System)即网络文件系统,是...
    99+
    2023-06-28
  • ubuntu重启nfs命令如何用
    今天小编给大家分享一下ubuntu重启nfs命令如何用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。使用快捷键【Ctrl+A...
    99+
    2023-07-04
  • Linux如何配置nfs共享存储服务
    这篇“Linux如何配置nfs共享存储服务”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Linux如何配置nfs共享存储服务...
    99+
    2023-06-28
  • Linux系统nfs服务器该如何配置
    小编今天带大家了解Linux系统nfs服务器该如何配置,文中知识点介绍的非常详细。觉得有帮助的朋友可以跟着小编一起浏览文章的内容,希望能够帮助更多想解决这个问题的朋友找到问题的答案,下面跟着小编一起深入学习“Linux系统nfs服务器该如何...
    99+
    2023-06-28
  • Ubuntu如何配置apache2
    Ubuntu配置apache2的示例:打开终端输入以下命令编辑/etc/apache2/apache2.conf文件。vim /etc/apache2/apache2.conf#将文件中的AllowOverride No...
    99+
    2022-10-19
  • Ubuntu如何配置maven
    Ubuntu配置maven的示例:Ubuntu下Maven地址。http://apache.fayea.com/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz下载后解压到...
    99+
    2022-10-17
  • Linux系统服务器如何进行nfs配置
    这篇文章将为大家详细讲解有关Linux系统服务器如何进行nfs配置,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。NFS是由Sun公司发展的,他最主要的功能就是可以透过网络,让不同的机器、不同...
    99+
    2023-06-28
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作