olNGIb4NkK5r2x7x4oG3GpEzizVpnY6KNCck9cym

Mount Google Cloud Storage on Compute Engine or Linux

Mount Google Cloud Storage on Compute Engine or Linux

In this tutorial will show you how to mount Google Cloud Storage (GCS) Bucket on Compute Engine or Linux.

We use Google Cloud Storage FUSE tool or gcsfuse, gcsfuse has been tested successfully with the following operating systems:

  • Linux (minimum kernel version 3.10)
  • OS X (minimum version 10.10.2)

It may or may not work correctly with other operating systems and older versions.

If you are running on Google Compute Engine, it is recommended that you use one of the following images with which it has been tested (preferring the latest version when possible):

  • ubuntu-2004-lts, ubuntu-1804-lts, ubuntu-1604-lts, and ubuntu-1404-lts
  • debian-8, debian-7
  • centos-8, centos-7
  • rhel-7
  • sles-12

Prerequisites

For this tutorial i use the following setup:

  • Compute Engine Instance with Ubuntu 18.04 LTS
  • Hetzner VPS with CentOS 7

Install gcsfuse on Ubuntu 18.04 LTS

  1. Add gcsfuse repository with the following command
    export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
    echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  2. Update and install gcsfuse
    sudo apt-get update
    sudo apt-get install gcsfuse
  3. Verify that gcsfuse is installed successfully
    gcsfuse -v
    Install gcsfuse ubuntu 18.04 lts

Install gcsfuse on CentOS 7

  1. Add gcsfuse repository with the following command
    sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
    [gcsfuse]
    name=gcsfuse (packages.cloud.google.com)
    baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
           https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    EOF
  2. Install gcsfuse
    sudo yum install gcsfuse
  3. Verify that gcsfuse is installed successfully
    gcsfuse -v
    Install gcsfuse centos 7
    Install gcsfuse centos 7

Add Credentials

We will the simple setting credentials using google account associated with the Google Cloud Storage, For default, Google Cloud SDK (gcloud) is already installed on Compute Engine Instance. Optionally If not, install gcloud using this tutorial https://cloud.google.com/sdk/docs/install and make sure to set the project

Run the following command to set credentials for gcsfuse

gcloud auth application-default login

If there is prompt asking Do you want to continue (Y/n)? type y and hit enter

gcloud auth application login GCE
reply gcloud auth application login GCE

Mount GCS Bucket

  1. First create directory for the mount location, for example we can create directory on user home folder /home/<user>/gcsbucket

    cd ~
    pwd
    mkdir gcsbucket
  2. Mount gcs bucket using the following command

    gcsfuse <bucket-name> /home/<user>/gcsbucket
    change <bucket-name> with your bucket name and <user> with your username
    Mount GCS Bucket
  3. [Optional] If you want to only mount specific folder in the bucket you can use this command
    gcsfuse --only-dir  <bucket-name> /home/<user>/gcsbucket

Bucket mounting success, now you can check by cd to /home/<user>/gcsbucket. Also try creating directory or creating and copying files, after that verify the folder or files created by going to Google Cloud Storage (GCS) Bucket in Google Cloud Console.

Creating Folder and File GCS Bucket

File and Folder created are automatically showing up on Google Cloud Storage (GCS) Bucket in Google Cloud Console

GCS Bucket on GCP Console

Useful links

Google Cloud Storage Documentation : https://cloud.google.com/storage/docs
Google Cloud Storage FUSE tool : https://github.com/GoogleCloudPlatform/gcsfuse
Installing Google Cloud SDK : https://cloud.google.com/sdk/docs/install

Related Posts

Post a Comment