20260417 NFS服务器

一、 NFS服务器

1.1 NFS 服务最佳实践

1.1.1 节点规划

节点名称 IP地址 作用
nfs-server 10.1.8.20/24 提供共享存储
nfs-client1 10.1.8.21/24 NFS客户端
nfs-client2 10.1.8.22/24 NFS客户端

1.1.2 部署服务

NFS服务由nfs-utils软件包提供。

bash 复制代码
# 安装包
[root@nfs-server ~ 13:54:07]# yum install -y nfs-utils
[root@nfs-server ~ 13:57:16]# yum install -y httpd

# 准备共享目录
[root@nfs-server ~ 13:59:30]# mkdir -p /shares/webapp
[root@nfs-server ~ 14:33:11]# chown apache /shares/webapp

# 启用并启动服务
[root@nfs-server ~ 14:33:25]# systemctl enable nfs-server --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

# 配置防火墙
[root@nfs-server ~ 14:33:41]# systemctl stop firewalld

1.1.3 客户端挂载

nfs-client1:

bash 复制代码
# 安装软件包
[root@nfs-client1 ~]# yum install -y nfs-utils httpd
[root@nfs-client1 ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache)
[root@nfs-client1 ~]# systemctl enable httpd --now
# 查看服务端提供的共享
[root@nfs-client1 ~]# showmount -e 10.1.8.20
Export list for storage:
/shares/webapp 10.1.8.0/24
# 挂载
[root@nfs-client1 ~]# mount -t nfs 10.1.8.20:/shares/webapp /var/www/html
# 验证
# 发现nfs-server上的/shares/webapp已经挂载到本地的/var/www/html
[root@nfs-client1 ~]# df -h | grep www
10.1.8.20:/shares/webapp   
50G  4.9G   46G  10% /var/www/html

nfs-client2:

bash 复制代码
# 安装软件包
[root@nfs-client2 ~]# yum install -y nfs-utils httpd
[root@nfs-client2 ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache)
[root@client ~]# systemctl enable httpd --now
# 查看服务端提供的共享
[root@nfs-client2 ~]# showmount -e 10.1.8.20
Export list for storage:
/shares/webapp 10.1.8.0/24
# 挂载
[root@nfs-client2 ~]# mount -t nfs 10.1.8.20:/shares/webapp /var/www/html
# 验证
# 发现nfs-server上的/shares/webapp已经挂载到本地的/var/www/html
[root@nfs-client2 ~]#  df -h | grep www
10.1.8.20:/shares/webapp   
50G  4.9G   46G  10% /var/www/html

测试

bash 复制代码
# nfs-client1 创建了xiyangyang文件,nfs-clien2也能看到,证明使用了相同的共享存储10.1.8.20
[root@nfs-client1 ~]# touch /var/www/html/xiyangyang
[root@nfs-client2 ~]# ls /var/www/html/
xiyangyang

实战测试

在nfs-server上共享的目录里(/shares/webapp)创建index.html

bash 复制代码
[root@nfs-server ~]# echo xixihahaheihei1-109 > /shares/webapp/index.html

nfs-client1,nfs-client2的网站打开看到一样的内容都是从nfs-server来的

权限测试

bash 复制代码
# nfs-server修改配置文件
[root@nfs-server ~]# vim /etc/exports
/shares/webapp 10.1.8.0/24(rw)
[root@nfs-server ~]# systemctl reload nfs-server.service 
# root用户不能创建
[root@nfs-client1 ~]# touch /var/www/html/file1
touch: cannot touch '/var/www/html/file1': Permission denied
# apache 用户能创建
[root@client ~]# su -l -s /bin/bash apache-bash-4.2$ echo apache website > /var/www/html/web1.html

1.2 持久化挂载

修改 /etc/fstab,最后添加如下记录:

bash 复制代码
[root@nfs-client1 ~]# vim /etc/fstab 
10.1.8.20:/shares/webapp /var/www/html nfs defaults 0 0
# 重启完,发现自动挂载
[root@nfs-client1 ~]# reboot
[root@nfs-client1 ~]# df | grep www
10.1.8.20:/shares/webapp  52403200 5110784  47292416  10% /var/www/html
相关推荐
en.en..1 小时前
Linux 孤儿进程与僵尸进程
linux·运维·服务器
一只积极向上的小咸鱼5 小时前
Codex Remote SSH / Dev Container 无限转圈与 GPT-6 可用问题排查总结
运维·gpt·ssh
智塑未来5 小时前
自动化立体库工业无线通信:AGV、AMR、RGV、穿梭车、无人叉车、堆垛机全覆盖
运维·自动化
T1mzhou6 小时前
ARM64 Linux 6.10内核启动流程7-ioremap和readl writel
linux·服务器·c语言
小羊没烦恼!7 小时前
Hello Web API系列教程——Web API与国际化
java·服务器·前端·javascript·php
Elastic 中国社区官方博客7 小时前
教程:使用 ES|QL 进行威胁狩猎
大数据·运维·数据库·elasticsearch·搜索引擎·全文检索·安全威胁分析
bwz999@88.com7 小时前
Ubuntu Server 24.04 设置中文
linux·运维·ubuntu
fly-977 小时前
Ubuntu FTP/SFTP 报错:找不到匹配的 hostkey 算法 完整解决
linux·ubuntu
Cx330❀7 小时前
【Linux网络】网络层协议 IP :从网络层原理到 Linux 内核源码
linux·运维·服务器·网络·tcp/ip·ai·ai编程