<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EFS &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/efs/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sun, 01 Nov 2020 13:13:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>AWS, WordPress: Deploy WordPress on AWS Linux using Terraform, EC2, RDS and EFS</title>
		<link>https://blog.andreev.it/2018/08/136-terraform-deploy-wordpress-on-aws-linux-using-terraform-ec2-rds-and-efs/</link>
					<comments>https://blog.andreev.it/2018/08/136-terraform-deploy-wordpress-on-aws-linux-using-terraform-ec2-rds-and-efs/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sat, 11 Aug 2018 16:18:35 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[EFS]]></category>
		<category><![CDATA[RDS]]></category>
		<category><![CDATA[Terraform]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=4060</guid>

					<description><![CDATA[I&#8217;ve started playing with Terraform in order to automate some server builds and found&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I&#8217;ve started playing with Terraform in order to automate some server builds and found it to be very useful. It has its own quirks, strange JSON-like syntax and it takes some time to get fully on-board. I&#8217;ve noticed several bugs but there is always a workaround if you google it. At the time of this writing, Terraform is version 0.11.7 so it&#8217;s still some kind of beta. The team behind it are making a lot of changes so expect some things to break. The book that I was using to study was already out of date and some commands were deprecated.<br />
I won&#8217;t explain how to install it and configure it. It&#8217;s very <a href="https://www.terraform.io/intro/getting-started/install.html" rel="noopener noreferrer" target="_blank">easy </a>to get it up and running. In order for the following script to work, make sure that you have Terraform and <a href="https://blog.andreev.it/?p=1905" rel="noopener noreferrer" target="_blank">AWS CLI</a> installed and configured.<br />
Create a separate folder/directory for this project and create three files. The first file is <strong>vars.tf</strong>. That&#8217;s where we define the variables. </p>
<pre class="brush: bash; title: ; notranslate">
variable &quot;region&quot; {
	description = &quot;The region for the deployment&quot;
	default = &quot;us-west-2&quot;
}
	
variable &quot;vpc_id&quot; {
	description = &quot;The VPC ID where WordPress will reside&quot;
	default = &quot;vpc-a36ga9zd&quot;
}

variable &quot;ami_id&quot; {
	description = &quot;The AMI ID for AWS Linux 2 in us-west-2. In other regions, the ID is different&quot;
	default = &quot;ami-a9d09ed1&quot;

}

variable &quot;instance_type&quot; {
	description = &quot;AWS Instance type to be used for the WordPress instance&quot;
	default = &quot;t2.small&quot;
}

variable &quot;volume_size&quot; {
	description = &quot;EBS volume size in GBs for the instance&quot;
	default = 8
}

variable &quot;key_name&quot; {
	description = &quot;The key pair that will be used to log to the server using SSH&quot;
	default = &quot;MyKeyPair-Oregon&quot;
}

variable &quot;ssh_port&quot; {
	description = &quot;The SSH port for the server&quot;
	default = 22
}

variable &quot;http_port&quot; {
	description = &quot;The HTTP port for the server&quot;
	default = 80
}

variable &quot;mysql_port&quot; {
	description = &quot;The MySQL port for the database&quot;
	default = 3306
}

variable &quot;nfs_port&quot; {
	description = &quot;The NFS port for the shared filesystem&quot;
	default = 2049
}

variable &quot;allocated_storage&quot; {
	description = &quot;The size in GBs of the SQL database&quot;
	default = 10
}

variable &quot;instance_class&quot; {
	description = &quot;The size/type of the SQL instance&quot;
	default = &quot;db.t2.micro&quot;
}

variable &quot;db_admin&quot; {
	description = &quot;The dbadmin username&quot;
	default = &quot;dbadmin&quot;
}

variable &quot;db_password&quot; {
	description = &quot;The dbadmin password&quot;
	default = &quot;SuperSecret&quot;
}

variable &quot;db_name&quot; {
	description = &quot;The database name&quot;
	default = &quot;dbwordpress&quot;
}
</pre>
<p>Make sure you specify your region, your VPC ID and the key name. That&#8217;s how you will login to your instance. You can find your key name if you go to <strong>Key Pairs</strong> menu in AWS console.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/08/P113-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/08/P113-01.png" alt="" width="544" height="227" class="aligncenter size-full wp-image-8274" /></a><br />
I tried to test the same setup on CentOS 7.x but for some reason the user data boot script was never executed, thus making this script unusable. It might work with Ubuntu or some other flavor of Linux, if you can make the user data script execute on boot and make some modifications, e.g. apt-get instead of yum etc&#8230;<br />
The next file is <strong>outputs.tf</strong>. These are the variables that are needed at the end of the run of the script. BTW, the script takes around 4 minutes to complete. </p>
<pre class="brush: bash; title: ; notranslate">
output &quot;efs_dns_name&quot; {
	value = &quot;${aws_efs_file_system.efsWordPress.dns_name}&quot;
}

output &quot;ip_address&quot; {
    value = &quot;${aws_instance.wordpress.public_ip}&quot;
}

output &quot;sql_hostname&quot; {
    value = &quot;${aws_db_instance.dbWordPress.address}&quot;
}
</pre>
<p>At the end of the script, we&#8217;ll get the DNS name of the EFS filesystem, the external IP address of the instance and the MySQL hostname. We&#8217;ll need the last two.<br />
And finally, the main script (<strong>main.tf</strong>) is where all the resources that are needed are specified.</p>
<pre class="brush: bash; highlight: [13,61,62,63,64,65,66,68,83,87]; title: ; notranslate">
provider &quot;aws&quot; {
	region = &quot;${var.region}&quot;
}

resource &quot;aws_security_group&quot; &quot;sgWordPress&quot; {
	name = &quot;sgWordPress&quot;
	vpc_id      = &quot;${var.vpc_id}&quot;

	ingress {
		from_port = &quot;${var.ssh_port}&quot;
		to_port = &quot;${var.ssh_port}&quot;
		protocol = &quot;tcp&quot;
		cidr_blocks =&#x5B;&quot;0.0.0.0/0&quot;]
	}

	ingress {
		from_port = &quot;${var.http_port}&quot;
		to_port = &quot;${var.http_port}&quot;
		protocol = &quot;tcp&quot;
		cidr_blocks = &#x5B;&quot;0.0.0.0/0&quot;]
	}

	ingress {
		from_port = &quot;${var.mysql_port}&quot;
		to_port = &quot;${var.mysql_port}&quot;
		protocol = &quot;tcp&quot;
		self = true
	}

	ingress {
		from_port = &quot;${var.nfs_port}&quot;
		to_port = &quot;${var.nfs_port}&quot;
		protocol = &quot;tcp&quot;
		self = true
	}

	egress {
		from_port = 0
		to_port = 0
		protocol = &quot;-1&quot;
		cidr_blocks = &#x5B;&quot;0.0.0.0/0&quot;]
	}

	tags {
		Name = &quot;sgWordPress&quot;
	}
}

resource &quot;aws_efs_file_system&quot; &quot;efsWordPress&quot; {
  creation_token = &quot;EFS for WordPress&quot;

  tags {
    Name = &quot;EFS for WordPress&quot;
  }
}

data &quot;aws_subnet_ids&quot; &quot;suballIDs&quot; {
	vpc_id = &quot;${var.vpc_id}&quot;
}

resource &quot;aws_efs_mount_target&quot; &quot;mtWordPress&quot; {
  count = &quot;${length(data.aws_subnet_ids.suballIDs.ids)}&quot;
  file_system_id = &quot;${aws_efs_file_system.efsWordPress.id}&quot;
  subnet_id      = &quot;${element(data.aws_subnet_ids.suballIDs.ids, count.index)}&quot;
  security_groups = &#x5B;&quot;${aws_security_group.sgWordPress.id}&quot;]
}

resource &quot;aws_instance&quot; &quot;wordpress&quot; {
	ami = &quot;${var.ami_id}&quot;
	instance_type = &quot;${var.instance_type}&quot;
	vpc_security_group_ids = &#x5B;&quot;${aws_security_group.sgWordPress.id}&quot;]
	key_name = &quot;${var.key_name}&quot; 
	ebs_block_device {
		device_name = &quot;/dev/sdb&quot;
    	volume_size = &quot;${var.volume_size}&quot;
    	delete_on_termination = &quot;true&quot;
  	}

	tags {
		Name = &quot;WordPress Server&quot;
	}

	user_data = &lt;&lt;EOF
		#!/bin/bash
		echo &quot;${aws_efs_file_system.efsWordPress.dns_name}:/ /var/www/html nfs defaults,vers=4.1 0 0&quot; &gt;&gt; /etc/fstab
		yum install -y php php-dom php-gd php-mysql
		for z in {0..120}; do
			echo -n .
			host &quot;${aws_efs_file_system.efsWordPress.dns_name}&quot; &amp;&amp; break
		  	sleep 1
		done
		cd /tmp
		wget https://www.wordpress.org/latest.tar.gz
		mount -a
		tar xzvf /tmp/latest.tar.gz --strip 1 -C /var/www/html
		rm /tmp/latest.tar.gz
		chown -R apache:apache /var/www/html
		systemctl enable httpd
		sed -i 's/#ServerName www.example.com:80/ServerName www.myblog.com:80/' /etc/httpd/conf/httpd.conf
		sed -i 's/ServerAdmin root@localhost/ServerAdmin admin@myblog.com/' /etc/httpd/conf/httpd.conf
		#setsebool -P httpd_can_network_connect 1
		#setsebool -P httpd_can_network_connect_db 1
		systemctl start httpd
		#firewall-cmd --zone=public --permanent --add-service=http
		#firewall-cmd --reload
		#iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
		#iptables -A OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
	EOF

}

resource &quot;aws_db_instance&quot; &quot;dbWordPress&quot; {
	identifier = &quot;dbwordpress&quot;
	engine = &quot;mysql&quot;
	engine_version = &quot;5.7&quot;
	allocated_storage = &quot;${var.allocated_storage}&quot;
	instance_class = &quot;${var.instance_class}&quot;
	vpc_security_group_ids = &#x5B;&quot;${aws_security_group.sgWordPress.id}&quot;]
	name = &quot;${var.db_name}&quot;
	username = &quot;${var.db_admin}&quot;
	password = &quot;${var.db_password}&quot;
	parameter_group_name = &quot;default.mysql5.7&quot;
	skip_final_snapshot = true
	tags {
		Name = &quot;WordPress DB&quot;
	}
}
</pre>
<p>The script starts with the name of the provided that will be used (AWS), then a security group is being defined with ports 22 and 80 open to the world. Opening port 22 to the world is not a good idea, so you can restrict the access. In line 13, you can change the subnets allowed, e.g. instead of [&#8220;0.0.0.0/0&#8221;], you can restrict the SSH to a couple of IPs, e.g. [&#8220;1.2.3.4/32&#8243;,&#8221;12.13.14.15/32&#8221;]. Then, we define the ports for NFS and MySQL. If you can see these ports are open to themselves only. That means that only the resources having assigned that security group can talk between themselves on these two ports. And finally, we allow all outgoing traffic.<br />
Further, we have an EFS file system created and mount targets. The mounts targets define in what availability zones the EFS system will be available. Since each region has different numbers of availability zones, we don&#8217;t know that number, so we have to enumerate the AZs for each region. If you look at lines 61 to 66 you&#8217;ll see how we do that. It&#8217;s pretty much a <a href="https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9" rel="noopener noreferrer" target="_blank">for..next loop</a> in Terraform.<br />
At line 68, we have our main resource defined, the instance. You&#8217;ll see that each resource has a lot of input parameters. Some of these are mandatory and some are optional. For each resource, you can find a detailed explanation on the Terraform site. For example, if you google <a href="https://www.google.com/search?q=terraform+aws_instance" rel="noopener noreferrer" target="_blank">&#8220;terraform aws_instance&#8221;</a> the first link that shows up on terraform.io website will be about that.<br />
At line 83 the custom script begins. It will add the EFS mount point to <strong>/etc/fstab</strong> so the NFS system is mounted on each reboot. At line 87 there is a short delay until EFS filesystem becomes available. Because the resources are created in parallel, it takes up to 90 seconds for the EFS DNS name to get propagated. If we don&#8217;t have the delay, the instance will boot up, try to mount the EFS system and fail, because the DNS mount point won&#8217;t be accessible. AWS Linux 2 comes with SELinux disabled and no firewalls, but if you have some other instance, you can uncomment the lines at the end of the user data script. Otherwise, SELinux will prevent Apache and MySQL to work with PHP. Lines 106 and 107 are if you use <strong>iptables </strong>instead of <strong>firewalld</strong>. Tailor to your needs. Finally, at line 112, the MySQL DB is defined.<br />
Once you have all these three files <strong>(vars.tf, outputs.tf and main.tf)</strong> modified and saved in the same folder/directory, you can star the provisioning. First, initialize the script so Terraform can download the plugin for AWS.</p>
<pre class="brush: bash; title: ; notranslate">
terraform init
</pre>
<p>Then, check if everything is OK with the script.</p>
<pre class="brush: bash; title: ; notranslate">
terraform plan
</pre>
<p>And finally, execute the script.</p>
<pre class="brush: bash; title: ; notranslate">
terraform apply
</pre>
<p>It will prompt you to say &#8220;<strong>yes</strong>&#8221; and after the script completes, you&#8217;ll have something like this at the end.</p>
<pre class="brush: bash; title: ; notranslate">
Apply complete! Resources: 7 added, 0 changed, 0 destroyed.

Outputs:

efs_dns_name = fs-64307acd.efs.us-west-2.amazonaws.com
ip_address = 34.220.235.222
sql_hostname = dbwordpress.cbh9gck8kp6s.us-west-2.rds.amazonaws.com
</pre>
<p>Go to <strong>http://your_ip</strong> and you should have the welcome WordPress screen. Use the database name, username and the password for the database defined in <strong>vars.tf</strong> (dbwordpress, dbadmin, SuperSecret) and for the hostname use the SQL DB output variable (<strong>sql_hostname</strong>) above.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/08/P113-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/08/P113-02.png" alt="" width="732" height="409" class="aligncenter size-full wp-image-8275" /></a><br />
And that&#8217;s it! You have your WordPress up and running on RDS and EFS filesystem without even logging to AWS console or your Linux instance.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/08/P113-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/08/P113-03.png" alt="" width="931" height="559" class="aligncenter size-full wp-image-8276" /></a><br />
Once you are done playing you can destroy all of the resources with one command.</p>
<pre class="brush: bash; title: ; notranslate">
terraform destroy
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/08/136-terraform-deploy-wordpress-on-aws-linux-using-terraform-ec2-rds-and-efs/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AWS: Elastic File System (EFS) on FreeBSD/RHEL/CentOS/AWS Linux</title>
		<link>https://blog.andreev.it/2016/09/94-amazon-aws-elastic-file-system-efs-on-freebsdrhelcentosaws-linux/</link>
					<comments>https://blog.andreev.it/2016/09/94-amazon-aws-elastic-file-system-efs-on-freebsdrhelcentosaws-linux/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Thu, 01 Sep 2016 19:11:26 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[EFS]]></category>
		<category><![CDATA[freebsd]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=2688</guid>

					<description><![CDATA[Recently I was playing with the new Elastic File System (EFS) that AWS provides.&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Recently I was playing with the new Elastic File System (EFS) that AWS provides. It&#8217;s an NFS v4  implementation and my goal was to use it as a shared repository between two different systems. The access is based on security groups and by default when you create a new file system, the mount targets are created in all availability zones for that region.</p>
<h1>Create NFS security group</h1>
<p>NFS access is based on security groups. So, if you have an instance that needs access to an NFS target, you have to make sure that the instance belongs to the same security group that NFS target belongs. We&#8217;ll create a security group that grants access to TCP port 2049. This is the port that NFS uses.<br />
Go to the main AWS menu, click on <strong>VPC</strong>, then <strong>Security Groups</strong> and click on <strong>Create Security Group</strong>.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-01.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-01.jpg" alt="" width="653" height="265" class="aligncenter size-full wp-image-7550" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-01.jpg 653w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-01-300x122.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-01-585x237.jpg 585w" sizes="(max-width: 653px) 100vw, 653px" /></a><br />
Once created, click on the <strong>Inbound Rules</strong> tab and then click <strong>Edit</strong>.<br />
From the first drop down box on the left choose <strong>NFS (2049)</strong>, for the source choose the same <strong>Group ID</strong> as the group itself and click <strong>Save</strong>. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-02.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-02.jpg" alt="" width="704" height="230" class="aligncenter size-full wp-image-7551" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-02.jpg 704w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-02-300x98.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-02-585x191.jpg 585w" sizes="(max-width: 704px) 100vw, 704px" /></a></p>
<h1>Create EFS</h1>
<p>From the main AWS menu, click on <strong>Elastic File System</strong>.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-03.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-03.jpg" alt="" width="586" height="511" class="aligncenter size-full wp-image-7552" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-03.jpg 586w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-03-300x262.jpg 300w" sizes="(max-width: 586px) 100vw, 586px" /></a><br />
Then, click on <strong>Create file system</strong>. This is how my default looks like.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-04.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-04.jpg" alt="" width="932" height="652" class="aligncenter size-full wp-image-7553" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-04.jpg 932w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-04-300x210.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-04-768x537.jpg 768w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-04-585x409.jpg 585w" sizes="(max-width: 932px) 100vw, 932px" /></a><br />
At this point, you can change the availability zone for the mount target. If you plan to launch instances in different zones, then go with the defaults. Remove the default security group on the right and add the security group that we just created for all of the zones, so the right part looks like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-05.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-05.jpg" alt="" width="289" height="458" class="aligncenter size-full wp-image-7554" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-05.jpg 289w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-05-189x300.jpg 189w" sizes="(max-width: 289px) 100vw, 289px" /></a></p>
<p>Click on <strong>Next Step</strong> and fill out the optional settings for the tags and the performance. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-06.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-06.jpg" alt="" width="934" height="568" class="aligncenter size-full wp-image-7555" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-06.jpg 934w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-06-300x182.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-06-768x467.jpg 768w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-06-585x356.jpg 585w" sizes="(max-width: 934px) 100vw, 934px" /></a><br />
Click on <strong>Next Step</strong> again, review and click <strong>Create File System</strong>.<br />
This is what you will have once you create your file system.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-07.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-07.jpg" alt="" width="1069" height="340" class="aligncenter size-full wp-image-7556" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-07.jpg 1069w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-07-300x95.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-07-1024x326.jpg 1024w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-07-768x244.jpg 768w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-07-585x186.jpg 585w" sizes="(max-width: 1069px) 100vw, 1069px" /></a><br />
If you click on <strong>DNS names</strong>, you&#8217;ll see your server names (for the mount target).</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-08.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-08.jpg" alt="" width="639" height="510" class="aligncenter size-full wp-image-7557" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-08.jpg 639w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-08-300x239.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-08-585x467.jpg 585w" sizes="(max-width: 639px) 100vw, 639px" /></a><br />
And that&#8217;s all what we need.  If you click on <strong>EC2 mount instruction</strong>, you&#8217;ll get a quick guide on how to mount your new file system.</p>
<h1>FreeBSD</h1>
<p>For FreeBSD, we&#8217;ll have to put this one line in <strong>/etc/rc.conf</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
nfs_client_enable=&quot;YES&quot;
</pre>
<p>and then start the nfs client with</p>
<pre class="brush: bash; title: ; notranslate">
service nfsclient start
</pre>
<p>In order to mount the NFS target, we&#8217;ll need to know what zone our instance belongs to. As you can remember from the above, each zone has a different DNS server name for the target. So, if you need your zone you can see that from the EC2 menu or if you have <strong>curl </strong>installed, you can browse your instance metadata.</p>
<pre class="brush: bash; title: ; notranslate">
curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/
</pre>
<p>Install curl with <strong>pkg install curl</strong> if you don&#8217;t have it.<br />
We also need a mount point. In my case I&#8217;ll mount my new file system under <strong>/root/efs</strong>. I don&#8217;t have the directory created, so I&#8217;ll do.</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /root/efs
</pre>
<p>The easiest way to mount the target without looking at the zone where the instance belongs is to run this one liner.</p>
<pre class="brush: bash; title: ; notranslate">
mount -t nfs -o nfsv4 `curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`.fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs
</pre>
<p>This means mount a new file system of type NFS, make sure it&#8217;s NFSv4 (-o), get the zone with curl and append it to the DNS server name of the NFS server and mount it under <strong>/root/efs</strong>.<br />
If you want to unmount the filesystem, do</p>
<pre class="brush: bash; title: ; notranslate">
umount /root/efs
</pre>
<p>For some reason, under FreeBSD I was getting RPC time out errors, so if you want to remove the mount instantly, force it.</p>
<pre class="brush: bash; title: ; notranslate">
umount -f /root/efs
</pre>
<p>Now, if you reboot your server the mount points are gone, so you&#8217;ll have to make sure that on each reboot your NFS mounts on. Edit <strong>/etc/fstab</strong> and add this line. </p>
<pre class="brush: bash; title: ; notranslate">
us-east-1d.fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs nfs rw,nfsv4 0 0
</pre>
<p>What if you have an image in a load balancing scenario and you have it configured to boot up in a random zone. The above <strong>/etc/fstab</strong> entry won&#8217;t work and you can&#8217;t query that with curl in <strong>fstab</strong>. It&#8217;s a text file, not an executable script. The solution is to put this little script in your image AMI under <strong>User Data</strong>. Any time an image launches, this will be executed once on the first boot. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-09.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-09.jpg" alt="" width="438" height="239" class="aligncenter size-full wp-image-7558" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-09.jpg 438w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-09-300x164.jpg 300w" sizes="(max-width: 438px) 100vw, 438px" /></a></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh
echo &quot;`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`.fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs nfs rw,nfsv4 0 0&quot; &gt;&gt; /etc/fstab
mount -a
</pre>
<h1>RHEL/CentOS</h1>
<p>Red Hat and CentOS don&#8217;t come up with NFS client installed, so you&#8217;ll have to install it first.</p>
<pre class="brush: bash; title: ; notranslate">
yum install nfs-utils
</pre>
<p>In order to mount the NFS target for Red Hat and CentOS servers, we&#8217;ll need to know what zone our instance belongs to. As you can remember from the above, each zone has a different DNS server name for the target. So, if you need your zone you can see that from the EC2 menu or with <strong>curl </strong> you can browse your instance metadata.</p>
<pre class="brush: bash; title: ; notranslate">
curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/
</pre>
<p>We also need a mount point. In my case I&#8217;ll mount my new file system under <strong>/root/efs</strong>. I don&#8217;t have the directory created, so I&#8217;ll do.</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /root/efs
</pre>
<p>The easiest way to mount the target without looking at the zone where the instance belongs is to run this one liner.</p>
<pre class="brush: bash; title: ; notranslate">
mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs
</pre>
<p>This means mount a new file system of type NFS, make sure it&#8217;s NFSv4 (-o), get the zone with curl and append it to the DNS server name of the NFS server and mount it under /root/efs.<br />
If you want to unmount the filesystem, do</p>
<pre class="brush: bash; title: ; notranslate">
umount /root/efs
</pre>
<p>Now, if you reboot your server, the mount points are gone, so you&#8217;ll have to make sure that on each reboot, your NFS mounts on. Edit <strong>/etc/fstab</strong> and add this line. </p>
<pre class="brush: bash; title: ; notranslate">
us-east-1d.fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs nfs defaults,vers=4.1 0 0
</pre>
<p>What if you have an image in a load balancing scenario and you have it configured to boot up in a random zone. The above <strong>/etc/fstab</strong> entry won&#8217;t work and you can&#8217;t query that with curl in <strong>fstab</strong>. It&#8217;s a text file, not an executable script. The solution is to put this little script in your image AMI under <strong>User Data</strong>. Anytime an image launches, this will be executed once on the first boot. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P073-10.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P073-10.jpg" alt="" width="438" height="239" class="aligncenter size-full wp-image-7559" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P073-10.jpg 438w, https://blog.andreev.it/wp-content/uploads/2016/09/P073-10-300x164.jpg 300w" sizes="(max-width: 438px) 100vw, 438px" /></a></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash
echo &quot;`$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-0b864a42.efs.us-east-1.amazonaws.com:/ /root/efs nfs defaults,vers=4.1 0 0&quot; &gt;&gt; /etc/fstab
mount -a
</pre>
<h1>AWS Linux</h1>
<p>See above for Red Hat and CentOS and just skip the part to install the nfs client. AWS Linux comes up with these utils preinstalled.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2016/09/94-amazon-aws-elastic-file-system-efs-on-freebsdrhelcentosaws-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
