LoginSignup
14
15

More than 3 years have passed since last update.

GCEからGCS(Cloud Storage)をファイルシステムとして利用する

Last updated at Posted at 2019-09-02

本記事は、以下のインストール方法を和訳したものになります。
- Ubuntu and Debian (latest releases)
https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/docs/installing.md#ubuntu-and-debian-latest-releases

環境

  • Google Compute Engine + Ubuntu and Debian
  • Google Cloud Storage

前提条件

  • GCE(Google Compute Engine)のインスタンスを作成済み。
    まだ作成されていない方はこちら
  • Cloud Storageのバケットを作成済み。
    まだ作成されていない方はこちら

事前準備

GCEのインスタンスを停止した状態で、インスタンスのデフォルトのアクセススコープ(権限)を変更。
この操作を行わないと、GCEのインスタンス上からCloud Storageのファイルを操作できません。

  1. VMインスタンスの詳細画面より「編集」
  2. アクセススコープを「各APIにアクセス権を設定」に変更
  3. ストレージの項目を「フル」に変更(デフォルトでは「読み取り」のみ)

GCSFuseをインストール

GCSFuseを使用することで、GCEのインスタンス上で、Cloud Storageを共有フォルダとしてGCEのコンソール上で操作できるようになります。通常のファイルシステム同様、ls , cp , mv , rm などのコマンドでファイル操作可能です。

上記ページでは以下のOSについて、インストール手順が載っていますが、本稿では動作確認をとった UbuntuDebian のみに絞ります。ご容赦ください。

  • ubuntu-1804-lts, ubuntu-1604-lts, and ubuntu-1404-lts
  • debian-8, debian-7
  • centos-7, centos-6
  • rhel-7, rhel-6
  • sles-12 (2019年9月2日現在)

GCSFuseのアップデート情報を確認し、公開鍵を取得

GCEのインスタンスを起動し、SSH接続後、以下のコードを実行します。
以下の処理は、現行のUbuntuとDebianに対応しているgcsfuseのアップデートがないか確認し、apt-getをセットアップしています。

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 -

GCSFuseをインストール

sudo apt-get update
sudo apt-get install gcsfuse

バケット名を指定して、ストレージをマウント

Cloud Storageのバケット名を指定して、新規フォルダにマウントします。
再起動する度に、gcsfuse [bucket-name] [path]の操作が必要になります。

mkdir mount
sudo gcsfuse [bucket-name] mount

まとめ

# install GCSFuse
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 -y
sudo apt-get install gcsfuse -y

# mount bucket
mkdir mount
sudo gcsfuse [bucket-name] mount    # please set up [bucket-name]

参考

Cloud Storage FUSE https://cloud.google.com/storage/docs/gcs-fuse?hl=ja
GitHub - GoogleCloudPlatform/gcsfuse https://github.com/GoogleCloudPlatform/gcsfuse

以上

14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15