miaoyun+Rancher+K8S学习与实践


NFS搭建

<h1>一、服务端安装</h1> <h2>1. 创建存储卷目录</h2> <pre><code class="language-bash">chown -R easytong:easytong /easytong_volumes</code></pre> <h2>2. 安装NFS服务端</h2> <pre><code class="language-bash">yum -y install nfs-utils</code></pre> <p>说明:rpcbind包会自动被安装</p> <h2>3. 启动服务</h2> <p>按顺序启动rpcbind和nfs服务</p> <pre><code class="language-bash">systemctl start nfs 或 systemctl start nfs-server systemctl start rpcbind</code></pre> <h2>4. 配置NFS</h2> <h3>4.1 配置NFS</h3> <p>cat /etc/exports</p> <pre><code class="language-bash">/easytong_volumes 172.16.7.204(rw,sync,no_subtree_check,no_root_squash) /easytong_volumes 172.16.7.205(rw,sync,no_subtree_check,no_root_squash) /easytong_volumes 172.16.7.206(rw,sync,no_subtree_check,no_root_squash)</code></pre> <p>注意:NFS服务端共享的目录不能太长,否则会报错如下:</p> <pre><code class="language-bash">mount.nfs: access denied by server while mounting 192.168.30.123:/xtptdatavolumes</code></pre> <h3>4.2 使文件 /etc/exports 生效</h3> <pre><code class="language-bash">exportfs -arv</code></pre> <h2>5. 设置防火墙</h2> <pre><code class="language-bash">firewall-cmd --permanent --add-service=nfs firewall-cmd --permanent --add-service=rpc-bind firewall-cmd --permanent --add-service=mountd firewall-cmd --reload firewall-cmd --list-all #查看firewalld方向的资源</code></pre> <h2>6. 加入开机启动</h2> <pre><code class="language-bash">systemctl enable nfs</code></pre> <h2>7. 查看服务端已共享的目录</h2> <p>以使用 showmount 命令来查看服务端(本机)是否可连接</p> <pre><code class="language-bash">showmount -e localhost</code></pre> <h1>二、nfs 客户端配置</h1> <h2>1. nfs 客户端安装</h2> <p>在安装nfs-utils的过程中,也会自动地将rpcbind安装上,无需手工开启nfs-utils服务。</p> <pre><code class="language-bash">yum -y install nfs-utils</code></pre> <h2>2. 挂载 nfs 文件系统</h2> <h3>2.1 在客户端查看 nfs 服务器已共享目录</h3> <pre><code class="language-bash">showmount -e 172.16.7.209</code></pre> <h3>2.2 k8s client 建立挂载目录,执行挂载命令</h3> <pre><code class="language-bash">mkdir -p /easytong_volumes chown -R easytong:easytong /easytong_volumes mount -t nfs 172.16.7.209:/easytong_volumes /easytong_volumes -o nolock,nfsvers=3,vers=3</code></pre> <h2>3. 开机自动挂载</h2> <p>如果按本文上面的部分配置好,NFS即部署好了,但是如果你重启客户端系统,发现不能随机器一起挂载,需要再次手动操作挂载,这样操作比较麻烦,因此我们需要设置开机自动挂载。我们不要把挂载项写到/etc/fstab文件中,因为开机时先挂载本机磁盘再启动网络,而NFS是需要网络启动后才能挂载的,所以我们把挂载命令写入到/etc/rc.d/rc.local文件中即可。</p> <h3>3.1 在客户端添加</h3> <pre><code class="language-bash">echo "mount -t nfs 172.16.7.209:/easytong_volumes /easytong_volumes -o nolock,nfsvers=3,vers=3" &gt;&gt; /etc/rc.d/rc.local</code></pre> <h3>3.2 客户端存储卷授权</h3> <p>如果不修改挂载到客户端存储卷的属主,只修改nfs服务器上存储卷属主,客户端的存储卷目录是1000:1000,则在部署应用时会报错,所以,登录每台计算节点,修改每个计算节点的存储卷属主,命令如下: 在秒云主机、K8S主机上分别执行</p> <pre><code class="language-bash">chown -R easytong:easytong /easytong_volumes</code></pre> <h3>3.3 rc.local 授可执行权限</h3> <pre><code class="language-bash">chmod +x /etc/rc.d/rc.local</code></pre> <p>保存并重启机器验证。</p> <p>下一篇:NFS高可用 <a href="https://blog.csdn.net/tigger2009/article/details/106388284/">https://blog.csdn.net/tigger2009/article/details/106388284/</a> <a href="https://blog.51cto.com/13447608/2405717">https://blog.51cto.com/13447608/2405717</a> <a href="https://www.cnblogs.com/chengxu715/p/11987023.html">https://www.cnblogs.com/chengxu715/p/11987023.html</a></p>

页面列表

ITEM_HTML