NFS共享存储服务
服务端部署
| 安装NFS工具包spcbind服务 |
| [root@nfs-31 ~] |
| |
| |
| 检查rpcbind服务是否运行 |
| [root@nfs-31 ~] |
| ● rpcbind.service - RPC bind service |
| Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled) |
| Active: inactive (dead) |
| [root@nfs-31 ~] |
| Active Internet connections (only servers) |
| Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name |
| tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 964/sshd |
| tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1401/master |
| tcp6 0 0 :::22 :::* LISTEN 964/sshd |
| tcp6 0 0 ::1:25 :::* LISTEN 1401/master |
| |
| |
| |
| 启动rpcbind服务,检查运行端口 |
| [root@nfs-31 ~] |
| [root@nfs-31 ~] |
| Active Internet connections (only servers) |
| Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name |
| tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1754/rpcbind |
| tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 964/sshd |
| tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1401/master |
| tcp6 0 0 :::111 :::* LISTEN 1754/rpcbind |
| tcp6 0 0 :::22 :::* LISTEN 964/sshd |
| tcp6 0 0 ::1:25 :::* LISTEN 1401/master |
| udp 0 0 0.0.0.0:657 0.0.0.0:* 1754/rpcbind |
| udp 0 0 0.0.0.0:111 0.0.0.0:* 1754/rpcbind |
| udp6 0 0 :::657 :::* 1754/rpcbind |
| udp6 0 0 :::111 :::* 1754/rpcbind |
| [root@nfs-31 ~] |
| tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1754/rpcbind |
| tcp6 0 0 :::111 :::* LISTEN 1754/rpcbind |
| udp 0 0 0.0.0.0:657 0.0.0.0:* 1754/rpcbind |
| udp 0 0 0.0.0.0:111 0.0.0.0:* 1754/rpcbind |
| udp6 0 0 :::657 :::* 1754/rpcbind |
| udp6 0 0 :::111 :::* 1754/rpcbind |
| |
修改配置文件
| 一个目录为读写,一个目录为只读 |
| [root@nfs-31 /etc] |
| [root@nfs-31 /] |
| /ops_data 172.16.1.0/24(rw,sync,all_squash) |
| /dev_data 172.16.1.0/24(ro,sync,all_squash) |
| |
| |
| |
| 创建,共享存储目录,以及修改文件的属主,属组 |
| [root@nfs-31 /] |
| [root@nfs-31 /] |
| [root@nfs-31 /] |
| [root@nfs-31 /] |
| |
| |
| 启动nfs服务,检查运行状态 |
| [root@nfs-31 /] |
| [root@nfs-31 /] |
| ● nfs-server.service - NFS server and services |
| Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled) |
| Active: active (exited) since Fri 2022-04-22 11:26:57 CST; 11s ago |
| Process: 2176 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS) |
| Process: 2159 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) |
| Process: 2158 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS) |
| Main PID: 2159 (code=exited, status=0/SUCCESS) |
| CGroup: /system.slice/nfs-server.service |
| |
| Apr 22 11:26:57 nfs-31 systemd[1]: Starting NFS server and services... |
| Apr 22 11:26:57 nfs-31 systemd[1]: Started NFS server and services. |
| [root@nfs-31 /] |
| root 2162 2 0 11:26 ? 00:00:00 [nfsd4_callbacks] |
| root 2168 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2169 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2170 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2171 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2172 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2173 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2174 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2175 2 0 11:26 ? 00:00:00 [nfsd] |
| root 2190 1329 0 11:27 pts/0 00:00:00 grep --color=auto nfs |
| |
| |
| |
| |
| 检查nfs服务端的共享情况,使用showmount命令查看 |
| [root@nfs-31 /] |
| Export list for 172.16.1.31: |
| /dev_data 172.16.1.0/24 |
| /ops_data 172.16.1.0/24 |
| |
| |
| |
| |
| 查看nfs服务端远程共享的所有参数,是系统自动生成的,以及我们配置文件里定义的,都是默认的 |
| [root@nfs-31 /] |
| /dev_data 172.16.1.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,all_squash) |
| /ops_data 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash) |
| |
| 注意: |
| |
| /etc/exports文件的语法不要写错,细心 |
| 修改/etc/exports文件后,注意要重启systemctl reload nfs或是exportfs -r重新加载配置,无需重启 |
客户端部署
一共两台机器
rsync-41和web-7
| rsync-41部署 |
| |
| 安装nfs工具包 |
| [root@rsync-41 ~] |
| |
| |
| 运行客户端的rpcbind程序 |
| [root@rsync-41 ~] |
| |
| 远程查看nfs服务器信息 |
| [root@rsync-41 ~] |
| Export list for 172.16.1.31: |
| /dev_data 172.16.1.0/24 |
| /ops_data 172.16.1.0/24 |
| |
| |
| 创建用于挂载的文件夹 |
| [root@rsync-41 ~] |
| |
| 挂载到可读写的目录 |
| [root@rsync-41 ~] |
| |
| 查看挂载情况 |
| [root@rsync-41 ~] |
| Filesystem Size Used Avail Use% Mounted on |
| /dev/mapper/centos-root 17G 1.6G 16G 10% / |
| devtmpfs 899M 0 899M 0% /dev |
| tmpfs 911M 0 911M 0% /dev/shm |
| tmpfs 911M 9.5M 902M 2% /run |
| tmpfs 911M 0 911M 0% /sys/fs/cgroup |
| /dev/sda1 1014M 142M 873M 14% /boot |
| tmpfs 183M 0 183M 0% /run/user/0 |
| 172.16.1.31:/ops_data 17G 1.6G 16G 10% /data |
| |
| 创建目录和文件,都可以执行 |
| [root@rsync-41 ~] |
| [root@rsync-41 /data] |
| [root@rsync-41 /data] |
| [root@rsync-41 /data] |
| [root@rsync-41 /data] |
| 666啊 牛啊牛啊 |
| |
| |
| 服务端查看如下 |

