nfs资源共享

实现功能

1、开放/nfs/shared目录,供所有用户查询资料;
2、开放/nfs/upload目录,供所有用户上传下载资料;

一、服务端配置

装包

[root@cent-83master yum.repos.d]# yum install mod_ssl -y

查看配置文件是否齐全

[root@cent-83master yum.repos.d]# rpm -ql mod_ssl
/etc/httpd/conf.d/ssl.conf
/etc/httpd/conf.modules.d/00-ssl.conf
/usr/lib/.build-id
/usr/lib/.build-id/e6/046e586d8d19fb92e3f8484a62203e841c3e2a
/usr/lib/systemd/system/httpd-init.service
/usr/lib/systemd/system/httpd.socket.d/10-listen443.conf
/usr/lib64/httpd/modules/mod_ssl.so
/usr/libexec/httpd-ssl-gencerts
/usr/libexec/httpd-ssl-pass-dialog
/usr/share/man/man8/httpd-init.service.8.gz
/var/cache/httpd/ssl
[root@cent-83master yum.repos.d]#

安装rpc

[root@red-85 yum.repos.d]# yum install rpcbind -y

查看相关配置文件

[root@red-85 yum.repos.d]# rpm -ql rpcbind
/etc/sysconfig/rpcbind
/run/rpcbind
/usr/bin/rpcbind
/usr/bin/rpcinfo
/usr/lib/.build-id
/usr/lib/.build-id/bb
/usr/lib/.build-id/bb/5282c412c3b89239b3af08911df67e7cc71e0a
/usr/lib/.build-id/bd
/usr/lib/.build-id/bd/68b3a188a7876638999a0238d315809e14bbc9
/usr/lib/systemd/system/rpcbind.service
/usr/lib/systemd/system/rpcbind.socket
/usr/lib/tmpfiles.d/rpcbind.conf
/usr/sbin/rpcbind
/usr/sbin/rpcinfo
/usr/share/doc/rpcbind
/usr/share/doc/rpcbind/AUTHORS
/usr/share/doc/rpcbind/ChangeLog
/usr/share/doc/rpcbind/README
/usr/share/man/man8/rpcbind.8.gz
/usr/share/man/man8/rpcinfo.8.gz
[root@red-85 yum.repos.d]#

查看rpc服务情况,如果处于关闭状态则需要开启

[root@red-85 yum.repos.d]# systemctl start rpcbind
[root@red-85 yum.repos.d]# systemctl status rpcbind
● rpcbind.service - RPC Bind
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2022-11-30 20:08:16 CST; 16h ago
     Docs: man:rpcbind(8)
 Main PID: 849 (rpcbind)
    Tasks: 1 (limit: 4652)
   Memory: 392.0K
   CGroup: /system.slice/rpcbind.service
           └─849 /usr/bin/rpcbind -w -f

Nov 30 20:08:16 red-85 systemd[1]: Starting RPC Bind...
Nov 30 20:08:16 red-85 systemd[1]: Started RPC Bind.
[root@red-85 yum.repos.d]#

启动nfs服务

[root@red-85 yum.repos.d]# systemctl start nfs-utils
[root@red-85 yum.repos.d]# systemctl status nfs-utils
● nfs-utils.service - NFS server and client services
   Loaded: loaded (/usr/lib/systemd/system/nfs-utils.service; static; vendor preset: disabled)
   Active: active (exited) since Thu 2022-12-01 12:46:02 CST; 12s ago
  Process: 38269 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 38269 (code=exited, status=0/SUCCESS)

Dec 01 12:46:02 red-85 systemd[1]: Starting NFS server and client services...
Dec 01 12:46:02 red-85 systemd[1]: Started NFS server and client services.
[root@red-85 yum.repos.d]#

创建nfs共享目录

[root@red-85 ~]# mkdir -pv /nfs/{shared,upload}
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared'
mkdir: created directory '/nfs/upload'
[root@red-85 ~]# tree /nfs
/nfs
├── shared
└── upload

