AWS S3 Mount on CentOS 7

Installing Goofys instead of S3FS1 min


1
1 point

I have used S3FS to mount S3 bucket which is easy to install and works. If your application or service writes heavily and multi-threading it could cause you errors on your files as I faced.

Goofys allows you to mount an S3 bucket as a filey system.

So let's start installing Goofys

$ sudo yum install fuse

Then we install golang:

$ cd ~/
$ wget https://storage.googleapis.com/golang/go1.11.8.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xvzf go1.11.8.linux-amd64.tar.gz
$ mkdir -p ~/projects/{bin,pkg,src}
$ rm go1.11.8.linux-amd64.tar.gz

Add the below line /etc/profile.d/path.sh file

$ sudo nano /etc/profile.d/path.sh
export PATH=$PATH:/usr/local/go/bin

Add the below two lines to .bash_profile file at the end

$ nano ~/.bash_profile
export GOBIN="$HOME/projects/bin"
export GOPATH="$HOME/projects/src"

To apply changes to your current session, run the below command

$ source /etc/profile && source ~/.bash_profile

First let's test if Go works

$ go version
go version go1.11.8 linux/amd64

Now install Goofys from github, it could take few minutes to install

$ go get github.com/kahing/goofys
$ go install github.com/kahing/goofys

Now we need to mount the S3 bucket

$ mkdir /mnt/s3mybucket

Add our credentials to a file

$ mkdir .aws
$ nano .aws/credentials
[s3]
aws_access_key_id=[ACCESS_KEY]
aws_secret_access_key=[SECRET_KEY]

Run the below to mout

$ ~/projects/bin/goofys –region [S3_REGION] –profile s3 [BUCKET_NAME] /mnt/s3mybucket

Check if you have mounted the bucket successfully

$ df -h

You should see your folder /mnt/s3mybucket listed. Go and test by creating a file and check your S3 bucket from AWS console.

To mount the folder on startup you will need to create a new service.

$ nano /etc/systemd/system/goofys.service
# /etc/systemd/system/goofys.service
[Unit]
Description=Goofys daemon
After=network.target

[Service]
Type=simple
ExecStart=/home/[YOUR_USER]/projects/bin/goofys –region [S3_REGION] –profile s3 [BUCKET_NAME] /mnt/s3mybucket
PIDFile=/home/[YOUR_USER]/.aws/goofys.pid
User=[YOUR_USER]
Group=[YOUR_GROUP]
TimeoutSec=120
KillMode=process

[Install]
WantedBy=default.target

Then run the below to start the service and check, if it works then enable it and reboot

$ systemctl daemon-reload
$ systemctl start goofys.service
$ df -h
$ systemctl enable goofys.service
$ reboot

Like it? Share with your friends!

1
1 point
Hasan

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Story
Formatted Text with Embeds and Visuals