{"id":174,"date":"2017-02-28T10:48:51","date_gmt":"2017-02-28T09:48:51","guid":{"rendered":"http:\/\/owncloud.gonscak.sk\/?p=174"},"modified":"2022-08-11T09:47:52","modified_gmt":"2022-08-11T07:47:52","slug":"how-to-set-up-nfs-server-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=174","title":{"rendered":"How to set up nfs server on centos 7\/8, and display content via httpd"},"content":{"rendered":"<p>Sometimes I need to use fast, simple and no-password storage over the network in bash, or an ISO storage for Xenserver. So nfs sharing is the best way for this.\u00a0 I have a linux machine with centos 7 and available storage of 1,5TB disk. So, prepare the disk:<\/p>\n<pre>fdisk -l \/dev\/xvdb\n&gt; n (new partition), and use default options. The use -t (change partition ID) and change it to 83 (Linux). The use -w (write)\nreboot\nmkfs.xfs \/dev\/xvdb1\nmkdir \/mnt\/nfs\nmount \/dev\/xvdb1 \/mnt\/nfs\/<\/pre>\n<p>If everything is OK, edit \/etc\/fstab to automount this partition to ours folder, and add this line:<\/p>\n<pre>\/dev\/xvdb1 \/mnt\/nfs xfs defaults,nosuid,noatime,nodiratime 0 0<\/pre>\n<p>The install package nfs-utils, for nfs server:<\/p>\n<pre>yum -y install nfs-utils<\/pre>\n<p>And allow nfs service in firewalld:<\/p>\n<pre>firewall-cmd --permanent --zone=public --add-service=nfs\nfirewall-cmd --reload\n#if sometimes on clients don't working showmount, and it create an error:\nshowmount -e 11.22.33.44\nrpc mount export: RPC: Unable to receive; errno = No route to host\n#we must add another ports to firewall:<br \/>firewall-cmd --permanent --zone=public --add-service=rpc-bind\nfirewall-cmd --permanent --zone=public --add-service=mountd<br \/>firewall-cmd --reload<\/pre>\n<p>And uncoment this lines in: \/etc\/sysconfig\/nfs <em>(this is no applicable at Centos 8)<\/em><\/p>\n<pre>MOUNTD_PORT=892\nSTATD_PORT=662<\/pre>\n<p>Now enable nfs-server to run after poweron server and start it:<\/p>\n<pre>systemctl enable nfs-server.service\nsystemctl start nfs-server.service<\/pre>\n<p>Now we must prepare this folder with this permissions, for read and write for everybody: <em>(this is no applicable at Centos 8)<\/em><\/p>\n<pre>chown nfsnobody:nfsnobody \/mnt\/nfs\/ -R\nchmod 755 \/mnt\/nfs\/<\/pre>\n<p>And edit file \/etc\/exports for this folder to by allowed for everybody in network:<\/p>\n<pre>\/mnt\/nfs *(rw,sync,no_root_squash,no_all_squash)<\/pre>\n<p>And apply this change:<\/p>\n<pre>exportfs -arv<\/pre>\n<p>We can see our settings with command &#8220;exportfs&#8221;:<\/p>\n<pre>\/mnt\/nfs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;world&gt;<\/pre>\n<p>And from other linux machine, we can mount this folder:<\/p>\n<pre>mount 11.22.33.44:\/mnt\/nfs \/mnt\/nfs\/\n#see this disk report space\ndf -h\nFilesystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Size\u00a0 Used Avail Use% Mounted on\n11.22.33.44:\/mnt\/nfs\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.5T\u00a0 200G\u00a0 1.3T\u00a0 14% \/mnt\/nfs<\/pre>\n<p>And we can test it with 1GB file:<\/p>\n<pre>dd if=\/dev\/zero of=\/mnt\/nfs\/1gb bs=1M count=1000\n1048576000 bytes (1.0 GB) copied, 16.4533 s, 63.7 MB\/s\n...\n...\nls -lah \/mnt\/nfs\/\ndrwxr-xr-x. 18 nfsnobody nfsnobody\u00a0 4.0K Feb 28 10:47 .\ndrwxr-xr-x.\u00a0 3 root\u00a0\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.0K Feb 28 10:24 ..\n-rw-r--r--.\u00a0 1 root\u00a0\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0\u00a0 1000M Feb 28 10:47 1gb\n<\/pre>\n<p>Now we can continue with installing apache web server:<\/p>\n<pre>yum install httpd -y<br \/>systemctl enable httpd.service<br \/>firewall-cmd --add-service=http --permanent<br \/>firewall-cmd --reload<\/pre>\n<p>Now, we create an configuration file for one folder from nfs storage:<\/p>\n<pre>vim \/etc\/httpd\/conf.d\/media.exmaple.com.conf<\/pre>\n<pre>&lt;VirtualHost *:80&gt;<br \/>    ServerAdmin user@example.com<br \/>    DocumentRoot \"\/mnt\/nfs\/kadeco\/installs\"<br \/>    ServerName installs.example.com<br \/>&lt;Directory \"\/mnt\/nfs\/kadeco\/installs\"&gt;<br \/>    AllowOverride All<br \/>    Require all granted<br \/>    Options Indexes <br \/>&lt;\/Directory&gt;<br \/>ErrorLog \/var\/log\/httpd\/installs.example.com-error_log<br \/>CustomLog \/var\/log\/httpd\/installs.example.com-access_log common<br \/>&lt;\/VirtualHost&gt;<\/pre>\n<p>But we cannot serve this directory:<\/p>\n<pre>AH01276: Cannot serve directory \/mnt\/nfs\/kadeco\/installs: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive<\/pre>\n<p>So, we install som softvare to modify file and folders context with selinux:<\/p>\n<pre>yum install setroubleshoot<\/pre>\n<p>And change context to this folder:<\/p>\n<pre>semanage fcontext -a -t httpd_sys_content_t \"\/mnt\/nfs\/kadeco\/installs(\/.*)?\"<br \/>restorecon -R \/mnt\/nfs\/kadeco\/installs<br \/>rm \/etc\/httpd\/conf.d\/welcome.conf<br \/>systemctl restart httpd.service<\/pre>\n<p>Have a fun \ud83d\ude42<\/p>\n\n\n<p><\/p>\n ","protected":false},"excerpt":{"rendered":"<p>Sometimes I need to use fast, simple and no-password storage over the network in bash, or an ISO storage for Xenserver. So nfs sharing is the best way for this.\u00a0 I have a linux machine with centos 7 and available storage of 1,5TB disk. So, prepare the disk: fdisk -l \/dev\/xvdb &gt; n (new partition), &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=174\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to set up nfs server on centos 7\/8, and display content via httpd<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3,116,33,34,35],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-centos","tag-centos","tag-centos-8","tag-exports","tag-nfs","tag-server"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":7,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":916,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/916"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}