使用 cbt CLI 建立執行個體並寫入資料
如果您正在學習 Bigtable,可以完成快速入門導覽,瞭解在實際環境中大規模使用的基本概念。
在本快速入門導覽課程中,您將執行下列操作:
- 連線至 Bigtable 執行個體。
- 執行基本管理工作。
- 將資料寫入資料表。
- 從資料表讀取資料。
事前準備
- 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.
- 
      Install the Google Cloud CLI. 
- 
          如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。 
- 
        如要初始化 gcloud CLI,請執行下列指令: gcloud init
- 
  
  
    Create or select 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.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith a name for the Google Cloud project you are creating.
- 
        Select the Google Cloud project that you created: gcloud config set project PROJECT_ID Replace PROJECT_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Bigtable and Cloud Bigtable Admin APIs: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable bigtable.googleapis.com bigtableadmin.googleapis.com 
- 
    
        Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/bigtable.admingcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE Replace the following: - PROJECT_ID: Your project ID.
- USER_IDENTIFIER: The identifier for your user account. For example,- myemail@example.com.
- ROLE: The IAM role that you grant to your user account.
 
- 
      Install the Google Cloud CLI. 
- 
          如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。 
- 
        如要初始化 gcloud CLI,請執行下列指令: gcloud init
- 
  
  
    Create or select 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.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith a name for the Google Cloud project you are creating.
- 
        Select the Google Cloud project that you created: gcloud config set project PROJECT_ID Replace PROJECT_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Bigtable and Cloud Bigtable Admin APIs: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable bigtable.googleapis.com bigtableadmin.googleapis.com 
- 
    
        Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/bigtable.admingcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE Replace the following: - PROJECT_ID: Your project ID.
- USER_IDENTIFIER: The identifier for your user account. For example,- myemail@example.com.
- ROLE: The IAM role that you grant to your user account.
 
- 執行下列指令,安裝 
cbtCLI :gcloud components install cbt
- 在 Google Cloud 控制台中開啟「建立執行個體」頁面。 
- 在「Instance name」(執行個體名稱) 中輸入 - Quickstart instance。
- 在「Instance ID」(執行個體 ID) 中輸入 - quickstart-instance。
- 按一下「繼續」。 
- 在「儲存類型」部分,請選擇「SSD」。 
- 按一下「繼續」。 
- 在「叢集 ID」部分輸入 - quickstart-instance-c1。
- 在「區域」部分,選取您附近的區域。 
- 在「Zone」(區域) 中選取「Any」(任何)。 
- 針對「節點資源調度模式」,選擇「手動分配」。 
- 在「數量」部分,選取「1」。 
- 按一下「建立」,建立執行個體。 
- 建立 - .cbtrc檔案,將- PROJECT_ID替換為您建立 Bigtable 執行個體的專案 ID,藉此設定- cbtCLI 使用您的專案和執行個體:- echo project = PROJECT_ID >> ~/.cbtrc && echo instance = quickstart-instance >> ~/.cbtrc 
- 確認您已正確設定 - .cbtrc檔案:- cat ~/.cbtrc - 終端機會顯示 - .cbtrc檔案的內容,類似於下列內容:- project = PROJECT_ID instance = quickstart-instance - 現在您可以使用 - cbtCLI 執行個體。
- 建立名為 - my-table的資料表。- cbt createtable my-table 
- 列出您的資料表︰ - cbt ls - 此指令會顯示類似下面內容的輸出: - my-table
- 新增名為 - cf1的資料欄系列:- cbt createfamily my-table cf1 
- 列出您的資料欄系列︰ - cbt ls my-table - 此指令會顯示類似下面內容的輸出: - Family Name GC Policy ----------- --------- cf1 <never>
- 使用資料欄系列 - cf1和資料欄限定詞- c1,將值- test-value1和- test-value2寫入資料列- r1:- cbt set my-table r1 cf1:c1=test-value1 cbt set my-table r1 cf1:c1=test-value2 
- 使用 - cbt read指令讀取您新增至資料表的資料:- cbt read my-table - shell 會顯示類似以下內容的輸出︰ - ---------------------------------------- r1 cf1:c1 @ 2023/03/22-06:56:11.323000 "test-value1" cf1:c1 @ 2023/03/22-06:56:04.361000 "test-value2"- 同一欄在第 - r1列中儲存了兩個含有時間戳記的值。
- 刪除資料表 - my-table:- cbt deletetable my-table 
- 刪除執行個體: - cbt deleteinstance quickstart-instance 
- 刪除 - .cbtrc檔案:- rm ~/.cbtrc 
- 選用:從 gcloud CLI 撤銷憑證: - gcloud auth revoke 
- 逐步演練 Bigtable 程式碼研究室。
- 查看 
cbtCLI 參考說明文件。
- 請參閱詐欺偵測用途的範例原始碼。
- 以 C#、C++、Go、Java、Node.js、PHP、Python、Ruby 或 適用於 Java 的 HBase 用戶端,編寫 Hello World 應用程式。
建立 Bigtable 執行個體
連線至執行個體
讀取和寫入資料
Bigtable 會將資料儲存在資料表中,當中包含資料列。每一資料列係由一「資料列索引鍵」識別。
資料列中的資料會組織成「資料欄系列」,即為資料欄的群組。 「資料欄限定詞」識別資料欄系列中的單一資料欄。
資料列和資料欄的交集可以有多個加上時間戳記的儲存格。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本快速入門導覽課程中所用資源的費用,請刪除執行個體。刪除 .cbtrc 檔案後,您就可以開始處理其他專案。