一、开放/nfs/shared目录,供所有用户查询资料
安装nfs和rpc的包 注意:就是安装nfs-utils会把rpcbind安装了
[root@server conf.d]# yum install nfs-utils
启动服务:nfs-utils 和rpcblind
[root@server conf.d]# systemctl restart rpcbind
[root@server conf.d]# systemctl status rpcbind
● rpcbind.service - RPC Bind
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-11-20 12:37:06 +08; 8s ago
Docs: man:rpcbind(8)
Main PID: 52502 (rpcbind)
Tasks: 1 (limit: 11174)
Memory: 932.0K
CGroup: /system.slice/rpcbind.service
└─52502 /usr/bin/rpcbind -w -f
Nov 20 12:37:06 server systemd[1]: Stopped RPC Bind.
Nov 20 12:37:06 server systemd[1]: Starting RPC Bind...
Nov 20 12:37:06 server systemd[1]: Started RPC Bind.
[root@server conf.d]# systemctl restart nfs
Failed to restart nfs.service: Unit nfs.service not found.
[root@server conf.d]# systemctl restart nfs-server
[root@server conf.d]# 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 Sun 2022-11-20 12:40:56 +08; 6s ago
Process: 52644 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
Process: 52630 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
Process: 52629 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 52644 (code=exited, status=0/SUCCESS)
Nov 20 12:40:56 server systemd[1]: Starting NFS server and services...
Nov 20 12:40:56 server exportfs[52629]: exportfs: No options for /nfs/shared 10.10.0.0/24: suggest 10.10.0.0/24(sync) to avoid warning
Nov 20 12:40:56 server exportfs[52629]: exportfs: No host name given with /nfs/shared (ro), suggest *(ro) to avoid warning
Nov 20 12:40:56 server systemd[1]: Started NFS server and services.
[root@server conf.d]#
创建目录
[root@server conf.d]# mkdir -pv /nfs/shared
mkdir: created directory '/nfs'
mkdir: created directory '/nfs/shared'
[root@server conf.d]# tree /nfs
/nfs
└── shared
1 directory, 0 files
[root@server conf.d]#
编辑配置文件:
[root@server conf.d]# vim /etc/exports
[root@server conf.d]# cat /etc/exports
/nfs/shared 10.10.0.129/24(ro)
[root@server conf.d]#
然后在/nfs/shared/下创建文件
[root@server conf.d]# echo "you visting 10.10.0.128's nfs" > /nfs/shared/server
[root@server conf.d]# cat /nfs/shared/server
you visting 10.10.0.128's nfs
[root@server conf.d]#
客户端:
[root@client ~]# systemctl restart nfs-server
[root@client ~]# showmount -e 10.10.0.128
Export list for 10.10.0.128:
/nfs/shared 10.10.0.129/24
[root@client /]# mkdir /share
[root@client /]# mount 10.10.0.128:/nfs/shared/ /share
[root@client /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 868M 0 868M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 9.5M 886M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/nvme0n1p3 xfs 57G 4.9G 52G 9% /
/dev/nvme0n1p1 xfs 495M 242M 254M 49% /boot
tmpfs tmpfs 180M 28K 179M 1% /run/user/0
/dev/sr0 iso9660 11G 11G 0 100% /run/media/root/RHEL-8-5-0-BaseOS-x86_64
10.10.0.128:/nfs/shared nfs4 37G 4.4G 33G 12% /share
[root@client /]#
客户端查看以及创建文件
[root@client /]# ll /share
total 4
-rw-r--r--. 1 root root 30 Nov 20 12:35 server
[root@client /]# cat /share/server
you visting 10.10.0.128's nfs
[root@client /]# touch /share/client
touch: cannot touch '/share/client': Read-only file system
[root@client /]#
客户换了ip:10.10.0.200
[root@client ~]# ip a s ens160
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:3d:73:2f brd ff:ff:ff:ff:ff:ff
inet 10.10.0.200/24 brd 10.10.0.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3d:732f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@client ~]# showmount -e 10.10.0.128
Export list for 10.10.0.128:
/nfs/shared 10.10.0.129
[root@client ~]# mount 10.10.0.128:/nfs/shared /share
mount.nfs: access denied by server while mounting 10.10.0.128:/nfs/shared
[root@client ~]#
二、开放/nfs/upload目录。供所有用户上传下载资料
创建/nfs/upload/目录和访问的文件
[root@server conf.d]# mkdir -pv /nfs/upload
mkdir: created directory '/nfs/upload'
[root@server conf.d]# tree /nfs
/nfs
├── shared
│ └── server
└── upload
2 directories, 1 file
[root@server conf.d]# echo "you visiting upload's directory" > /nfs/upload/allserver
[root@server conf.d]# cat /nfs/upload/allserver
you visiting upload's directory
[root@server conf.d]#
[root@server nfs]# chmod o+w upload/
[root@server nfs]# cd upload/
[root@server upload]# ll
total 4
-rw-r--r--. 1 root root 32 Nov 20 13:13 allserver
[root@server upload]# chmod o+w /nfs
[root@server upload]#
写配置文件/etc/exports
[root@server conf.d]# vim /etc/exports
[root@server conf.d]# cat /etc/exports
/nfs/shared 10.10.0.129(ro)
/nfs/upoload *(rw)
[root@server conf.d]#
重启相关的服务
[root@server conf.d]# systemctl restart rpcbind
[root@server conf.d]# systemctl restart nfs-server
客户端查看以及挂载
[root@client ~]# showmount -e 10.10.0.128
Export list for 10.10.0.128:
/nfs/upload *
/nfs/shared 10.10.0.129
[root@client /]# mount 10.10.0.128:/nfs/upload /client/
[root@client /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 868M 0 868M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 9.5M 886M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/nvme0n1p3 xfs 57G 4.9G 52G 9% /
/dev/nvme0n1p1 xfs 495M 242M 254M 49% /boot
tmpfs tmpfs 180M 28K 179M 1% /run/user/0
/dev/sr0 iso9660 11G 11G 0 100% /run/media/root/RHEL-8-5-0-BaseOS-x86_64
10.10.0.128:/nfs/upload nfs4 37G 4.4G 33G 12% /client
在客户端查看以及创建文件
[root@client /]# cd /client/
[root@client client]# ll
total 4
-rw-r--r--. 1 root root 32 Nov 20 13:13 allserver
[root@client client]# cat allserver
you visiting upload's directory
[root@client client]# echo "i'm in client" > allclient
[root@client client]# ll
total 8
-rw-r--r--. 1 nobody nobody 14 Nov 20 14:00 allclient
-rw-r--r--. 1 root root 32 Nov 20 13:13 allserver
[root@client client]#