使用 gcloud CLI 建立 Memorystore for Memcached 執行個體

本快速入門導覽課程將逐步說明如何建立 Memorystore for Memcached 執行個體、連線至執行個體、傳送一些 Memcached 指令,以及刪除執行個體。

事前準備

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. 如果尚未安裝 Google Cloud SDK,請安裝

    系統提示時,請選擇在上方選取或建立的專案。

  7. 如果您已安裝 Google Cloud SDK,請更新。

    gcloud components update
  8. 為專案啟用 Service Networking API。
    啟用 Service Networking API
  9. 為專案啟用 Memorystore for Memcached API。
    啟用 Memorystore for Memcached API

建立 Memorystore for Memcached 執行個體

如要建立 Memorystore for Memcached 執行個體,請按照下列步驟操作:

  1. 開啟終端機視窗。

  2. 輸入下列指令,將您要建立執行個體的專案設定為 gcloud 的預設專案:

    gcloud config set core/project project-id
    
  3. 輸入下列指令,在 us-central1 地區建立具有 3 個節點的 Memcached 執行個體 (每個節點有 4 個核心和 10 GB 記憶體):

    gcloud memcache instances create myinstance --node-count=3 --node-cpu=4 \
        --node-memory=10GB --region=us-central1 --memcached-version=1.6.15
    
  4. 建立執行個體後,請執行下列 describe 指令,並記下其中一個節點的 IP 位址。

    gcloud memcache instances describe myinstance --region=us-central1
    

從 Compute Engine VM 連線至執行個體

  1. 連線至 Linux VM。如需連線至 Linux VM 的步驟,請參閱「使用 Linux VM 的快速入門導覽課程」。 如果您依快速入門所述,使用以 Debian 為基礎的映像檔建立 VM 執行個體,請使用 apt-get 安裝 telnet

    sudo apt-get install telnet
    
  2. 在終端機中,透過 telnet 連線至其中一個 Memcached 節點的 IP 位址,並將 variables 替換為適當的值。

    telnet node-ip-address 11211
    

    如果運作正常,您應該會看到以下輸出內容,且 [bracketed-variables] 已替換為專案的變數:

    Trying [node-ip-address]…
    Connected to [node-ip-address]
    
  3. 在 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 帳戶收取本頁所用資源的費用,請按照下列步驟操作。

  1. 如要避免系統向您的 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]
    
  2. 如果成功,gcloud 會傳回下列回應:

    Deleted instance [myinstance]
    

後續步驟