gcloud CLI を使用して Memorystore for Memcached インスタンスを作成する
このクイックスタートでは、Memorystore for Memcached インスタンスの作成、インスタンスへの接続、Memcached コマンドの送信、インスタンスの削除の手順を説明します。
始める前に
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- まだインストールしていない場合は、Google Cloud SDK をインストールします。プロンプトが表示されたら、上記で作成または選択したプロジェクトを選択します。 
- 
  Google Cloud SDK をインストール済みの場合は更新します。 gcloud components update 
- 
    プロジェクトで Service Networking API を有効にします。
 Service Networking API を有効にします。
- 
    プロジェクトで Memorystore for Memcached API を有効にします。
 Memorystore for Memcached API を有効にする
Memorystore for Memcached インスタンスの作成
Memorystore for Memcached インスタンスを作成するには:
- ターミナル ウィンドウを開きます。 
- 次のコマンドを入力して、インスタンスを作成するプロジェクトを、 - gcloudのデフォルト プロジェクトとして設定します。- gcloud config set core/project project-id 
- 次のコマンドを入力して、us-central1 リージョンに 3 ノード(それぞれ 4 コアと 10 GB メモリを持つノード)の Memcached インスタンスを作成します。 - gcloud memcache instances create myinstance --node-count=3 --node-cpu=4 \ --node-memory=10GB --region=us-central1 --memcached-version=1.6.15
- インスタンスを作成したら、次の - describeコマンドを実行して、いずれかのノードの IP アドレスを書き留めます。- gcloud memcache instances describe myinstance --region=us-central1 
Compute Engine VM からインスタンスへの接続
- Linux VM に接続します。Linux VM に接続する手順については、Linux VM の使用に関するクイックスタートをご覧ください。クイックスタートの説明に従い、Debian ベースのイメージを使用して VM インスタンスを作成した場合は、 - apt-getを使用して- telnetをインストールします。- sudo apt-get install telnet 
- ターミナルから、いずれかの Memcached ノードの IP アドレスに telnet 接続します。variables は、適切な値に置き換えてください。 - telnet node-ip-address 11211 - 正しく動作すると、 - [bracketed-variables]をプロジェクトの変数に置き換えた、次の出力が表示されます。- Trying [node-ip-address]… Connected to [node-ip-address] 
- telnet セッションで、いくつかの Memcached コマンドを入力します。 - 次のように入力します。 - get greeting - 結果: - END - 次のように入力します。 - set greeting 1 0 11 hello world - 結果: - STORED - 次のように入力します。 - get greeting - 結果: - VALUE greeting 1 11 hello world END 
Memorystore for Memcached は、標準のオープンソース Memcached ライブラリをサポートしています。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
- このクイックスタートで使用したリソースに対して Google Cloud アカウントに課金されないようにするには、次のコマンドを入力してインスタンスを削除します。 - gcloud memcache instances delete myinstance --region=us-central1 - Yと入力して、インスタンスの削除を確認します。- You are about to delete instance [myinstance] in [us-central1]. Any associated data will be lost. Do you want to continue (Y/n)? Y Delete request issued for: [myinstance] 
- 成功すると、 - gcloudは次のレスポンスを返します。- Deleted instance [myinstance]