2 directories, 0 files
[root@red-85 ~]#

修改的权限,将shared的其他人权限改为rx,upload的其他人权限改为rwx

[root@red-85 nfs]# ll
total 0
drwxr-xr-x. 2 root root 6 Dec  1 12:47 shared
drwxr-xr-x. 2 root root 6 Dec  1 12:47 upload
[root@red-85 nfs]# chmod o+w upload
[root@red-85 nfs]# ll
total 0
drwxr-xr-x. 2 root root 6 Dec  1 12:47 shared
drwxr-xrwx. 2 root root 6 Dec  1 12:47 upload
[root@red-85 nfs]#

 编辑nfs的配置文件

[root@red-85 nfs]# vim /etc/exports
[root@red-85 nfs]# cat /etc/exports
/nfs/shared 192.168.240.11(ro)
/nfs/upload 192.168.240.11(rw)

[root@red-85 nfs]#

关闭防火墙

[root@red-85 nfs]# systemctl stop firewalld
[root@red-85 nfs]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2022-12-02 20:09:54 CST; 3s ago
     Docs: man:firewalld(1)
  Process: 985 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, stat>
 Main PID: 985 (code=exited, status=0/SUCCESS)

Nov 30 20:08:23 red-85 systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 30 20:08:26 red-85 systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 30 20:08:27 red-85 firewalld[985]: WARNING: AllowZoneDrifting is enabled. This is considered>
Dec 02 20:09:48 red-85 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Dec 02 20:09:54 red-85 systemd[1]: firewalld.service: Succeeded.
Dec 02 20:09:54 red-85 systemd[1]: Stopped firewalld - dynamic firewall daemon.
lines 1-13/13 (END)

关闭SElinux

[root@red-85 nfs]# getenforce
Enforcing
[root@red-85 nfs]# setenforce 0
[root@red-85 nfs]# getenforce
Permissive
[root@red-85 nfs]#

重启服务端的rpc服务

[root@red-85 nfs]# systemctl restart rpcbind nfs-server
[root@red-85 nfs]# systemctl status rpcbind nfs-server
● rpcbind.service - RPC Bind
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-12-02 20:11:20 CST; 40s ago
     Docs: man:rpcbind(8)
 Main PID: 44106 (rpcbind)
    Tasks: 1 (limit: 4652)
   Memory: 1.2M
   CGroup: /system.slice/rpcbind.service
           └─44106 /usr/bin/rpcbind -w -f

Dec 02 20:11:20 red-85 systemd[1]: Starting RPC Bind...
Dec 02 20:11:20 red-85 systemd[1]: Started RPC Bind.

● 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-12-02 20:11:30 CST; 30s ago
  Process: 44097 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 44094 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
  Process: 44093 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 44122 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload >
  Process: 44111 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
  Process: 44110 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 44122 (code=exited, status=0/SUCCESS)

Dec 02 20:11:20 red-85 systemd[1]: Starting NFS server and services...
Dec 02 20:11:30 red-85 systemd[1]: Started NFS server and services.

[root@red-85 nfs]#

查看服务端的配置文件

[root@red-85 nfs]# showmount -e  192.168.240.11
Export list for 192.168.240.11:
/nfs/upload 192.168.240.11
/nfs/shared 192.168.240.11
[root@red-85 nfs]#

二、客户端的配置

安装服务端软件包

[root@cent-83master yum.repos.d]# yum install nfs-utils -y

Complete!
[root@cent-83master yum.repos.d]#

测试双方是否能够正常通信

[root@red-85 nfs]# ping 192.168.240.135
PING 192.168.240.135 (192.168.240.135) 56(84) bytes of data.
64 bytes from 192.168.240.135: icmp_seq=1 ttl=64 time=0.332 ms
64 bytes from 192.168.240.135: icmp_seq=2 ttl=64 time=0.365 ms
64 bytes from 192.168.240.135: icmp_seq=3 ttl=64 time=0.315 ms
64 bytes from 192.168.240.135: icmp_seq=4 ttl=64 time=0.344 ms
64 bytes from 192.168.240.135: icmp_seq=5 ttl=64 time=0.336 ms

