700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【Linux】 NFS服务器实现开机自动挂载

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

时间:2018-12-03 11:45:53

相关推荐

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

文章目录

NFS服务介绍NFS存储服务作用安装NFS:1) yum安装nfs2) 配置文件位置3) 启动NFS服务 使用方法1) 创建共享目录2) 设置配置文件并查看3) 客户端测试 NFS共享的常用参数设置自动挂载NFS总结

NFS服务介绍

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

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

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

NFS的模式: C/S 模式

NFS监听的端口: 2049

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

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

NFS存储服务作用

实现数据的共享存储编写数据操作管理节省购买服务器磁盘开销 淘宝–上万 用电开销

安装NFS:

1) yum安装nfs

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

2) 配置文件位置

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

3) 启动NFS服务

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

使用方法

1) 创建共享目录

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

2) 设置配置文件并查看

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

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

3) 客户端测试

[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 ~]#

挂载测试:

[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 -h192.168.1.64:/share/dir1 17G 4.7G 13G 28% /mnt/test1192.168.1.64:/share/dir2 17G 4.7G 13G 28% /mnt/test2

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

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

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

NFS共享的常用参数

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

设置自动挂载NFS

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

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

总结

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。