{"id":15875,"date":"2025-04-18T22:22:42","date_gmt":"2025-04-18T14:22:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/15875.html"},"modified":"2025-04-18T22:22:42","modified_gmt":"2025-04-18T14:22:42","slug":"%e6%90%ad%e5%bb%banfs%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/15875.html","title":{"rendered":"\u642d\u5efaNFS\u670d\u52a1\u5668"},"content":{"rendered":"<h2>\u642d\u5efaNFS\u670d\u52a1\u5668<\/h2>\n<p>\u8bb0\u5f55linux\u4e0b\u642d\u5efa\u4f7f\u7528NFS\u670d\u52a1\u5668\u7684\u4e00\u822c\u6b65\u9aa4&#xff0c;\u4ee5ubuntu20.04\u548ccentos7.9\u64cd\u4f5c\u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n<h3>1. \u5b89\u88c5 NFS \u670d\u52a1\u5668<\/h3>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 NFS \u670d\u52a1\u5668\u3002<\/p>\n<p> <span class=\"token comment\"># ubuntu\u4e0b\u5b89\u88c5<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> nfs-kernel-server<br \/>\n<span class=\"token comment\"># \u914d\u7f6e\u670d\u52a1<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl start nfs-kernel-server<br \/>\n<span class=\"token function\">sudo<\/span> systemctl <span class=\"token builtin class-name\">enable<\/span> <span class=\"token parameter variable\">&#8211;now<\/span> nfs-kernel-server<br \/>\n<span class=\"token function\">sudo<\/span> systemctl status nfs-kernel-server<\/p>\n<p><span class=\"token comment\"># centos\u4e0b\u8f7d\u5b89\u88c5<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token parameter variable\">-y<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> nfs-utils<span class=\"token comment\"># dnf\u5b89\u88c5\u7c7b\u4f3c<\/span><br \/>\n<span class=\"token comment\"># \u670d\u52a1\u4e3anfs-server\u6216\u8005nfs<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl start nfs-server.service<br \/>\n<span class=\"token function\">sudo<\/span> systemctl <span class=\"token builtin class-name\">enable<\/span> nfs-server.service<br \/>\n<span class=\"token function\">sudo<\/span> systemctl status nfs-server.service<\/p>\n<p><span class=\"token comment\"># \u786e\u8ba4nfs\u7248\u672c&#xff0c;\u8f93\u51fa\u7684\u7b2c\u4e8c\u5217<\/span><br \/>\nrpcinfo <span class=\"token parameter variable\">-p<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> nfs\n <\/li>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<p>\u53ef\u4ee5\u5728 \/etc\/nfs.conf \u627e\u5230 NFS \u5b88\u62a4\u8fdb\u7a0b\u7684\u914d\u7f6e\u6587\u4ef6&#xff0c;\u8fd8\u53ef\u4ee5\u5728 \/etc\/nfsmount.conf \u627e\u5230\u6302\u8f7d\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u5728\u6807\u51c6\u7684 NFS \u914d\u7f6e\u4e2d&#xff0c;\u4e3b\u8981\u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u662f \/etc\/exports \u7528\u4e8e NFS \u670d\u52a1\u5668\u7684\u5171\u4eab\u76ee\u5f55\u8bbe\u7f6e&#xff0c;\u800c\u4e0d\u662f \/etc\/nfs.conf\u3002\u800c\u5ba2\u6237\u7aef\u7684\u914d\u7f6e\u901a\u5e38\u6d89\u53ca \/etc\/fstab \u6216\u4f7f\u7528 mount \u547d\u4ee4\u65f6\u6307\u5b9a\u9009\u9879&#xff0c;\u5e76\u6ca1\u6709\u4e00\u4e2a\u4e13\u95e8\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<h3>2. \u521b\u5efa\u5e76\u5bfc\u51fa\u5171\u4eab<\/h3>\n<p>NFS \u5ba2\u6237\u7aef\u5c06\u5728\u670d\u52a1\u5668\u673a\u5668\u4e0a\u6302\u8f7d\u4e00\u4e2a\u76ee\u5f55&#xff0c;\u8be5\u76ee\u5f55\u6709 NFS \u670d\u52a1\u5668\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6307\u5b9a\u6302\u8f7d\u6587\u4ef6\u5939\u540d\u79f0&#xff08;\u4f8b\u5982&#xff0c;\/mnt\/nfs&#xff09;\u3002<\/p>\n<p> <span class=\"token function\">sudo<\/span> <span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> \/mnt\/nfs\n <\/li>\n<li>\n<p>\u8bbe\u7f6e\u6587\u4ef6\u5939\u7684\u6743\u9650\u3002<\/p>\n<p> <span class=\"token function\">sudo<\/span> <span class=\"token function\">chown<\/span> <span class=\"token parameter variable\">-R<\/span> nobody: \/mnt\/nfs<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">chmod<\/span> <span class=\"token parameter variable\">-R<\/span> <span class=\"token number\">777<\/span> \/mnt\/nfs\n <\/li>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<p>\u5982\u679c\u662f\u751f\u4ea7\u73af\u5883&#xff0c;\u5efa\u8bae\u6309\u7167\u6700\u5c0f\u6743\u9650\u8fdb\u884c\u8bbe\u7f6e&#xff0c;\u5426\u5219\u6709\u5b89\u5168\u9690\u60a3\u3002<\/p>\n<li>\u914d\u7f6eNFS\u5171\u4eab<\/li>\n<p>linux\u4e0bnfs\u5171\u4eab\u914d\u7f6e\u4e3b\u8981\u901a\u8fc7\u6587\u4ef6\/etc\/exports\u8fdb\u884c\u3002\u914d\u7f6e\u8bed\u6cd5&#xff1a;<\/p>\n<p>[\u5171\u4eab\u7684\u76ee\u5f551] [\u4e3b\u673a\u540d1\u6216IP\u5730\u57401(\u53c2\u65701,\u53c2\u65702,&#8230;)] [\u4e3b\u673a\u540d2\u6216IP\u5730\u57402(\u53c2\u65701,\u53c2\u65702,&#8230;)]<\/p>\n<p>[\u5171\u4eab\u7684\u76ee\u5f552] [\u4e3b\u673a\u540d1\u6216IP\u5730\u57401(\u53c2\u65701,\u53c2\u65702,&#8230;)] [\u4e3b\u673a\u540d2\u6216IP\u5730\u57402(\u53c2\u65703,\u53c2\u65704,&#8230;)]<\/p>\n<p>\u7f16\u8f91NFS\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/exports&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">vi<\/span> \/etc\/exports<\/p>\n<p>\u5c06\u5ba2\u6237\u7aef\u4fe1\u606f\u6dfb\u52a0\u5230\u6587\u4ef6\u4e2d&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;nfs ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># cat \/etc\/exports<\/span><br \/>\n\/mnt\/nfs <span class=\"token number\">10.210<\/span>.0.0\/16<span class=\"token punctuation\">(<\/span>rw,sync,no_all_squash,root_squash,no_subtree_check<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u53c2\u6570\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\/mnt\/nfs: \u5171\u4eab\u7684\u76ee\u5f55\u8def\u5f84\u3002<\/p>\n<\/li>\n<li>\n<p>192.168.0.0\/24: \u8bbe\u7f6e\u53ef\u4ee5\u8bbf\u95ee\u7684\u5ba2\u6237\u7aef\u7f51\u7edc&#xff1b;\u9664\u4e86\u7f51\u6bb5&#xff0c;\u4e5f\u53ef\u4ee5\u8bbe\u7f6eip\u6216\u8005\u57df\u540d&#xff08;client.test.com\u6216\u8005*.test.com&#xff09;&#xff0c;\u4e5f\u53ef\u4ee5\u7528*\u5141\u8bb8\u6240\u6709\u5ba2\u6237\u7aef\u7f51\u7edc\u3002<\/p>\n<\/li>\n<li>\n<p>rw,sync,no_all_squash,root_squash,no_subtree_check:<\/p>\n<ul>\n<li>rw&#xff1a;\u8868\u793a\u76ee\u5f55\u8bfb\u5199\u6743\u9650&#xff0c;\u5982\u679c\u662fro\u8868\u793a\u53ea\u8bfb\u3002<\/li>\n<li>sync&#xff1a;\u6570\u636e\u5199\u5165\u78c1\u76d8\u6a21\u5f0f\u3002sync\u8868\u793a\u540c\u6b65\u5199\u5165&#xff0c;\u6570\u636e\u4f1a\u540c\u6b65\u5199\u5165\u5230\u5185\u5b58\u548c\u786c\u76d8\u4e2d&#xff0c;\u6548\u7387\u4f4e&#xff0c;\u4f46\u53ef\u4ee5\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u3002\u76f8\u53cd async\u4e3a\u5f02\u6b65\u5199\u5165&#xff0c; \u8868\u793a\u6570\u636e\u4f1a\u5148\u6682\u5b58\u4e8e\u5185\u5b58\u4e2d&#xff0c;\u800c\u975e\u76f4\u63a5\u5199\u5165\u5230\u786c\u76d8\u4e2d&#xff0c;\u6548\u7387\u9ad8&#xff0c;\u4f46\u6781\u7aef\u60c5\u51b5\u4e0b\u65e0\u6cd5\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<li>all_squash: \u65e0\u8bba\u8bbf\u8868\u793a\u5c06\u5ba2\u6237\u7aef\u8bf7\u6c42\u4e2d\u7684\u6240\u6709\u7528\u6237 ID (UIDs) \u548c\u7ec4 ID (GIDs) \u6620\u5c04\u4e3a NFS \u670d\u52a1\u5668\u4e0a\u76f8\u540c\u7684 UIDs \u548c GIDs\u3002<\/li>\n<li>no_all_squash: \u5ba2\u6237\u7aef\u8bf7\u6c42\u4e2d\u7684\u7528\u6237\u5148\u4e0e\u672c\u673a\u7528\u6237\u5339\u914d&#xff0c;\u5339\u914d\u5931\u8d25\u540e\u518d\u6620\u5c04\u4e3a\u533f\u540d\u7528\u6237\u6216\u7528\u6237\u7ec4\u3002<\/li>\n<li>root_squash: \u5c06\u5ba2\u6237\u7aefroot\u7528\u6237\u7684\u8bf7\u6c42\u6620\u5c04\u5230\u4e00\u4e2a\u533f\u540d\u7684\u7528\u6237 ID (UID)\/\u7ec4 ID (GID)\u3002<\/li>\n<li>no_root_squash&#xff1a;\u8868\u793a\u5f53\u5ba2\u6237\u673a\u4ee5root\u8eab\u4efd\u8bbf\u95ee\u65f6\u8d4b\u4e88\u672c\u5730root\u6743\u9650&#xff0c;\u5b89\u5168\u98ce\u9669\u8f83\u5927\u3002<\/li>\n<li>no_subtree_check&#xff1a;\u5373\u4f7f\u8f93\u51fa\u76ee\u5f55\u662f\u4e00\u4e2a\u5b50\u76ee\u5f55&#xff0c;nfs\u670d\u52a1\u5668\u4e5f\u4e0d\u68c0\u67e5\u5176\u7236\u76ee\u5f55\u7684\u6743\u9650&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<li>subtree_check&#xff1a;\u82e5\u8f93\u51fa\u76ee\u5f55\u662f\u4e00\u4e2a\u5b50\u76ee\u5f55&#xff0c;\u5219nfs\u670d\u52a1\u5668\u5c06\u68c0\u67e5\u5176\u7236\u76ee\u5f55\u7684\u6743\u9650\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<li>\u5bfc\u51fa\u5171\u4eab\u7ed9\u5ba2\u6237\u7aef<\/li>\n<p>\u4f7f\u7528exportfs\u547d\u4ee4\u52a0\u8f7dexports\u914d\u7f6e&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> exportfs <span class=\"token parameter variable\">-arv<\/span><\/p>\n<p>\u6216\u8005\u4e5f\u53ef\u4ee5\u91cd\u542f NFS \u670d\u52a1\u5668&#xff1a;<\/p>\n<p><span class=\"token comment\"># ubuntu<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl restart nfs-kernel-server<\/p>\n<p><span class=\"token comment\"># centos<\/span><br \/>\nsystemctl resstart nfs<\/p>\n<p>\u67e5\u770bexport\u5217\u8868&#xff1a;<\/p>\n<p>root&#064;nfs:~<span class=\"token comment\"># showmount -e localhost<\/span><br \/>\nExport list <span class=\"token keyword\">for<\/span> localhost:<br \/>\n\/mnt\/nfs <span class=\"token number\">10.210<\/span>.0.0\/16<\/p>\n<h3>3. \u914d\u7f6e\u9632\u706b\u5899\u89c4\u5219<\/h3>\n<p><span class=\"token comment\"># 1. ubuntu\u3002<\/span><br \/>\n<span class=\"token comment\">## \u53ef\u4ee5\u5173\u95ed\u9632\u706b\u5899<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;nfs ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># ufw disable<\/span><br \/>\nFirewall stopped and disabled on system startup<br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;nfs ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># ufw status<\/span><br \/>\nStatus: inactive<\/p>\n<p><span class=\"token comment\">## \u6216\u8005ufw\u653e\u884c\u89c4\u5219<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw allow nfs<br \/>\n<span class=\"token function\">sudo<\/span> ufw allow portmapper<br \/>\n<span class=\"token function\">sudo<\/span> ufw reload<\/p>\n<p><span class=\"token comment\"># 2. centos<\/span><br \/>\n<span class=\"token comment\">## \u5173\u95ed\u9632\u706b\u5899<\/span><br \/>\nsystemctl stop firewalld<span class=\"token punctuation\">;<\/span>systemctl disable firewalld<\/p>\n<p><span class=\"token comment\">## \u6216\u8005\u914d\u7f6e\u9632\u706b\u5899\u89c4\u5219<\/span><br \/>\n<span class=\"token function\">sudo<\/span> firewall-cmd <span class=\"token parameter variable\">&#8211;permanent<\/span> &#8211;add-service<span class=\"token operator\">&#061;<\/span>nfs<br \/>\n<span class=\"token function\">sudo<\/span> firewall-cmd <span class=\"token parameter variable\">&#8211;permanent<\/span> &#8211;add-service<span class=\"token operator\">&#061;<\/span>rpc-bind<br \/>\n<span class=\"token function\">sudo<\/span> firewall-cmd <span class=\"token parameter variable\">&#8211;permanent<\/span> &#8211;add-service<span class=\"token operator\">&#061;<\/span>mountd<br \/>\n<span class=\"token function\">sudo<\/span> firewall-cmd <span class=\"token parameter variable\">&#8211;reload<\/span><\/p>\n<p>\u6309\u7167\u7aef\u53e3\u653e\u884c&#xff1a;<\/p>\n<p><span class=\"token comment\"># nfs\u76f8\u5173\u7aef\u53e3<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;nfs ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># rpcinfo -p localhost<\/span><br \/>\n   program vers proto   port  <span class=\"token function\">service<\/span><br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">4<\/span>   tcp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">3<\/span>   tcp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">2<\/span>   tcp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">4<\/span>   udp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">3<\/span>   udp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100000<\/span>    <span class=\"token number\">2<\/span>   udp    <span class=\"token number\">111<\/span>  portmapper<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">1<\/span>   udp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">1<\/span>   tcp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">2<\/span>   udp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100024<\/span>    <span class=\"token number\">1<\/span>   udp  <span class=\"token number\">48719<\/span>  status<br \/>\n    <span class=\"token number\">100024<\/span>    <span class=\"token number\">1<\/span>   tcp  <span class=\"token number\">37476<\/span>  status<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">2<\/span>   tcp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">3<\/span>   udp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100005<\/span>    <span class=\"token number\">3<\/span>   tcp  <span class=\"token number\">20048<\/span>  mountd<br \/>\n    <span class=\"token number\">100003<\/span>    <span class=\"token number\">3<\/span>   tcp   <span class=\"token number\">2049<\/span>  nfs<br \/>\n    <span class=\"token number\">100003<\/span>    <span class=\"token number\">4<\/span>   tcp   <span class=\"token number\">2049<\/span>  nfs<br \/>\n    <span class=\"token number\">100227<\/span>    <span class=\"token number\">3<\/span>   tcp   <span class=\"token number\">2049<\/span>  nfs_acl<br \/>\n    <span class=\"token number\">100003<\/span>    <span class=\"token number\">3<\/span>   udp   <span class=\"token number\">2049<\/span>  nfs<br \/>\n    <span class=\"token number\">100003<\/span>    <span class=\"token number\">4<\/span>   udp   <span class=\"token number\">2049<\/span>  nfs<br \/>\n    <span class=\"token number\">100227<\/span>    <span class=\"token number\">3<\/span>   udp   <span class=\"token number\">2049<\/span>  nfs_acl<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">1<\/span>   udp  <span class=\"token number\">53709<\/span>  nlockmgr<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">3<\/span>   udp  <span class=\"token number\">53709<\/span>  nlockmgr<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">4<\/span>   udp  <span class=\"token number\">53709<\/span>  nlockmgr<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">1<\/span>   tcp  <span class=\"token number\">37318<\/span>  nlockmgr<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">3<\/span>   tcp  <span class=\"token number\">37318<\/span>  nlockmgr<br \/>\n    <span class=\"token number\">100021<\/span>    <span class=\"token number\">4<\/span>   tcp  <span class=\"token number\">37318<\/span>  nlockmgr<\/p>\n<p>nfs\u9664\u4e86\u56fa\u5b9a\u7684port111\u30012049\u5916&#xff0c;\u8fd8\u6709\u5176\u4ed6\u670d\u52a1\u5982rpc.mounted\u7b49\u5f00\u542f\u7684\u4e0d\u56fa\u5b9a\u7684\u7aef\u53e3&#xff0c;\u5982\u679c\u6309\u7167\u7aef\u53e3\u914d\u7f6e\u5bf9\u9632\u706b\u5899\u6765\u8bf4\u5c31\u6bd4\u8f83\u9ebb\u70e6\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6eNFS\u670d\u52a1\u7684\u7aef\u53e3\u914d\u7f6e\u6587\u4ef6\/etc\/sysconfig\/nfs&#xff0c;\u5c06\u4e0b\u5217\u5185\u5bb9\u7684\u6ce8\u91ca\u53bb\u6389&#xff0c;\u5982\u679c\u6ca1\u6709\u5219\u6dfb\u52a0&#xff1a;<\/p>\n<p><span class=\"token assign-left variable\">RQUOTAD_PORT<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">1001<\/span><br \/>\n<span class=\"token assign-left variable\">LOCKD_TCPPORT<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">30001<\/span><br \/>\n<span class=\"token assign-left variable\">LOCKD_UDPPORT<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">30002<\/span><br \/>\n<span class=\"token assign-left variable\">MOUNTD_PORT<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">1002<\/span><\/p>\n<p>\u4fdd\u5b58\u540e&#xff0c;\u5c06\u7aef\u53e3\u52a0\u5165\u9632\u62a4\u5899\u653e\u884c&#xff1a;<\/p>\n<p><span class=\"token comment\"># ufw<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw allow proto tcp from any to any port <span class=\"token number\">111<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw allow proto udp from any to any port <span class=\"token number\">111<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw allow proto tcp from any to any port <span class=\"token number\">2049<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw allow proto udp from any to any port <span class=\"token number\">2049<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw reload<\/p>\n<p><span class=\"token comment\"># firewalld<\/span><br \/>\nfirewall-cmd <span class=\"token parameter variable\">&#8211;zone<\/span><span class=\"token operator\">&#061;<\/span>public &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">111<\/span>\/tcp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">111<\/span>\/udp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2049<\/span>\/tcp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2049<\/span>\/udp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1001<\/span>\/tcp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1001<\/span>\/udp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1002<\/span>\/tcp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1002<\/span>\/udp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30001<\/span>\/tcp &#8211;add-port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30002<\/span>\/udp <span class=\"token parameter variable\">&#8211;permanent<\/span><br \/>\nfirewall-cmd <span class=\"token parameter variable\">&#8211;reload<\/span><\/p>\n<h3>4. \u5ba2\u6237\u7aef\u6302\u8f7d\u9a8c\u8bc1<\/h3>\n<p>nfs\u6302\u8f7d\u9700\u8981\u5b89\u88c5nfs\u5ba2\u6237\u7aef&#xff1a;<\/p>\n<p><span class=\"token comment\"># ubuntu<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> nfs-common<\/p>\n<p><span class=\"token comment\"># centos<\/span><br \/>\nyum <span class=\"token parameter variable\">-y<\/span> <span class=\"token function\">install<\/span> nfs-utils<span class=\"token comment\"># dnf\u5b89\u88c5\u7c7b\u4f3c<\/span><\/p>\n<p>\u6267\u884c\u6302\u8f7d\u547d\u4ee4&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u67e5\u770bnfs\u5171\u4eab\u7684\u76ee\u5f55<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;client ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># showmount -e 10.210.10.209<\/span><br \/>\nExport list <span class=\"token keyword\">for<\/span> <span class=\"token number\">10.210<\/span>.10.209:<br \/>\n\/mnt\/nfs <span class=\"token number\">10.210<\/span>.0.0\/16<\/p>\n<p><span class=\"token comment\"># \u6302\u8f7d\u547d\u4ee4\u5982\u4e0b<\/span><br \/>\n<span class=\"token function\">mount<\/span> <span class=\"token parameter variable\">-t<\/span> nfs <span class=\"token operator\">&lt;<\/span>nfs-server-ip<span class=\"token operator\">&gt;<\/span>:\/exports-dir \/local-dir<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;client:~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># mkdir -p \/mnt\/nfs<\/span><br \/>\n<span class=\"token comment\"># -t\u914d\u7f6efs\u7c7b\u578b&#xff0c;\u8bbe\u7f6enfs\u6216\u8005nfs4<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;client:~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># mount -t nfs 10.210.10.209:\/mnt\/nfs \/mnt\/nfs<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;client ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># sudo mount | grep -i nfs<\/span><br \/>\n<span class=\"token number\">10.210<\/span>.10.209:\/mnt\/nfs on \/mnt\/nfs <span class=\"token builtin class-name\">type<\/span> nfs4 <span class=\"token punctuation\">(<\/span>rw,relatime,vers<span class=\"token operator\">&#061;<\/span><span class=\"token number\">4.1<\/span>,rsize<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1048576<\/span>,wsize<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1048576<\/span>,namlen<span class=\"token operator\">&#061;<\/span><span class=\"token number\">255<\/span>,hard,proto<span class=\"token operator\">&#061;<\/span>tcp,timeo<span class=\"token operator\">&#061;<\/span><span class=\"token number\">600<\/span>,retrans<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2<\/span>,sec<span class=\"token operator\">&#061;<\/span>sys,clientaddr<span class=\"token operator\">&#061;<\/span><span class=\"token number\">10.210<\/span>.10.220,local_lock<span class=\"token operator\">&#061;<\/span>none,addr<span class=\"token operator\">&#061;<\/span><span class=\"token number\">10.210<\/span>.10.209<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u8bfb\u5199<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;client ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># cd \/mnt\/nfs<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;dns nfs<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># echo aaa &gt; test.txt<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;dns nfs<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># cat test.txt<\/span><br \/>\naaa<\/p>\n<p>\u914d\u7f6e\u91cd\u542f\u7cfb\u7edf\u81ea\u52a8\u6302\u8f7d&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;client ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># cat \/etc\/fstab<\/span><br \/>\n<span class=\"token punctuation\">..<\/span>.<br \/>\n<span class=\"token number\">10.210<\/span>.10.209:\/mnt\/nfs \/mnt\/nfs nfs defaults,_netdev <span class=\"token number\">0<\/span> <span class=\"token number\">0<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;client ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># mount -a<\/span><\/p>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<li>\u53c2\u6570_netdev\u8868\u793a\u5ef6\u8fdf\u52a0\u8f7d&#xff0c;\u7b49\u5f85\u7f51\u7edc\u670d\u52a1\u542f\u52a8\u540e\u518d\u6302\u8f7d\u3002<\/li>\n<h3>5. \u76f8\u5173\u547d\u4ee4<\/h3>\n<p><span class=\"token comment\"># \u67e5\u770bnfs\u7248\u672c\u53ca\u7edf\u8ba1\u6570\u636e<\/span><br \/>\nnfsstat <span class=\"token parameter variable\">-s<\/span><span class=\"token comment\"># \u670d\u52a1\u5668\u7aef\u4f7f\u7528<\/span><br \/>\nnfsstat <span class=\"token parameter variable\">-c<\/span><span class=\"token comment\"># \u5ba2\u6237\u7aef\u4f7f\u7528<\/span><\/p>\n<h3>6. \u76f8\u5173\u8d44\u6599<\/h3>\n<li>How to configure NFS on Linux &#8211; Linux Tutorials &#8211; Learn Linux Configuration<\/li>\n<li>Learning NFS through server and client configuration | Enable Sysadmin (redhat.com)\u3001<\/li>\n<li>\u7b2c 4 \u7ae0 \u6302\u8f7d NFS \u5171\u4eab | Red Hat Product Documentation<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf31\u6b21\u3002\u8bb0\u5f55linux\u4e0b\u642d\u5efa\u4f7f\u7528NFS\u670d\u52a1\u5668\u7684\u4e00\u822c\u6b65\u9aa4\uff0c\u4ee5\u548ccentos7.9\u64cd\u4f5c\u8fdb\u884c\u8bb0\u5f55\u3002_nfs\u670d\u52a1\u5668\u642d\u5efa<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,43],"topic":[],"class_list":["post-15875","post","type-post","status-publish","format-standard","hentry","category-server","tag-linux","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/15875.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf31\u6b21\u3002\u8bb0\u5f55linux\u4e0b\u642d\u5efa\u4f7f\u7528NFS\u670d\u52a1\u5668\u7684\u4e00\u822c\u6b65\u9aa4\uff0c\u4ee5\u548ccentos7.9\u64cd\u4f5c\u8fdb\u884c\u8bb0\u5f55\u3002_nfs\u670d\u52a1\u5668\u642d\u5efa\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/15875.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T14:22:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15875.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/15875.html\",\"name\":\"\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T14:22:42+00:00\",\"dateModified\":\"2025-04-18T14:22:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/15875.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/15875.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15875.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u642d\u5efaNFS\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/15875.html","og_locale":"zh_CN","og_type":"article","og_title":"\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf31\u6b21\u3002\u8bb0\u5f55linux\u4e0b\u642d\u5efa\u4f7f\u7528NFS\u670d\u52a1\u5668\u7684\u4e00\u822c\u6b65\u9aa4\uff0c\u4ee5\u548ccentos7.9\u64cd\u4f5c\u8fdb\u884c\u8bb0\u5f55\u3002_nfs\u670d\u52a1\u5668\u642d\u5efa","og_url":"https:\/\/www.wsisp.com\/helps\/15875.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T14:22:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/15875.html","url":"https:\/\/www.wsisp.com\/helps\/15875.html","name":"\u642d\u5efaNFS\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T14:22:42+00:00","dateModified":"2025-04-18T14:22:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/15875.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/15875.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/15875.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u642d\u5efaNFS\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=15875"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15875\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=15875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=15875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=15875"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=15875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}