【Linux】 NFS服务器实现开机自动挂载

网友投稿 1237 2022-05-28

文章目录

NFS服务介绍

NFS存储服务作用

安装NFS:

1) yum安装nfs

2) 配置文件位置

3) 启动NFS服务

使用方法

1) 创建共享目录

2) 设置配置文件并查看

3) 客户端测试

NFS共享的常用参数

设置自动挂载NFS

总结

NFS,是Network File System的简写,即网络文件系统。网络文件系统是FreeBSD支持的文件系统中的一种,NFS允许一个系统在网络上与他人共享目录和文件。

它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录

通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件,如图:

NFS的模式: C/S 模式

NFS监听的端口: 2049

RHEL7是以NFSv4作为默认版本,NFSv4使用TCP协议(端口号是2049)和NFS服务器建立连接。

在/etc/services里定义了nfs的端口号

实现数据的共享存储

编写数据操作管理

节省购买服务器磁盘开销 淘宝–上万 用电开销

[root@gaosh-64 ~]# yum install rpcbind nfs-utils

[root@gaosh-64 ~]# ls /etc/exports /etc/exports

1

2

[root@gaosh-64 ~]# systemctl restart rpcbind [root@gaosh-64 ~]# systemctl start nfs-server.service [root@gaosh-64 ~]# [root@gaosh-64 ~]# netstat -antup |grep 2049 tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp6 0 0 :::2049 :::* LISTEN - udp 0 0 0.0.0.0:2049 0.0.0.0:* - udp6 0 0 :::2049 :::* -

1

2

3

4

5

6

7

8

9

[root@gaosh-64 ~]# mkdir -p /share/{dir1,dir2} [root@gaosh-64 ~]# chmod -R 777 /share/ #给共享目录写的权限 [root@gaosh-64 ~]# ll /share/ 总用量 0 drwxrwxrwx 2 root root 6 7月 18 20:42 dir1 drwxrwxrwx 2 root root 6 7月 18 20:42 dir2

1

2

3

4

5

6

7

[root@gaosh-64 ~]# cat /etc/exports /share/dir1 *(ro) #只读 /share/dir2 192.168.1.0/24(rw,sync) #读写

1

2

3

[root@gaosh-64 ~]# systemctl restart nfs.service #启动 [root@gaosh-64 ~]# exportfs -v #检查当前主机的NFS输出(共享) /share/dir2 192.168.1.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash) /share/dir1 (sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash) [root@gaosh-64 ~]#

1

2

3

4

5

6

[root@gaosh-17 ~]# showmount -e 192.168.1.64 #查看存储端共享 Export list for 192.168.1.64: /share/dir1 * /share/dir2 192.168.1.0/24 [root@gaosh-17 ~]#

1

2

3

4

5

6

挂载测试:

[root@gaosh-17 ~]# showmount -e 192.168.1.64 [root@gaosh-17 ~]# mkdir /mnt/test1 [root@gaosh-17 ~]# mkdir /mnt/test2 [root@gaosh-17 ~]# mount -t nfs 192.168.1.64:/share/dir1 /mnt/test1 [root@gaosh-17 ~]# mount -t nfs 192.168.1.64:/share/dir2 /mnt/test2 [root@gaosh-17 ~]# df -h 192.168.1.64:/share/dir1 17G 4.7G 13G 28% /mnt/test1 192.168.1.64:/share/dir2 17G 4.7G 13G 28% /mnt/test2

1

2

3

4

5

6

7

8

在上文中我们设置的test1 为只读,test2 为可读写

为了验证这一点,我们只需要复制一个文件过去查看即可

[root@gaosh-17 ~]# cp /etc/passwd /mnt/test1/ #只读文件系统,无法复制文件进去 cp: 无法创建普通文件"/mnt/test1/passwd": 只读文件系统 [root@gaosh-17 ~]# cp /etc/passwd /mnt/test2/

1

2

3

我们已经使用过ro和rw,sync, 三个参数,除此之外还有很多,如下表:

直接在配置文件 /etc/fstab里设置

[root@gaosh-17 ~]# grep '192.168.1.64' /etc/fstab 192.168.1.64:/share/dir1 /mnt/test1 nfs deaults 0 0

1

2

3

【Linux】 NFS服务器实现开机自动挂载

本文主要探讨了NFS的安装,及使用,实现的NFS开机自动挂载。 为了防止单点NFS,也是可以使用keepalived做高可用的。当你当前的服务器硬盘不够用的时候,你可以使用NFS服务,分享一个硬盘过来使用。

Linux 网络

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:系统监控工具-dstat
下一篇:AI控制登月器着陆,低代码搭建飞船控制台…玩转代码星球,程序员节福利陆续放送!
相关文章