知识库

标准化实施手册及常见错误


磁盘共享-NFS共享文件挂载

<p>[TOC]</p> <h2>实现多台不同类型服务器之间文件共享实现多台不同类型服务器之间文件共享</h2> <p>文档编写目的:   本文档适用于linux服务器与linux服务器之间、linux服务器与windows服务器之间,通过nfs服务挂载实现文件共享,解决不同服务器下应用系统之间附件共享问题。</p> <h3>[nfs离线包下载](<a href="http://101.69.243.254:5010/files/%E5%AE%9E%E6%96%BD%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85%E5%8C%85/nfs/">http://101.69.243.254:5010/files/%E5%AE%9E%E6%96%BD%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85%E5%8C%85/nfs/</a> &quot;nfs离线包下载&quot;)</h3> <h2>一、搭建nfs服务端</h2> <p><strong>服务端(192.168.5.181):</strong></p> <h3>1、查看是否安装</h3> <p><code>rpm -qa |grep nfs</code> <code>rpm -qa |grep rpcbind</code> 如果是Unbantu系统,则将rpm -qa替换成 dpkg -l</p> <h3>2、配置DNS(可以访问互联网的前提下,实现网络源配置在线安装软件包和依赖)</h3> <p><code>vi /etc/resolv.conf</code> 添加下列dns <code>nameserver 114.114.114.114</code></p> <h3>3、安装nfs服务模块</h3> <p>如果是centos系统就执行: <code>yum -y install nfs-utils rpcbind</code> 如果是Unbantu系统就执行: <code>apt -y install nfs-kernel-server</code></p> <h3>4、编辑参数文件</h3> <p><code>vim /etc/exports</code> 末行加入以下内容 <code>/risen/data 192.168.40.48(rw,sync,no_root_squash,no_subtree_check)</code> <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/1e7ebb68a347935528087b0fd33f61e9" alt="" /> 编辑完重载exports文件 <code>exportfs -a</code> 其中: /risen/data 表示要共享的目录;☆表示所有的网段,也可指定客户端ip访问,即将☆替换成客户端ip。 指定多个客户端的话,可以参考如下配置 <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/a4a87a244002abc87f3fe56b608db853" alt="" /></p> <h3>5、共享目录授权</h3> <p><code>chmod -R 755 /risen/data</code></p> <h3>6、重启nfs服务</h3> <p><code>systemctl restart nfs</code> <code>systemctl restart rpcbind</code></p> <h3>7、设置开机自启</h3> <p><code>systemctl enable nfs-kernel-server</code> <code>systemctl enable rpcbind</code></p> <h3>8、开启防火墙,添加端口策略</h3> <p>启动防火墙 <code>systemctl start firewalld.service</code> 防火墙开机自启 <code>systemctl enable firewalld.service</code> 添加端口策略 <code>firewall-cmd --permanent --zone=public --add-port=111/tcp</code> <code>firewall-cmd --permanent --zone=public --add-port=2049/tcp</code> <code>firewall-cmd --permanent --zone=public --add-port=20048/tcp</code></p> <p><code>firewall-cmd --permanent --zone=public --add-port=111/udp</code> <code>firewall-cmd --permanent --zone=public --add-port=4046/udp</code> 重加载防火墙 <code>firewall-cmd --reload</code> 查看规则 <code>firewall-cmd --list-all</code></p> <p><strong>至此nfs服务端配置完毕</strong></p> <h2>二、搭建nfs客户端</h2> <p><strong>客户端(192.168.40.48):</strong></p> <h3>1、安装NFS服务</h3> <p>如果是centos系统: <code>yum -y install nfs-utils</code> 如果是Unbantu系统: <code>apt -y install nfs-common</code></p> <h3>2、新建挂载点</h3> <p><code>mkdir -p /risen/data</code></p> <h3>3、检查客户端和服务端网络是否连通</h3> <p><code>ping 192.168.5.181</code> <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/7be546219ef67b7f6f9292cda098ffa6" alt="" /></p> <h3>4、查看服务端的共享目录</h3> <p><code>showmount -e +ip</code>(查看服务端提供的共享目录) <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/565d1d8ab21a8800c77fb8dc7390d7e4" alt="" /></p> <h3>5、添加开机挂载</h3> <p><code>vim /etc/fstab</code></p> <p><code>192.168.5.181:/risen/data /risen/data nfs defaults 0 0</code> <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/0bf469d3100a1abb2f63bb2a33ba72da" alt="" /></p> <h3>6、刷新挂载<code>mount -a</code></h3> <p><code>mount | grep ip</code> #检查是否已经成功挂载,查看NFS挂载版本vers=版本号 <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/1dae5e5bf54a9c1b51399244f7a32a88" alt="" /> <code>df -h</code>查看挂载大小(如果所示代表成功,进入挂载文件/risen/data查看内容) <img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/ab15e9bbc3a1b5c64a1fb51e3046c4b5" alt="" /></p>

页面列表

ITEM_HTML