Google Cloud SDK をAmazon Linux 2環境にインストール(スクリプトベース+検証コード利用)

Google Cloud SDK をAmazon Linux 2環境にインストール(スクリプトベース+検証コード利用)

Clock Icon2019.09.10

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

個人的Google Cloud SDK導入備忘録 第2弾。当エントリではAmazon Linux 2環境にGoogle Cloud SDKを導入する手順について見ていきたいと思います。前エントリ同様、専用スクリプトを使って導入する方法です。

Google Cloud SDKインストール手順 in Amazon Linux 2(スクリプトベース+検証コード利用):実践

まずは導入環境を用意。Amazon Linux 2環境をサクッと構築しておきます。

$ ssh -i gcp-xxxxxxxxxx.pem ec2-user@xx.xxx.xxx.xx
Last login: Tue Sep  3 08:41:37 2019 from fs276ec90a.tkyc004.ap.nuro.jp

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
$ sudo yum -y update
$ cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

導入スクリプトの入手&解凍&実行はMac OSXで実践したときのものと同様。

$ wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-196.0.0-linux-x86_64.tar.gz
$ tar xvf google-cloud-sdk-196.0.0-linux-x86_64.tar.gz
$ cd google-cloud-sdk/
$ ./google-cloud-sdk/install.sh 
Welcome to the Google Cloud SDK!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:

    gcloud config set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)?  y


Your current Cloud SDK version is: 196.0.0
The latest available version is: 260.0.0

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                   Components                                                  │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬──────────┤
│      Status      │                         Name                         │            ID            │   Size   │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼──────────┤
│ Update Available │ BigQuery Command Line Tool                           │ bq                       │  < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries                             │ core                     │ 11.4 MiB │
│ Update Available │ Cloud Storage Command Line Tool                      │ gsutil                   │  3.6 MiB │
│ Not Installed    │ App Engine Go Extensions                             │ app-engine-go            │ 56.6 MiB │
│ Not Installed    │ Cloud Bigtable Command Line Tool                     │ cbt                      │  7.4 MiB │
│ Not Installed    │ Cloud Bigtable Emulator                              │ bigtable                 │  6.6 MiB │
│ Not Installed    │ Cloud Datalab Command Line Tool                      │ datalab                  │  < 1 MiB │
│ Not Installed    │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │ 18.4 MiB │
│ Not Installed    │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │ 38.1 MiB │
│ Not Installed    │ Cloud Firestore Emulator                             │ cloud-firestore-emulator │ 36.7 MiB │
│ Not Installed    │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │ 34.8 MiB │
│ Not Installed    │ Cloud SQL Proxy                                      │ cloud_sql_proxy          │  3.8 MiB │
│ Not Installed    │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │ 14.5 MiB │
│ Not Installed    │ Google Cloud Build Local Builder                     │ cloud-build-local        │  6.0 MiB │
│ Not Installed    │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │  1.8 MiB │
│ Not Installed    │ gcloud Alpha Commands                                │ alpha                    │  < 1 MiB │
│ Not Installed    │ gcloud Beta Commands                                 │ beta                     │  < 1 MiB │
│ Not Installed    │ gcloud app Java Extensions                           │ app-engine-java          │ 85.9 MiB │
│ Not Installed    │ gcloud app PHP Extensions                            │ app-engine-php           │          │
│ Not Installed    │ gcloud app Python Extensions                         │ app-engine-python        │  6.0 MiB │
│ Not Installed    │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras │ 28.5 MiB │
│ Not Installed    │ kubectl                                              │ kubectl                  │  < 1 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴──────────┘
To install or remove components at your current SDK version [196.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [260.0.0], run:
  $ gcloud components update


Modify profile to update your $PATH and enable shell command 
completion?

Do you want to continue (Y/n)?  Y

The Google Cloud SDK installer will now prompt you to update an rc 
file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use 
[/home/ec2-user/.bashrc]:  
Backing up [/home/ec2-user/.bashrc] to [/home/ec2-user/.bashrc.backup].
[/home/ec2-user/.bashrc] has been updated.

==> Start a new shell for the changes to take effect.


For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts

初期化コマンド(gcloud init)実施。『ログインしますか?』と促されるので、ここは『はい』(Y)を入力し[Enter]押下。認証ページのURLが(下記18行目の位置に)出力されるので、そのURLにブラウザアクセスしてください。

$ ./google-cloud-sdk/bin/gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                                                                                                              
Reachability Check passed.
Network diagnostic (1/1 checks) passed.

You must log in to continue. Would you like to log in (Y/n)?  Y

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?redirect_uri=(以下略)

Enter verification code: 

ブラウザアクセスすると、対象アカウントへのアクセスを求められます。対応するアカウントを選択し、[許可]を押下。次の画面に現れる識別コードをコピーします。

識別コード検証が通ると、以降はMac OSX版同様にプロジェクト選択を行ってツール導入完了となります。

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?redirect_uri=(以下略)

Enter verification code: 4/qXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXoQ

Updates are available for some Cloud SDK components.  To install them,
please run:
  $ gcloud components update

You are logged in as: [GCPにアクセスしているGMailアカウント].

Pick cloud project to use: 
 [1] cm-xxxxxxxxxxxxxx
 [2] tokyo-xxxxxxxxxxxxxxxxxxx
 [3] Create a new project
Please enter numeric choice or text value (must exactly match list 
item):  1

Your current project has been set to: [cm-xxxxxxxxxxxxxx].

Your project default Compute Engine zone has been set to [asia-northeast1-b].
You can change it by running [gcloud config set compute/zone NAME].

Your project default Compute Engine region has been set to [asia-northeast1].
You can change it by running [gcloud config set compute/region NAME].

Created a default .boto configuration file at [/home/ec2-user/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use (GCPにアクセスしているGMailアカウント) by default
* Commands will reference project `cm-xxxxxxxxxxxxxx` by default
* Compute Engine commands will use region `asia-northeast1` by default
* Compute Engine commands will use zone `asia-northeast1-b` by default

Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic -h` to learn about advanced features of the SDK like arg files and output formatting
$ 

## 補完を効かせる為に入り直す
$ exit
$ ssh -i gcp-xxxxxxxxxxxx.pem ec2-user@xx.xxx.xxx.xx

## バージョン確認
$ gcloud version
Google Cloud SDK 196.0.0
bq 2.0.31
core 2018.03.30
gsutil 4.30
Updates are available for some Cloud SDK components.  To install them,
please run:
  $ gcloud components update

## ツールのアップデート
$ gcloud components update

まとめ

というわけでGoogle Cloud SDKのインストール手順(Amazon Linux 2/スクリプトベース+検証コード利用)のご紹介でした。次のエントリでは同じOS(Amazon Linux2)で異なる手法で導入を試みてみたいと思います。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.