挂载NFS文件系统到云服务器(Linux)
<p class="shortdesc">登录到云主机后,可以在Linux操作系统下完成NFS文件系统的挂载。</p>
<section class="section prereq" id="MountNFS__prereq_vjn_5hl_3mb"><div class="tasklabel"><h2 class="doc-tairway">前提条件</h2></div>
<p class="p">您需要连接到云主机下完成如下操作。</p>
</section>
<section class="section context" id="MountNFS__context_e2y_pll_3mb"><div class="tasklabel"><h2 class="doc-tairway">背景信息</h2></div>
<p class="p">创建完文件系统后,您需要在已授权的云服务器操作系统下挂载该文件系统。这样,云服务器才能够像访问本地磁盘一样访问EFS文件系统。</p>
</section>
<section id="MountNFS__steps_u3r_lnk_3mb"><div class="tasklabel"><h2 class="doc-tairway">操作步骤</h2></div><ol class="ol steps" id="MountNFS__steps_u3r_lnk_3mb"><li class="li step stepexpand">
<span class="ph cmd">检查已经安装NFS客户端软件包(以CentOS系统为例)。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>rpm -qa|grep nfs</code></pre>
<p class="p">如果出现如下示例类似提示信息,则说明已经安装过NFS客户端软件包,则执行步骤3。如果显示为空,则说明没有安装过NFS客户端,执行步骤2。</p>
<p class="p">示例:</p>
<pre class="pre codeblock"><code>[root@efs ~]# rpm -qa|grep nfs
libnfsidmap-0.25-19.el7.x86_64
nfs-utils-1.3.0-0.61.el7.x86_64</code></pre>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">安装NFS客户端。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>sudo yum -y install nfs-utils</code></pre>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">创建用于挂载文件系统的本地目录。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>mkdir <本地挂载目录></code></pre>
<p class="p">示例:</p>
<pre class="pre codeblock"><code>mkdir /local/
mkdir /local/file</code></pre>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">将文件系统挂载到ECS云主机上。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>mount –t nfs <挂载路径> <本地挂载路径> -o rw,soft,intr,rsize=32768,wsize=32768,tcp,timeo=300</code></pre>
<p class="p">示例:</p>
<pre class="pre codeblock"><code>//挂载路径为100.68.212.1:/csp_pingan_id063402_vol1007_prd,待挂载目录为/local/file,则执行命令如下。
mount-t nfs 100.68.212.1:/csp_pingan_id063402_vol1007_prd /local/file -o rw,soft,intr,rsize=32768,wsize=32768,tcp,timeo=300
</code></pre>
<table class="table" id="MountNFS__table_cj1_5nk_3mb"><caption></caption><colgroup><col><col></colgroup><thead class="thead">
<tr class="row">
<th class="entry" id="MountNFS__table_cj1_5nk_3mb__entry__1">参数</th>
<th class="entry" id="MountNFS__table_cj1_5nk_3mb__entry__2">说明</th>
</tr>
</thead><tbody class="tbody">
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">-t nfs</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">挂载的文件系统的类型,此处为NFS。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">挂载路径</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">文件系统的挂载路径在待挂载的文件系统详情处查看。在<span class="ph uicontrol">CloudNAS卷列表</span>中,单击待挂载文件系统名称,在<span class="keyword wintitle">卷详情</span>页面中,查看<span class="ph uicontrol">挂载路径(主)</span>。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">本地挂载路径</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">云服务器上创建用于挂载NAS卷的本地路径。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">-o rw</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">用来标识设备的挂载方式:</p>
<ul class="ul" id="MountNFS__ul_dj1_5nk_3mb">
<li class="li">rw: 采用读写方式挂载。</li>
<li class="li">ro:采用只读方式挂载。</li>
</ul>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">soft</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">使用软挂载的方式挂载系统,若客户端的请求得不到回应,则重新请求并传回错误信息。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">intr</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">允许NFS中断文件操作和向调用它的程序返回值,默认不允许文件操作被中断。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">rsize</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">每次向服务器读取文件的最大字节数。</p>
<p class="p">建议值:32768</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">wsize</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">每次向服务器写入文件的最大字节数。</p>
<p class="p">建议值:32768</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">tcp</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">对文件系统的挂载使用TCP,而不是默认的UDP。</p>
</td>
</tr>
<tr class="row">
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__1 ">
<p class="p">timeo</p>
</td>
<td class="entry" headers="MountNFS__table_cj1_5nk_3mb__entry__2 ">
<p class="p">NFS客户端重传请求前的等待时间(单位为0.1秒)。建议值:300。</p>
</td>
</tr>
</tbody></table>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">执行查看已挂载的文件系统及其相关信息,验证是否挂载成功。</span>
<div class="itemgroup info">
<ul class="ul" id="MountNFS__ul_ryy_znk_3mb">
<li class="li">执行<code class="ph codeph">mount –l</code>命令查看已挂载的文件系统。</li>
<li class="li">执行<code class="ph codeph">df –h</code>查看文件系统的容量信息。</li>
</ul>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">进入本地挂载目录,并写入文件。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>//进入/local/file目录
cd /local/file
//在该目录下写入文件test.txt
touch test.txt
//查看该文件是否已经在路径下存在。
ls</code></pre>
</div>
</li></ol></section>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!