码迷,mamicode.com
首页 > 其他好文 > 详细

nfs安装

时间:2020-07-27 15:59:04      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:grep   home   dash   挂载点   wrong   方便   stat   配置使用   wro   

Linux 环境下 NFS 服务安装及配置使用

 

3、NFS 服务安装
通过上边简要的介绍,我们知道 NFS 服务需要依赖 RPC 服务,所以这里 NFS 服务端需要安装 rpcbind 和 nfs-utils,客户端只需要安装 nfs-utils 即可,由于我选用的为 CentOS 系统,所以可以使用 yum 快速的安装。

首先,确认下服务端系统是否已安装 NFS。

$ rpm -qa nfs-utils rpcbind
nfs-utils-1.3.0-0.54.el7.x86_64
rpcbind-0.2.0-38.el7.x86_64
1
2
3
注意:这里我已经安装完毕,若为空,则说明未安装。

然后,安装 NFS 服务

# 服务端
$ yum install -y nfs-utils rpcbind
# 客户端
$ yum install -y nfs-utils
1
2
3
4
另:Ubuntu 16.04 安装命令为:

# 服务端
apt install nfs-kernel-server
# 客户端
apt install nfs-common
1
2
3
4
4、NFS 配置及使用
我们在服务端创建一个共享目录 /data/share ,作为客户端挂载的远端入口,然后设置权限。

$ mkdir -p /data/share
$ chmod 666 /data/share
1
2
然后,修改 NFS 配置文件 /etc/exports

$ vim /etc/exports
/data/share 10.222.77.0/24(rw,sync,insecure,no_subtree_check,no_root_squash)
1
2
说明一下,这里配置后边有很多参数,每个参数有不同的含义,具体可以参考下边。此处,我配置了将 /data/share 文件目录设置为允许 IP 为该 10.222.77.0/24 区间的客户端挂载,当然,如果客户端 IP 不在该区间也想要挂载的话,可以设置 IP 区间更大或者设置为 * 即允许所有客户端挂载,例如:/home *(ro,sync,insecure,no_root_squash) 设置 /home 目录允许所有客户端只读挂载。

参数 说明
ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
async nfs 在写入数据前可以响应请求
secure nfs 通过 1024 以下的安全 TCP/IP 端口发送
insecure nfs 通过 1024 以上的端口发送
wdelay 如果多个用户要写入 nfs 目录,则归组写入(默认)
no_wdelay 如果多个用户要写入 nfs 目录,则立即写入,当使用 async 时,无需此设置
hide 在 nfs 共享目录中不共享其子目录
no_hide 共享 nfs 目录的子目录
subtree_check 如果共享 /usr/bin 之类的子目录时,强制 nfs 检查父目录的权限(默认)
no_subtree_check 不检查父目录权限
all_squash 共享文件的 UID 和 GID 映射匿名用户 anonymous,适合公用目录
no_all_squash 保留共享文件的 UID 和 GID(默认)
root_squash root 用户的所有请求映射成如 anonymous 用户一样的权限(默认)
no_root_squash root 用户具有根目录的完全管理访问权限
anonuid=xxx 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID
anongid=xxx 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID
接下来,我们先启动 RPC 服务。

$ service rpcbind start
# 或者使用如下命令亦可
$ /bin/systemctl start rpcbind.service

# 查看 NFS 服务项 rpc 服务器注册的端口列表
$ rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
1
2
3
4
5
6
7
8
9
10
11
12
13
注意:此时我们还没有启动 NFS 服务,只监听了 111 端口,接着我们来启动 NFS 服务,再来看下注册的端口列表。

# 启动 NFS 服务
$ service nfs start
# 或者使用如下命令亦可
/bin/systemctl start nfs.service

# 启动 NFS 服务后 rpc 服务已经启用了对 NFS 的端口映射列表
# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 33745 status
100024 1 tcp 36980 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 38960 nlockmgr
100021 3 udp 38960 nlockmgr
100021 4 udp 38960 nlockmgr
100021 1 tcp 38362 nlockmgr
100021 3 tcp 38362 nlockmgr
100021 4 tcp 38362 nlockmgr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
我们发现,启动了 NFS 服务后,rpc 注册的端口列表明显增多。OK 现在服务端都启动起来了,在服务端看下是否正确加载了设置的 /etc/exports 配置。

$ showmount -e localhost
Export list for localhost:
/data/share 10.222.77.0/24
1
2
3
5、NFS 测试
最后,在另一台 Linux 虚拟机上测试一下,是否能够正确挂载吧。首先,我们可以在客户端查看下 NFS 服务端 (上边服务端 IP 为:10.222.77.86) 设置可共享的目录信息。

# showmount -e 10.222.77.86
Export list for 10.222.77.86:
/data/share 10.222.77.0/24
1
2
3
然后,在客户端创建挂在目录 /share

$ mkdir -p /share
1
最后,挂载远端目录到本地 /share 目录。

$ mount 10.222.77.86:/data/share /share
$ df -h | grep 10.222.77.86
Filesystem Size Used Avail Use% Mounted on
10.222.77.86:/data/share 27G 11G 17G 40% /share
1
2
3
4
可以看到,可以正确将远端 NFS 目录挂载到本地。注意:挂载点 /share 目录必须已经存在,而且目录中没有文件或子目录。

最后,我们在 NFS 服务端 /data/share 目录下创建一个文件,看下客户端是否能够正确读取并修改。

# 服务端写入
$ echo "This is NFS server." > /data/share/nfs.txt
# ll /data/share/
total 4
-rw-r--r-- 1 root root 20 Nov 5 16:49 nfs.txt

# 客户端读取
$ ll /share/
total 4
-rw-r--r-- 1 root root 20 Nov 5 16:49 nfs.txt
$ cat /share/nfs.txt
This is NFS server.

# 客户端写入
$ echo "This is NFS client." >> /share/nfs.txt

# 服务端读取
$ cat /data/share/nfs.txt
This is NFS server.
This is NFS client.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
都是木有问题的,这是因为上边设置了 NFS 远端目录权限为 rw 拥有读写权限,如果设置为 ro,那么客户端只能读取,不能写入,根据实际应用场景合理配置,这里就不在演示了。这里提一下,NFS 默认使用用 UDP 协议来进行挂载,为了提高 NFS 的稳定性,可以使用 TCP 协议挂载,那么客户端挂载命令可使用如下命令:

$ mount 10.222.77.86:/data/share /share -o proto=tcp -o nolock
1
最后,如果客户端要卸载 NFS 挂载的话,使用如下命令即可。

$ umount /share
1
好了,上边简单介绍了 NFS 安装及配置使用,使用它我们可以很方便的透过网络,让不同的主机、操作系统实现共享存储。下一篇,我们继续研究 Kubernetes 集群中各种方式挂载 NFS,来实现挂载网络文件存储系统。

 

 

-------------------------------------------------------------

错误信息:

mount: wrong fs type, bad option, bad superblock on 127.0.0.1:/data/ftp/tvcms_test,
       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

解决办法:

yum install nfs-utils
————————————————
版权声明:本文为CSDN博主「cedar0007」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cedar707/article/details/92808087

nfs安装

标签:grep   home   dash   挂载点   wrong   方便   stat   配置使用   wro   

原文地址:https://www.cnblogs.com/xiaoL/p/13384640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!