{"id":8772,"date":"2024-04-30T22:01:01","date_gmt":"2024-04-30T14:01:01","guid":{"rendered":""},"modified":"2024-04-30T22:01:01","modified_gmt":"2024-04-30T14:01:01","slug":"NSF\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8772.html","title":{"rendered":"NSF\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf"},"content":{"rendered":"

1\u3001NSF\u4ecb\u7ecd<\/strong>
NFS\uff0c\u662fNetwork File System\u7684\u7b80\u5199\uff0c\u5373\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u3002\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u662fFreeBSD\u652f\u6301\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u4e00\u79cd\uff0c\u4e5f\u88ab\u79f0\u4e3aNFS. NFS\u5141\u8bb8\u4e00\u4e2a\u7cfb\u7edf\u5728\u7f51\u7edc\u4e0a\u4e0e\u4ed6\u4eba\u5171\u4eab\u76ee\u5f55\u548c\u6587\u4ef6\u3002\u901a\u8fc7\u4f7f\u7528NFS\uff0c\u7528\u6237\u548c\u7a0b\u5e8f\u53ef\u4ee5\u50cf\u8bbf\u95ee\u672c\u5730\u6587\u4ef6\u4e00\u6837\u8bbf\u95ee\u8fdc\u7aef\u7cfb\u7edf\u4e0a\u7684\u6587\u4ef6\u3002<\/strong><\/span><\/p>\n

nfs\u4e3a\u4ec0\u4e48\u9700\u8981RPC?
\u56e0\u4e3aNFS\u652f\u6301\u7684\u529f\u80fd\u5f88\u591a\uff0c\u4e0d\u540c\u529f\u80fd\u4f1a\u4f7f\u7528\u4e0d\u540c\u7a0b\u5e8f\u6765\u542f\u52a8\uff0c\u56e0\u6b64\uff0cNFS\u5bf9\u5e94\u7684\u529f\u80fd\u6240\u5bf9\u5e94\u7684\u7aef\u53e3\u65e0\u6cd5\u56fa\u5b9a\u3002
\u7aef\u53e3\u4e0d\u56fa\u5b9a\u9020\u6210\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u4e4b\u95f4\u7684\u901a\u4fe1\u969c\u788d\uff0c\u6240\u4ee5\u9700\u8981RPC\u6765\u4ece\u4e2d\u5e2e\u5fd9\u3002
NFS\u542f\u52a8\u65f6\u4f1a\u968f\u673a\u53d6\u7528\u82e5\u5e72\u7aef\u53e3\uff0c\u7136\u540e\u4e3b\u52a8\u5411RPC\u670d\u52a1\u6ce8\u518c\u53d6\u7528\u76f8\u5173\u7aef\u53e3\u548c\u529f\u80fd\u4fe1\u606f\uff0cRPC\u4f7f\u7528\u56fa\u5b9a\u7aef\u53e3111\u6765\u76d1\u542c\u6765\u81eaNFS\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u5e76\u5c06\u6b63\u786e\u7684NFS\u670d\u52a1\u7aef\u53e3\u4fe1\u606f\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff0c\u8fd9\u6837\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u5c31\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u4e86\u3002<\/p>\n

2\u3001NFS\u7684\u5de5\u4f5c\u6d41\u7a0b<\/strong>
1\u3001\u7531\u7a0b\u5e8f\u5728NFS\u5ba2\u6237\u7aef\u53d1\u8d77\u5b58\u53d6\u6587\u4ef6\u7684\u8bf7\u6c42\uff0c\u5ba2\u6237\u7aef\u672c\u5730\u7684RPC(rpcbind)\u670d\u52a1\u4f1a\u901a\u8fc7\u7f51\u7edc\u5411NFS\u670d\u52a1\u7aef\u7684RPC\u7684111\u7aef\u53e3\u53d1\u51fa\u6587\u4ef6\u5b58\u53d6\u529f\u80fd\u7684\u8bf7\u6c42\u3002
2\u3001NFS\u670d\u52a1\u7aef\u7684RPC\u627e\u5230\u5bf9\u5e94\u5df2\u6ce8\u518c\u7684NFS\u7aef\u53e3\uff0c\u901a\u77e5\u5ba2\u6237\u7aefRPC\u670d\u52a1\u3002
3\u3001\u5ba2\u6237\u7aef\u83b7\u53d6\u6b63\u786e\u7684\u7aef\u53e3\uff0c\u5e76\u4e0eNFS daemon\u8054\u673a\u5b58\u53d6\u6570\u636e\u3002
4\u3001\u5b58\u53d6\u6570\u636e\u6210\u529f\u540e\uff0c\u8fd4\u56de\u524d\u7aef\u8bbf\u95ee\u7a0b\u5e8f\uff0c\u5b8c\u6210\u4e00\u6b21\u5b58\u53d6\u64cd\u4f5c\u3002
\u6240\u4ee5\u65e0\u8bba\u5ba2\u6237\u7aef\uff0c\u670d\u52a1\u7aef\uff0c\u9700\u8981\u4f7f\u7528NFS\uff0c\u5fc5\u987b\u5b89\u88c5RPC\u670d\u52a1\u3002
NFS\u7684RPC\u670d\u52a1\uff0c\u5728Centos5\u4e0b\u540d\u4e3aportmap,Centos6\u4e0b\u540d\u79f0\u4e3arpcbind\u3002<\/p>\n

3\u3001\u5b89\u88c5nfs\u670d\u52a1<\/strong>
[root@k8smaster ~]# systemctl restart rpcbind;systemctl status rpcbind #\u670d\u52a1\u7aef\u5fc5\u987b\u5b89\u88c5rpcbind<\/strong><\/span>
[root@k8snode01 ~]# systemctl restart rpcbind;systemctl status rpcbind #\u5ba2\u6237\u7aef\u53ef\u4ee5\u4e0d\u5b89\u88c5rpcbind<\/strong><\/span>
[root@k8snode02 ~]# systemctl restart rpcbind;systemctl status rpcbind #\u5ba2\u6237\u7aef\u53ef\u4ee5\u4e0d\u5b89\u88c5rpcbind<\/strong><\/span><\/p>\n

[root@k8smaster ~]# systemctl restart nfs;systemctl status nfs #\u670d\u52a1\u7aef\u5fc5\u987b\u5b89\u88c5nfs<\/strong><\/span>
[root@k8snode01 ~]# systemctl restart nfs;systemctl status nfs #\u5ba2\u6237\u7aef\u5fc5\u987b\u5b89\u88c5nfs<\/strong><\/span>
[root@k8snode02 ~]# systemctl restart nfs;systemctl status nfs #\u5ba2\u6237\u7aef\u5fc5\u987b\u5b89\u88c5nfs<\/strong><\/span><\/p>\n

[root@k8smaster ~]# mkdir \/sharedir #\u521b\u5efa\u6302\u8f7d\u76ee\u5f55\uff08\u5efa\u8bae\u548c\u670d\u52a1\u7aef\u540c\u8def\u5f84\uff0c\u4fbf\u4e8e\u7edf\u4e00\u7ba1\u7406\uff09<\/strong><\/span>
[root@k8snode01 ~]# mkdir \/sharedir #\u521b\u5efa\u6302\u8f7d\u76ee\u5f55\uff08\u5efa\u8bae\u548c\u670d\u52a1\u7aef\u540c\u8def\u5f84\uff0c\u4fbf\u4e8e\u7edf\u4e00\u7ba1\u7406\uff09<\/strong><\/span>
[root@k8snode01 ~]# mkdir \/sharedir #\u521b\u5efa\u6302\u8f7d\u76ee\u5f55\uff08\u5efa\u8bae\u548c\u670d\u52a1\u7aef\u540c\u8def\u5f84\uff0c\u4fbf\u4e8e\u7edf\u4e00\u7ba1\u7406\uff09<\/strong><\/span>
[root@k8smaster ~]# chmod -R 777 \/sharedir #\u6743\u9650\u8bbe\u7f6e<\/strong><\/span><\/p>\n

[root@k8smaster ~]# more \/etc\/exports #\u670d\u52a1\u7aefNFS\u914d\u7f6e\u6587\u4ef6<\/strong><\/span>
\/sharedir *(rw,sync,all_squash)<\/strong><\/span>
[root@k8smaster ~]# exportfs -rv #\u914d\u7f6e\u751f\u6548<\/strong><\/span>
exporting *:\/sharedir
[root@k8smaster sharedir]# showmount -e #\u663e\u793a\u5171\u4eab\u76ee\u5f55<\/strong><\/span>
Export list for k8smaster:
\/sharedir *
[root@k8smaster sharedir]#
\/sharedir - \u4e3a\u5171\u4eab\u76ee\u5f55
* - \u8868\u793a\u53ef\u8bbf\u95ee\u5ba2\u6237\u7aef\u7684IP\u6216IP\u6bb5<\/strong><\/span>\uff08\u652f\u6301\u5355\u4e2aIP\"192.168.1.0\"\u3001IP\u6bb5\"192.168.1.0\/24\"\u3001\u901a\u914d\u7b26\u57df\u540d\"*.qq.com\"\u7b49\uff09
rw - \u8868\u793a\u8bfb\u5199\u6743\u9650<\/strong><\/span>
ro - \u8868\u793a\u53ea\u8bfb\u6743\u9650<\/strong><\/span>
sync\uff08\u540c\u6b65\uff09 - \u8bf7\u6c42\u6216\u5199\u5165\u6570\u636e\u65f6\uff0c\u6570\u636e\u540c\u6b65\u5199\u5165\u5230NFS Server\u7684\u786c\u76d8\u540e\u518d\u8fd4\u56de<\/strong><\/span>
async\uff08\u5f02\u6b65\uff09 - \u8bf7\u6c42\u6216\u5199\u5165\u6570\u636e\u65f6\uff0c\u5148\u8fd4\u56de\u8bf7\u6c42\uff0c\u518d\u5c06\u6570\u636e\u5199\u5165\u5230\u5185\u5b58\u548c\u7f13\u5b58\u4e2d\u3002\u6b64\u53c2\u6570\u53ef\u4ee5\u63d0\u5347NFS\u6027\u80fd\uff0c\u4f46\u662f\u4f1a\u964d\u4f4e\u6570\u636e\u5b89\u5168\uff0c\u4e0d\u5efa\u8bae\u4f7f\u7528<\/strong><\/span>
no_root_squash - \u8bbf\u95eeNFS Sever\u5171\u4eab\u76ee\u5f55\u7684\u7528\u6237\u5982\u679c\u662froot\u7684\u8bdd\uff0c\u5b83\u5bf9\u8be5\u5171\u4eab\u76ee\u5f55\u5c31\u6709root\u6743\u9650\u3002\u907f\u514d\u4f7f\u7528<\/strong><\/span>
root_suqash - \u5bf9\u4e8e\u8bbf\u95eeNFS Server\u5171\u4eab\u76ee\u5f55\u7684\u7528\u6237\u5982\u679c\u662froot\u7684\u8bdd\uff0c\u5219\u5b83\u7684\u6743\u9650\u88ab\u538b\u7f29\u6210\u533f\u540d\u7528\u6237\uff0c\u540c\u65f6\u5b83\u7684UID\u548cGID\u4f1a\u53d8\u6210nobody\u6216nfsbody<\/strong><\/span>
all_squash - \u4e0d\u7ba1\u8bbf\u95eeNFS Server\u5171\u4eab\u76ee\u5f55\u7684\u7528\u6237\u8eab\u4efd\u5982\u4f55\uff0c\u5b83\u7684\u6743\u9650\u90fd\u5c06\u88ab\u538b\u7f29\u6210\u533f\u540d\u7528\u6237\uff0c\u540c\u65f6\u5b83\u7684UID\u548cGID\u90fd\u4f1a\u53d8\u6210nobody\u6216nfsnobody\u8d26\u53f7\uff0c\u5728\u591a\u4e2aNFS\u5ba2\u6237\u7aef\u540c\u65f6\u8bfb\u5199NFS Sever\u6570\u636e\u65f6\uff0c\u8fd9\u4e2a\u53c2\u6570\u5f88\u6709\u7528<\/strong><\/span>
anonuid - \u53c2\u6570\u4ee5anon*\u5f00\u5934\u5373\u6307anonymous\u533f\u540d\u7528\u6237\uff0c\u8fd9\u4e2a\u7528\u6237\u7684UID\u8bbe\u7f6e\u503c\u901a\u5e38\u4e3anobody\u6216nfsbody\u7684UID\u503c\uff0c\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u81ea\u884c\u8bbe\u7f6e\u8fd9\u4e2aUID\u503c\uff0c\u4f46\u662fUID\u5fc5\u987b\u5b58\u5728\u4e8e\/etc\/passwd\u4e2d\u3002
anongid - \u540canonuid\uff0c\u533a\u522b\u5c31\u662f\u628auid\u6362\u6210gid<\/p>\n

exportfs\u547d\u4ee4\u7528\u6cd5<\/strong>
-a \u5168\u90e8\u6302\u8f7d\u6216\u5378\u8f7d
-r \u91cd\u65b0\u8bfb\u53d6\/etc\/exports \u4e2d\u7684\u4fe1\u606f \uff0c\u5e76\u540c\u6b65\u66f4\u65b0\/etc\/exports\u3001\/var\/lib\/nfs\/xtab<\/strong><\/span>
-u \u5378\u8f7d\u5355\u4e00\u76ee\u5f55\uff08\u548c-a\u4e00\u8d77\u4f7f\u7528\u4e3a\u5378\u8f7d\u6240\u6709\/etc\/exports\u6587\u4ef6\u4e2d\u7684\u76ee\u5f55\uff09
-v \u5728\u5c4f\u5e55\u8f93\u51fa\u8be6\u7ec6\u4fe1\u606f<\/strong><\/span><\/p>\n

showmount \u547d\u4ee4\u7528\u6cd5<\/strong>
-a  \u663e\u793a\u5df2\u7ecf\u4e8e\u5ba2\u6237\u7aef\u8fde\u63a5\u4e0a\u7684\u76ee\u5f55\u4fe1\u606f
-e  IP\u6216\u8005hostname \u663e\u793a\u6b64IP\u5730\u5740\u5206\u4eab\u51fa\u6765\u7684\u76ee\u5f55<\/strong><\/span><\/p>\n

\u5ba2\u6237\u7aef\u6302\u8f7d<\/strong>
\u6267\u884c\u6302\u8f7d\u547d\u4ee4\uff1a
# \u683c\u5f0f\u4e3a\uff1amount -t nfs hostname(orIP):\u670d\u52a1\u7aef\u76ee\u5f55 \u672c\u673a\u76ee\u5f55<\/strong>
[root@k8snode01 ~]# mount -t nfs 192.168.23.100:\/sharedir \/sharedir<\/strong><\/span>
[root@k8snode02 ~]# mount -t nfs 192.168.23.100:\/sharedir \/sharedir<\/strong><\/span><\/p>\n

4\u3001\u64cd\u4f5c\u9a8c\u8bc1<\/strong>
\u5728node1\u548cnode2\u4e0a\u5199\u5165\u6587\u4ef6\uff0c\u5728master\u4e0a\u67e5\u770b\u5199\u5165\u60c5\u51b5
[root@k8snode01 sharedir]# echo \"node01\" >node01.log #\u5ba2\u6237\u7aef\u5199\u5165\u6587\u4ef6<\/strong><\/span>
[root@k8snode01 sharedir]# <\/p>\n

[root@k8snode02 sharedir]# echo \"node02\" >node02.log#\u5ba2\u6237\u7aef\u5199\u5165\u6587\u4ef6<\/strong><\/span>
[root@k8snode02 sharedir]# <\/p>\n

[root@k8smaster sharedir]# ls -lrt #\u670d\u52a1\u7aef\u67e5\u770b\u6587\u4ef6<\/strong><\/span>
total 8
-rw-r--r-- 1 nfsnobody nfsnobody 7 Feb 19 22:19 node01.log
-rw-r--r-- 1 nfsnobody nfsnobody 7 Feb 19 22:19 node02.log
[root@k8smaster sharedir]# more node01.log <\/strong><\/span>
node01
[root@k8smaster sharedir]# more node02.log <\/strong><\/span>
node02
[root@k8smaster sharedir]#<\/p>\n","protected":false},"excerpt":{"rendered":"NSF\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf1\u3001NSF\u4ecb\u7ecdNFS\uff0c\u662fNetworkFileSystem\u7684\u7b80\u5199\uff0c\u5373\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8772"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8772"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8772\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}