题目要求:
• 共享/data/share目录;
• 用于存储server01主机的web数据;
• 仅允许service01主机访问该共享。
题目实施:
server01服务端配置:
安装nfs软件包:
[root@server01 ~]# yum -y install nfs-utils rpcbind
修改配置文件:
[root@server01 ~]# vim /etc/exports
#添加以下内容
/data/share 192.168.88.88/24(rw,sync,no_root_squash)
#方法二:
echo '/data/share 192.168.88.88/24(rw,sync,no_root_squash)' >> /etc/exports
#rw:可读写
#sync:同时将数据写入到内存与硬盘中,保证不丢失数据
#no_root_squash:无论 NFS 客户端使用什么用户访问,均映射为 NFS 服务器的 root 管理员
重启服务查看状态:
[root@server01 ~]# systemctl restart nfs-server
[root@server01 ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Active: active (exited) since 一 2022-12-12 19:36:44 CST; 1s ago
Process: 2052 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
Process: 2035 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 2034 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE)
Main PID: 2035 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service
12月 12 19:36:44 server01 systemd[1]: Starting NFS server and services...
12月 12 19:36:44 server01 exportfs[2034]: exportfs: Failed to stat /data/share: No...ry
12月 12 19:36:44 server01 systemd[1]: Started NFS server and services.
Hint: Some lines were ellipsized, use -l to show in full.
关闭防火墙:
[root@server01 ~]# systemctl stop firewalld
查看nfs的文件共享:
[root@server01 ~]# showmount -e 192.168.88.88
Export list for 192.168.88.88:
/data/share 192.168.88.88/24
[root@server01 ~]# exportfs -v
/data/share 192.168.88.88/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
[root@server01 ~]# exportfs -arv
exporting 192.168.88.88/24:/data/share
exportfs: Failed to stat /data/share: No such file or directory
客户端配置:
安装nfs软件包:
[root@khd ~]# yum -y install nfs-utils rpcbind
配置永久挂载:
[root@khd ~]# mkdir /data/share -p
[root@khd ~]# echo '192.168.88.88:/data/share /data/share nfs defaults_netdev 0 0' >> /etc/fstab
[root@khd ~]# mount -a
查看挂载:
[root@khd ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.4G 16G 9% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
192.168.88.88:/data/share 47G 1.5G 46G 4% /data/share
配置完成