Showing posts with label EC2. Show all posts
Showing posts with label EC2. Show all posts

HOWTO Mount S3 bucket into EC2 instance

I would like to share my experience mounting a S3 bucket into a Linux EC2 instance.

The steps I followed were:

  • 1.- Download the latest version of s3fs (which is a FUSE backend for S3) from https://code.google.com/p/s3fs/downloads/list or
    wget https://s3fs.googlecode.com/files/s3fs-1.71.tar.gz
    • tar zxf s3fs-r177-source.tar.gz
  • 2.- Unpack it: 
    • apt-get install build-essential libxml2-dev libfuse-dev libcurl4-openssl-dev
  • 3.- Install dependencies for building. In my Ubuntu AMI was: 
    • cd s3fs; make install
  • 4.- Build and install the code (this copies the binary s3fs to /usr/bin): 
    •  touch /etc/passwd-s3fs && chmod 640 /etc/passwd-s3fs && echo 'AccessKey:SecretKey' > /etc/passwd-s3fs        
  • 5.- Edit a config file for storing your keys (you can check them out under AWS Menu -> Your Account -> Security Credentials)  Note: If you dont want to leave any trace of your secret key in your shell history, use a text editor to edit the file rather than echoing it.
    So where to find 
    'AccessKey:SecretKey'?
    Actually, you can download a file named 
    rootkey.csv and find that in it. 
  • 6.- Create a directory for mounting the S3 filesystem and mount it. Note that you can mount the s3fs anywhere you like:  /usr/bin/s3fs bucketname /mnt/mountpoint
  • 7. Check it is working correctly:  grep s3fs /etc/mtab

A frequently occurred problem that makes your Drupal or other CMS fail is: 

PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (111) in lock_may_be_available() (line 167 of /var/www/drupal­
7.22/includes/lock.inc).

I saw many people asking this problem online, but did not see any viable answers. After Googling for hours, I finally came up with a solution. Let me start with what causes this problem. 


Why this problem happens?

The error mainly happens due to the insufficient memory on the heap for the mySQL on EC2. The Amazon EC2′s micro instance gives us just 613MB of memory and mySQL can’t take all of the memory for itself.
InnoDB memory heap is disabled in mySQL is an annoying issue that occurs pretty often when you install mySQL on Amazon EC2 server, especially when you use it for Drupal or WordPress. Let’s now look at why this error happens and how we could trouble shoot it.

How to solve this issue?

The solution that works best is to create a swap memory for mySQL and allow the applications to take advantage of that. Here’s how to do that:
  1. Login into your instance from Terminal or Command Prompt via SSH.
  2. Now, switch to Root mode (Sudo su)
  3. Run the following command: dd if=/dev/zero of=/swapfile bs=1M count=1024
  4. Make a swap file by running: mkswap /swapfile 
  5. Turn on Swap Files: swapon /swapfile
And that’s it. You’re done. To monitor your Swap file size and free space, just type swapon -s.


Hope this helps. 
This problem used to happy to me quite frequently on daily base. After using this method, my Drupal has been work perfectly for days.  

Recently, I played around with the EC2 virtual instance from Amazon. It is super awesome and I think I would change to use it.

Today,  I wanted to check if the website is online. It went with saying that I used the “ping” command, but not getting through, I thought the server was down (kinda freaked out). However,  the website on the browser was working fine.
Then, I realized that all I needed to do was to enable the ICMP requests:
1) Log into AWS account.
2) Click on “Security Groups”. Choose the required security group.
3) Click on the “Inbound” tab.
Create a new rule: Custom ICMP rule
Type: Echo request
Source: 0.0.0.0/0
0.0.0.0 will allow everyone to ping your server. You can specify your own addresses if you want.
That’s it.

In addition, if you cannot get through with other similar functionalities, it could be not enabled. You can fix it in the same way.

Popular Posts