| web-7客户端部署 |
| |
| 安装nfs工具包 |
| [root@web-7 ~] |
| |
| |
| 运行客户端的rpcbind程序 |
| [root@web-7 ~] |
| |
| |
| 远程查看nfs服务器信息 |
| [root@web-7 ~] |
| Export list for 172.16.1.31: |
| /dev_data 172.16.1.0/24 |
| /ops_data 172.16.1.0/24 |
| |
| |
| 创建用于挂载的文件夹 |
| [root@web-7 ~] |
| |
| |
| 挂载到只读的目录 |
| [root@web-7 ~] |
| |
| |
| 查看挂载情况 |
| [root@web-7 ~] |
| Filesystem Size Used Avail Use% Mounted on |
| /dev/mapper/centos-root 17G 1.6G 16G 9% / |
| devtmpfs 899M 0 899M 0% /dev |
| tmpfs 911M 0 911M 0% /dev/shm |
| tmpfs 911M 9.5M 902M 2% /run |
| tmpfs 911M 0 911M 0% /sys/fs/cgroup |
| /dev/sda1 1014M 142M 873M 14% /boot |
| tmpfs 183M 0 183M 0% /run/user/0 |
| 172.16.1.31:/dev_data 17G 1.6G 16G 10% /data |
| |
| |
| |
| 创建目录和文件都没有权限,因为是只读的 |
| [root@web-7 /data] |
| mkdir: cannot create directory ‘666啊’: Read-only file system |
| [root@web-7 /data] |
| touch: cannot touch ‘牛啊牛啊’: Read-only file system |
| |
| ls查看什么都没有 |
| [root@web-7 /data] |
| [root@web-7 /data] |
| |
| |
| |
| 服务端查看该文件夹 |

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)