为了配合设置k8s的存储,这篇文章讲解一下如何搭建NFS服务。
为了测试,我们暂时在k8s-master节点(172.16.64.233/24)来安装NFS服务,数据共享目录设置为/data/nfs
。
关闭防火墙
k8s集群其实都已经关了的,如果在其他机器上,先关掉。
1 2
| # systemctl stop firewalld # systemctl disable firewalld
|
安装NFS
通过yum安装nfs-utils
,这个组件会依赖rpcbind
,也会自动被安装上。
设置共享目录权限
配置NFS
NFS的默认配置文件在/etc/exports文件里,在该文件中添加如下内容:
1 2
| # vi /etc/exports /data/nfs *(rw,sync,no_root_squash)
|
启动NFS
注意启动顺序,先启动rpcbind
。
启动服务 nfs 需要向 rpc 注册,rpc 一旦重启了,注册的文件都会丢失,向他注册的服务都需要重启。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # systemctl enable rpcbind # systemctl start rpcbind # systemctl status rpcbind ● rpcbind.service - RPC bind service Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled) Active: active (running) since 日 2020-03-08 13:24:03 CST; 5s ago Process: 114504 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS) Main PID: 114505 (rpcbind) Tasks: 1 Memory: 748.0K CGroup: /system.slice/rpcbind.service └─114505 /sbin/rpcbind -w
3月 08 13:24:03 k8s-master systemd[1]: Starting RPC bind service... 3月 08 13:24:03 k8s-master systemd[1]: Started RPC bind service.
|
RPC bind服务Started说明RPC启动成功。
然后启动NFS服务:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service. # systemctl start nfs # systemctl status nfs ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled) Drop-In: /run/systemd/generator/nfs-server.service.d └─order-with-mounts.conf Active: active (exited) since 日 2020-03-08 13:25:57 CST; 6s ago Process: 116906 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS) Process: 116889 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) Process: 116887 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS) Main PID: 116889 (code=exited, status=0/SUCCESS) Tasks: 0 Memory: 0B CGroup: /system.slice/nfs-server.service
3月 08 13:25:57 k8s-master systemd[1]: Starting NFS server and services... 3月 08 13:25:57 k8s-master systemd[1]: Started NFS server and services.
|
NFS server成功启动。
我们还可以通过下面的命令确认NFS服务启动成功。
1 2 3 4 5 6 7
| # rpcinfo -p | grep nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100227 3 udp 2049 nfs_acl
|
查看具体的挂载权限:
1 2
| # cat /var/lib/nfs/etab /data/nfs *(rw,sync,wdelay,hide,nocrossmnt,secure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,no_root_squash,no_all_squash)
|
查看共享目录
在其他机器上,可以检查NFS是否有共享目录
1 2 3
| showmount -e 172.16.64.233 Exports list on 172.16.64.233: /data/nfs *
|