Cloud computing is constantly evolving and platforms like Google Cloud Storage (GCS) are becoming increasingly important for efficient data management. If you are a Linux user looking to integrate GCS seamlessly into your workflow, you’ve come to the right place. In this blog, we will guide you through the step-by-step process of mounting a Google Cloud Storage bucket onto your Linux system.
Software Requirements for this process
1. Python 2.7
2. Google Cloud SDK
3. FUSE
Google Cloud SDK Installation
The Cloud SDK is a set of tools for Cloud Platform. It contains gcloud, gsutil, and bq, which you can use to access Google Compute Engine, Google Cloud Storage, Google BigQuery, and other products and services from the command line. You can run these tools interactively or in your automated scripts.
Step 1: Download the Cloud SDK archive file:
Firstly, download the cloud SDK file in your system by using the following links. Check with your versions and install the file.
Linux (x86_64) : https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-156.0.0-linux-x86_64.tar.gz
Linux (x86) : https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-156.0.0-linux-x86.tar.gz
Step 2:
Now, extract the downloaded file to any location on your file system.
Step 3:
This step is an optional. Run the install script to add Cloud SDK tools to your path and enable the command completion in your bash shell, and/or and enable usage reporting
./google-cloud-sdk/install.sh
It will add the commands in /root/.bashrc. After that, execute the below command in order to make it work in the current shell.
source /root/.bashrc
Step 4: Authentication of Google Cloud in SDK
After completing the installation now we need to authenticate the Google Cloud in SDK. Run the core gcloud commands to authenticate your SDK to your Google Cloud account:
o authenticate run:
#gcloud auth login
It will generate the browser-level login URL to complete the verification
Step 5:
Visit the URL by using the browser and sign in using your Google Cloud account.
Step 6:
After sigining in using your account, you will get a verification code and now verify yourself with your verification code.
Step 7:
After getting verified, you will be able to complete the authentication of SDK.
Step 8:
Now to verify your Google Cloud account is active or not use the following command.
#gcloud auth list
After the activation now it’s time to get the authentication key. In order to get the default key use the below command.
#gcloud auth application-default login
Step 9:
Again, the browser-level login URL will be generated and repeat the steps 5 & 6.
Once the steps have been completed successfully, the auth key will be saved in a JSON file [/root/.config/gcloud/application_default_credentials.json]. These credentials will be used by any library that requests Application Default Credentials.
FUSE Installation
Cloud Storage FUSE is an open source plugin that allows you to mount Google Cloud Storage buckets as file systems on Linux or OS X systems. It also provides a way for applications to upload and download Google Cloud Storage objects using standard file system semantics.
Cloud Storage FUSE can be run anywhere with connectivity to Google Cloud Storage, including Google Compute Engine VMs or on-premises systems
Prerequisites
Before invoking gcsfuse, you must have a GCS bucket that you want to mount. If your bucket doesn’t yet exist, create one using the Google Developers Console. GCS credentials are automatically loaded using Google application default credentials, or a JSON key file can be specified explicitly using –key
Step 1:
Configure the gcsfuse using yum repo:
#vim /etc/yum.repos.d/gcsfuse.repo
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
Step 2:
To install the gcsfuse use the following command.
#sudo yum install gcsfuse
Step 3:
To mount a bucket using gcsfuse over an existing directory /path/to/mount, invoke it like the following,
#gcsfuse my-bucket /path/to/mount
The gcsfuse tool will exit successfully after mounting the file system. Unmount in the usual way for a fuse file system on your operating system:
#fusermount -u /path/to/mount # Linux
Wrapping Up
To mount the google bucket on system startup, add below line in fstab.
#my-bucket /mount/point gcsfuse rw,uid=0,gid=0
Thank you for taking the time to read our blog on “How to setup Google cloud storage bucket in the linux?”. We hope you found the information valuable and insightful. If you find any issues with the information provided in this blog don’t hesitate to contact us (info@assistanz.com).
Optimize your cloud and never lose a valuable customer again!
Our mission is to ensure that your cloud remain lightning-fast and protected at all times by monitoring and maintaining it 24×7 by our experts.