{"id":471,"date":"2024-02-18T17:17:09","date_gmt":"2024-02-18T15:17:09","guid":{"rendered":"https:\/\/it4home.dk\/?p=471"},"modified":"2024-02-18T17:18:40","modified_gmt":"2024-02-18T15:18:40","slug":"automating-nfs-mounts-with-autofs-on-raspberry-pi-for-docker-swarm","status":"publish","type":"post","link":"https:\/\/it4home.dk\/index.php\/2024\/02\/18\/automating-nfs-mounts-with-autofs-on-raspberry-pi-for-docker-swarm\/","title":{"rendered":"Automating NFS Mounts with Autofs on Raspberry Pi for Docker Swarm"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-post pdfprnt-top-right\"><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/471?print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\" ><\/a><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/471?print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\" ><img decoding=\"async\" src=\"https:\/\/it4home.dk\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">When managing a Docker Swarm on a fleet of Raspberry Pis, ensuring consistent and reliable access to shared storage across your nodes is crucial. This is where Autofs comes into play. Autofs is a utility that automatically mounts network file systems when they&#8217;re accessed, making it an ideal solution for managing persistent storage in a Docker Swarm environment. In this blog post, we&#8217;ll walk through the process of installing and configuring Autofs on a Raspberry Pi to use with an NFS server for shared storage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Setting Up the NFS Server<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before configuring Autofs, you need an NFS server that hosts your shared storage. If you haven&#8217;t already set up an NFS server, you can do so by installing the <code>nfs-kernel-server<\/code> package on your Raspberry Pi designated as the NFS server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install nfs-kernel-server -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, configure the NFS export by editing the <code>\/etc\/exports<\/code> file and adding the following line to share the <code>\/data<\/code> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/data 192.168.0.0\/24(rw,sync,no_subtree_check,no_root_squash)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Restart the NFS server to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/nfs-kernel-server restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the export with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo exportfs<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Installing Autofs on Client Raspberry Pis<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">On each Raspberry Pi client that needs access to the NFS share, install Autofs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update -y\nsudo apt install autofs -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reboot the Raspberry Pi to ensure all updates are applied:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo reboot<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Configuring Autofs<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installing Autofs, you&#8217;ll need to configure it to automatically mount the NFS share. Edit the <code>\/etc\/auto.master<\/code> file and add a line for the mount point:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/-    \/etc\/auto.data --timeout=60<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create and edit <code>\/etc\/auto.data<\/code> to specify the NFS share details:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/data -fstype=nfs,rw 192.168.0.220:\/data<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration tells Autofs to mount the NFS share located at <code>192.168.0.220:\/data<\/code> to <code>\/data<\/code> on the client Raspberry Pi.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Starting and Testing Autofs<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Enable and start the Autofs service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable autofs\nsudo systemctl start autofs<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the status to ensure it&#8217;s running without issues:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status autofs<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To test, simply access the <code>\/data<\/code> directory on the client Raspberry Pi. Autofs should automatically mount the NFS share.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/data\nls<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you see the contents of your NFS share, the setup is successful. Autofs will now manage the mount points automatically, ensuring your Docker Swarm has seamless access to shared storage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">By leveraging Autofs with NFS on Raspberry Pi, you can streamline the management of shared volumes in your Docker Swarm, enhancing both reliability and efficiency. This setup minimizes the manual intervention required for mounting shared storage, making your Swarm more resilient to reboots and network changes. Happy Swarming!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When managing a Docker Swarm on a fleet of Raspberry Pis, ensuring consistent and reliable access to shared storage across your nodes is crucial. This is where Autofs comes into play. Autofs is a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2,7],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","category-raspberry"],"_links":{"self":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":1,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/471\/revisions\/472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media\/473"}],"wp:attachment":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}