--- 192.168.240.135 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4115ms
rtt min/avg/max/mdev = 0.315/0.338/0.365/0.023 ms
[root@red-85 nfs]#
[root@cent-83master yum.repos.d]# ping 192.168.240.11
PING 192.168.240.11 (192.168.240.11) 56(84) bytes of data.
64 bytes from 192.168.240.11: icmp_seq=1 ttl=64 time=0.605 ms
64 bytes from 192.168.240.11: icmp_seq=2 ttl=64 time=0.367 ms
64 bytes from 192.168.240.11: icmp_seq=3 ttl=64 time=0.390 ms
64 bytes from 192.168.240.11: icmp_seq=4 ttl=64 time=0.371 ms

--- 192.168.240.11 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 83ms
rtt min/avg/max/mdev = 0.367/0.433/0.605/0.100 ms
[root@cent-83master yum.repos.d]#

查看服务端共享文件目录

[root@cent-83master yum.repos.d]# showmount -e 192.168.240.11
Export list for 192.168.240.11:
/nfs/upload 192.168.240.11
/nfs/shared 192.168.240.11
[root@cent-83master yum.repos.d]#

在客户端对共享文件进行挂载

##创建挂载目录
[root@cent-83master ~]# mkdir /ceshi{1,2}
[root@cent-83master ~]# ll /
total 20
drwxr-xr-x.   2 root root    6 Nov 30 09:04 ceshi1
drwxr-xr-x.   2 root root    6 Nov 30 09:04 ceshi2





##挂载共享目录

[root@cent-83master /]# mount 192.168.240.128:/nfs/shared /ceshi1
[root@cent-83master /]# mount 192.168.240.128:/nfs/upload /ceshi2
[root@cent-83master /]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     372M     0  372M   0% /dev
tmpfs                        391M     0  391M   0% /dev/shm
tmpfs                        391M   11M  381M   3% /run
tmpfs                        391M     0  391M   0% /sys/fs/cgroup
/dev/mapper/cl-root           15G  2.1G   13G  14% /
/dev/nvme0n1p1               495M  166M  329M  34% /boot
tmpfs                         79M     0   79M   0% /run/user/0
192.168.240.128:/nfs/shared   30G  5.5G   25G  19% /ceshi1
192.168.240.128:/nfs/upload   30G  5.5G   25G  19% /ceshi2
[root@cent-83master /]#

客户端对共享文件进行测试

#先在服务端shared中创立file文件,并向其中写入hello world
[root@server shared]# touch file
[root@server shared]# echo hello world > /nfs/shared/file
[root@server shared]# cat file
hello world
[root@server shared]#
#随后在客户端ceshi1中查看
[root@cent-83master /]# cd /ceshi1
[root@cent-83master ceshi1]# cat file
hello world
[root@cent-83master ceshi1]# touch file1
touch: cannot touch 'file1': Read-only file system
[root@cent-83master ceshi1]#
#接下来测试客户端对应挂载到ceshi2中的/nfs/upload的权限
#先在服务端upload中创建file文件
[root@server upload]# touch file
[root@server upload]# echo hello > /nfs/upload/file
[root@server upload]# cat file
hello
[root@server upload]#
#客户端测试权限

[root@cent-83master ceshi2]# cp file /file
[root@cent-83master ceshi2]# vim file1
[root@cent-83master ceshi2]# cat file1
ceshi
[root@cent-83master ceshi2]# ll
total 8
-rw-r--r--. 1 root   root   6 Dec  3  2022 file
-rw-r--r--. 1 nobody nobody 6 Dec  3  2022 file1
[root@cent-83master ceshi2]#

[root@cent-83master ceshi2]# cd /
[root@cent-83master /]# cat file
hello
[root@cent-83master /]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值