NFS
1 | #debian |
#下载安装包
sudo apt-get install nfs-common nfs-kernel-server -y –download-only
sudo yum install nfs-utils rpcbind -y –downloadonly –downloaddir /opt/nfs
- 首先服务器端启动RPC服务,并开启111端口;启动NFS服务,并向RPC注册端口信息
- 客户端启动RPC(portmap服务),向服务端的RPC(portmap)服务请求服务端的NFS端口(由程序在NFS客户端发起存取文件的请求,客户端本地的RPC(rpcbind)服务会通过网络向NFS服务端的RPC的111端口发出文件存取功能的请求。)
- 服务端的RPC(portmap)服务反馈NFS端口信息给客户端。
- 客户端通过获取的NFS端口来建立和服务端的NFS连接并进行数据的传输。(客户端获取正确的端口,并与NFS daemon联机存取数据。)
- 存取数据成功后,返回前端访问程序,完成一次存取操作。
安装
1 | sudo rpm -ivh /opt/nfs/*.rpm --force --nodeps |
服务端
设置共享目录
1 | #开启 |
exports配置
/etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
#/opt/data ip地址为客户端的地址或网段(rw,sync,no_root_squash,insecure)
/opt/data/k8s/redis/pv1 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/pv2 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/pv3 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/pv4 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/pv5 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/pv6 192.168.56.0/24(rw,sync,no_root_squash)
/opt/data/k8s/redis/srcipt 192.168.56.0/24(rw,sync,no_root_squash)
exportfs: /etc/exports [3]: Neither ‘subtree_check’ or ‘no_subtree_check’ specified for export “192.168.122.0/24:/home/cs/data/k8s/mysql/pv3”.
Assuming default behaviour (‘no_subtree_check’).
NOTE: this default has changed since nfs-utils version 1.0.x#即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限
/home/cs/data/k8s/mysql/pv3 192.168.122.0/24(rw,sync,no_root_squash,no_subtree_check)
重新加载 可以让配置文件,重新生效。不需要重启
1 | ❯ sudo exportfs -arv |
客户端
1 | #服务端ip,查看服务端里面可以挂载的目录 |
[root@base opt]# df -Th /opt/data/k8s/mysql/pv3
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 19G 2.6G 17G 14% /
1 | echo "192.168.122.6:/data /opt nfs default 0 0" >>/etc/fstab |
1 | $ showmount -e 192.168.122.8 |
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
服务端防火墙
1 | systemctl status firewalld |
[root@test opt]# firewall-cmd –add-service=nfs
success
[root@test opt]# firewall-cmd –add-service=rpc-bind
success
[root@test opt]# firewall-cmd –add-service=mountd
success
卸载
1 | ❯ sudo apt remove --purge nfs-common nfs-kernel-server |