配置NFS服务

配置NFS服务,第1张

配置NFS服务

目录

一、NFS概述

1、NFS优点与缺点

2、NFS服务实现所需条件

二、NFS服务配置

配置服务器 

配置客户端


一、NFS概述


●NFS是一种基于TCP/IP传输的网络文件系统协议。通过使用NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源。

1、NFS优点与缺点


●对于大多数负载均衡群集来说,使用NFS协议来共享数据存储是比较常见的做法,NFS也是NAS存储设备必然支持的一种协议。但是由于NFS没有用户认证机制,而且数据在网络上明文传输,所以安全性很差,一般只能在局域网中使用。

2、NFS服务实现所需条件


●NFS 服务的实现依赖于 RPC(Remote Process Call,远端过程调用)机制,以完成远程到本地的映射过程。
所以需要安装 nfs-utils、rpcbind 软件包来提供 NFS共享服务,前者用于 NFS 共享发布和访问,后者用于 RPC 支持
 

二、NFS服务配置

配置服务器 
[root@ky17 ~]# yum install -y nfs-utils rpcbind  安装nfs软件包
[root@ky17 ~]# 
[root@ky17 ~]# vim /etc/exports
/opt/web/ 192.168.247.0/24(rw,sync,no_root_squash)    将/opt目录共享给192.168.247.0网段的所有用户   



[root@ky17 ~]# mkdir -p /opt/web  (默认没有共享目录。需要创建)
[root@ky17 ~]# ls /opt
ceshi     etc           john-1.8.0         lmy2  shadow.txt  test.txt  wtb1
dome.txt  httpd-2.4.25  john-1.8.0.tar.gz  rh    suibian     web

[root@ky17 ~]# systemctl start rpcbind    开启服务(一定要先开启rpcbind,因为nfs依赖于rpcbind)


[root@ky17 ~]# systemctl start nfs
[root@ky17 ~]# systemctl stop firewalld   关闭防火墙和增强功能
[root@ky17 ~]# setenforce 0
[root@ky17 ~]# netstat -anpu|grep rpc
udp        0      0 127.0.0.1:942           0.0.0.0:*                           24510/rpc.statd     
udp        0      0 0.0.0.0:20048           0.0.0.0:*                           24536/rpc.mountd    
udp        0      0 0.0.0.0:39223           0.0.0.0:*                           24510/rpc.statd     
udp        0      0 0.0.0.0:704             0.0.0.0:*                           8589/rpcbind        
udp6       0      0 :::34217                :::*                                24510/rpc.statd     
udp6       0      0 :::20048                :::*                                24536/rpc.mountd    
udp6       0      0 :::704                  :::*                                8589/rpcbind        
[root@ky17 ~]# showmount -e 192.168.247.18   查看共享目录
Export list for 192.168.247.18:
/opt/web 192.168.247.0/24
[root@ky17 ~]# exportfs -v    发布共享
/opt/web      	192.168.247.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

~                                                                         

 

配置客户端
[root@ky17 bao]# yum install nfs-utils rpcbind -y   安装nfs软件包
[root@ky17 bao]# showmount -e 192.168.247.18
Export list for 192.168.247.18:
/opt/web 192.168.247.0/24       
[root@ky17 bao]# systemctl start rpcbind      开启服务
[root@ky17 bao]# systemctl start nfs
[root@ky17 bao]# systemctl stop firewalld
[root@ky17 bao]# setenforce 0
[root@ky17 bao]# ls /var/www
cgi-bin  html
[root@ky17 bao]# ls /var/www/
cgi-bin  html
[root@ky17 bao]# mount -t nfs 192.168.247.18:/opt/web /var/www/html/ 将服务器共享的目录挂载到本机的/var/www/html/目录下

[root@ky17 bao]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/sda3               xfs        57G  5.2G   52G   10% /
devtmpfs                devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G    0% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G    1% /run
tmpfs                   tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               xfs       497M  167M  330M   34% /boot
tmpfs                   tmpfs     378M  4.0K  378M    1% /run/user/42
tmpfs                   tmpfs     378M   36K  378M    1% /run/user/1000
/dev/sr0                iso9660   4.3G  4.3G     0  100% /mnt
192.168.247.18:/opt/web nfs4       57G  4.9G   52G    9% /var/www/html   挂载成功
[root@ky17 bao]# curl 127.0.0.1   
[root@ky17 bao]# echo "ceshi" >> /var/www/html/index.html   将ceshi写入服务器共享的目录文件下

切换到服务器下

[root@ky17 ~]# cd /opt     
[root@ky17 opt]# cd web
[root@ky17 web]# ls index.html     共享成功
ceshi

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5704724.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存