CentOS8 NFS配置部署

NFS简介

NFS网络文件系统是一种用于在linux系统中共享资源的服务软件。
特点:

  1. 基于TCP/IP协议,服务于linux之间资源共享
  2. 将远程主机上共享资源挂载到本地目录,使得像使用本地资源一样使用共享文件。

NFS部署实践

CentOS8中默认安装了nfs-utils软件包。

服务端配置

创建共享目录

步骤:

  1. 创建共享目录
  2. 设置目录权限,确保其他人有写入权限
[root@MyCentOS home]# mkdir nfs_database
[root@MyCentOS home]# chmod 777 nfs_database
[root@MyCentOS home]# cd nfs_database/
[root@MyCentOS nfs_database]# ll
总用量 0
[root@MyCentOS nfs_database]# echo "this is nfs database test !!" > nfs_test.txt
echo "this is nfs database test ll" > nfs_test.txt

编辑NFS服务程序配置文件

NFS配置文件中默认没有任何内容。
定义要共享的目录与相应权限格式:
共享文件路径 允许访问的NFS客户端
配置文件路径/etc/exports
---------------------------------------------------------NFS配置文件参数-------------------------------------------------------

参数作用
ro只读(read only)
rw读写(read write)
root_squash当NFS客户端以root管理员访问时,映射为NFS服务器匿名用户
no_root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
sync同时将数据写入到内存与硬盘中,保证不丢失数据
async优先将数据保存到内存,然后再写入硬盘,效率更高,但可能丢失数据
/home/nfs_database 192.168.127.* (rw,async,root_squash) 《《《允许该IP地址范围内的所有主机访问NFS共享资源文件夹

启动和启用NFS服务程序

在使用NFS服务之前,首先需要调用RPC服务程序将NFS服务器IP地址和端口号信息发送给客户端。
步骤:

  1. 重启并启用rpc服务程序
  2. 启动NFS服务程序
  3. 将两个程序都加入到开启自动项中
[root@MyCentOS home]# systemctl restart rpcbind
[root@MyCentOS home]# systemctl enable rpcbind
[root@MyCentOS home]# systemctl start nfs-server
[root@MyCentOS home]# systemctl enable nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.

重要总结

在完成上述配置之后,一定要注意查看当下防火墙和SELinux安全上下文
每当部署一个服务之后一定要将该服务添加到防火墙中进行放行。部署nfs服务不仅需要nfs服务软件包,还需要rpc-bind服务和mountd服务。因为nfs服务需要向客户端广播地址和端口信息,nfs客户端需要使用mount对远程nfs服务器目录进行挂载。

十分重要: 在向防火墙添加服务后一定要使用firewall-cmd --reload进行更新

[root@MyCentOS home]# firewall-cmd --permanent --zone=internal --add-service=nfs
success
[root@MyCentOS home]# firewall-cmd --permanent --zone=internal --add-service=rpc-bind
success
[root@MyCentOS home]# firewall-cmd --permanent --zone=internal --add-service=mountd
success
[root@MyCentOS home]# firewall-cmd --reload 
success

客户端配置

查询NFS服务器共享信息

使用showmount命令查询NFS服务器共享信息
输出格式: 共享目录名称 允许使用的客户端地址

--------------------------------------------------------showmount参数----------------------------------------------------------

参数作用
-e显示NFS服务器共享列表
-a显示本地挂载的文件资源情况
-v显示版本号

在linux系统中部署nfs客户端,另以linux系统是Ubuntu系统。

  1. 安装nfs客户端
root@ubuntu:~# apt-get install nfs-common
  1. 查询远程nfs服务器是否能够连通
root@ubuntu:~# showmount -e 192.168.127.200
Export list for 192.168.127.200:
/home/nfs_database (everyone)
  1. 创建本地nfs专用共享目录
root@ubuntu:~# mkdir nfs_database
  1. 将远程nfs服务器共享目录挂载到本地创建的nfs共享目录
root@ubuntu:~# mount -t nfs 192.168.127.200:/home/nfs_database nfs_database

释义:

  • -t 参数表示使用的是TCP协议
  • nfs 表示为nfs服务
  • 192.168.127.200:/home/nfs_database 表示远程nfs服务器资源共享目录
  • nfs-database 表示本地资源共享目录
  1. 将挂载信息写入到客户端fstab文件中
192.168.127.200:/home/nfs_database /nfs_database nfs defaults 0 0

结果显示

root@ubuntu:~# cd nfs_database/
root@ubuntu:~/nfs_database# ll
total 8
drwxrwxrwx 2 root root   26 814 15:49 ./
drwx------ 6 root root 4096 814 19:44 ../
-rw-r--r-- 1 root root   29 814 15:49 nfs_test.txt
root@ubuntu:~/nfs_database# cat nfs_test.txt
this is nfs database test created by CentOS8  !! 

bingo ! ! ! ! ! !

  • 3
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值