========================
Mounting a Google Cloud Storage bucket into CentOS/Debian
================================================
So here are the steps;
Create a GCP Cloud Storage bucket
Add a service account to which has access to that bucket
Install GCSFuse (The software that actually does the job) on the server
Prepare to mount (like we were doing bungee jumping up-to this point)
[Optional] Configure HTTP proxy settings
Mount the bucket
------------
key.json create
enable api
https://console.cloud.google.com/apis/enableflow?apiid=iam.googleapis.com&redirect=https:%2F%2Fconsole.cloud.google.com&_ga=2.231830424.623026834.1668416683-356279560.1666504556&_gac=1.84295403.1667475992.Cj0KCQjwqoibBhDUARIsAH2OpWgkL2zPs1B-deHAoIRedHDdgqrlFzJDsyKyG1fqB1l6tVO7MIxrWNcaArfrEALw_wcB&authuser=1&project=stl-tms
from the top area click the Create Service Account button.
Add a unique name, and press Create
In the grant service account access step, select Cloud Storage > Storage Object Admin
Goto Console-> IAM -> service account -> create Service account -> (... Actions) -> Manage Key -> create json file ->
upload this key.json file to linux instance
gcsfuse --key-file /home/khan/stl-td2e879f.json --foreground /bucketdata
============================
----------------------
Mount in a Ubuntu instance
------------------------
** Install gcsfuse
Enter the following commands one by one
sudo apt-get update
sudo apt-get install curl -y
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 -
sudo apt-get update
sudo apt-get install gcsfuse
As of now, you should have gcsfuse installed and ready for action. But we will need google-cloud-sdk for authenticating to the Google Storage
** Install Google Cloud SDK
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install google-cloud-sdk
Authenticate with Google Cloud Storage
Switch to the user you will be mounting your bucket with. And issue the following command
gcloud auth application-default login
This will present you with a URL. Copy that URL and paste it in your browser, login with your Google account. You should see a token on your browser window. Copy it and paste it in the Terminal prompt asking for the verification code.
Once you give the token, you should be authenticated and you can now mount your Bucket.
Mount the bucket
Again, switch to the user you want to mount the bucket as. This is important because you cannot change the ownership of the mount. If you mount it with root user, then the mount can only be used by the root user.
mkdir /mnt/google-cloud-bucket
gcsfuse your_bucket_name /mnt/google-cloud-bucket
That’s it, you should have your bucket mounted on your system. You can verify the mount using the df -h command
No comments:
Post a Comment