Membuat instance dan menulis data dengan cbt CLI
Jika sedang mempelajari Bigtable, Anda dapat mempelajari panduan memulai cepat untuk memahami dasar-dasar yang akan Anda gunakan dalam skala besar di lingkungan produksi.
Dalam panduan memulai ini, Anda akan melakukan tindakan berikut:
- Hubungkan ke instance Bigtable.
- Lakukan tugas administratif dasar.
- Menulis data ke tabel.
- Membaca data dari tabel.
Sebelum memulai
- 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.
-
Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.
-
Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:
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,[email protected].ROLE: The IAM role that you grant to your user account.
-
Install the Google Cloud CLI.
-
Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.
-
Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:
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,[email protected].ROLE: The IAM role that you grant to your user account.
- Jalankan perintah berikut untuk menginstal
cbtCLI :gcloud components install cbt Buka halaman Create instance di konsol Google Cloud .
Untuk Instance name, masukkan
Quickstart instance.Untuk Instance ID, masukkan
quickstart-instance.Klik Lanjutkan.
Untuk Storage type, pilih SSD.
Klik Lanjutkan.
Untuk Cluster ID, masukkan
quickstart-instance-c1.Untuk Region, pilih wilayah di dekat Anda.
Untuk Zone, pilih Any.
Untuk Node scaling mode, pilih Manual allocation.
Untuk Jumlah, pilih 1.
Klik Buat untuk membuat instance.
Konfigurasi CLI
cbtuntuk menggunakan project dan instance Anda dengan membuat file.cbtrc, menggantiPROJECT_IDdengan ID untuk project tempat Anda membuat instance Bigtable:echo project = PROJECT_ID >> ~/.cbtrc && echo instance = quickstart-instance >> ~/.cbtrc
Pastikan Anda menyiapkan file
.cbtrcdengan benar:cat ~/.cbtrc
Terminal akan menampilkan isi file
.cbtrc, yang terlihat mirip dengan berikut:project = PROJECT_ID instance = quickstart-instance
Sekarang Anda dapat menggunakan
cbtCLI dengan instance Anda.Buat tabel bernama
my-table.cbt createtable my-table
Menampilkan daftar tabel Anda:
cbt ls
Perintah ini menampilkan output yang mirip dengan berikut ini:
my-tableTambahkan satu family kolom bernama
cf1:cbt createfamily my-table cf1
Mencantumkan grup kolom Anda:
cbt ls my-table
Perintah ini menampilkan output yang mirip dengan berikut ini:
Family Name GC Policy ----------- --------- cf1 <never>Tulis nilai
test-value1dantest-value2ke barisr1, menggunakan grup kolomcf1dan penentu kolomc1:cbt set my-table r1 cf1:c1=test-value1 cbt set my-table r1 cf1:c1=test-value2
Gunakan perintah
cbt readuntuk membaca data yang Anda tambahkan ke tabel:cbt read my-table
Shell akan menampilkan output yang mirip dengan berikut ini:
---------------------------------------- r1 cf1:c1 @ 2023/03/22-06:56:11.323000 "test-value1" cf1:c1 @ 2023/03/22-06:56:04.361000 "test-value2"Dua nilai yang diberi stempel waktu disimpan untuk kolom yang sama di baris
r1.Hapus tabel
my-table:cbt deletetable my-table
Hapus instance:
cbt deleteinstance quickstart-instance
Hapus file
.cbtrc:rm ~/.cbtrc
Opsional: Cabut kredensial dari gcloud CLI:
gcloud auth revoke
- Selesaikan codelab Bigtable.
- Lihat
dokumentasi referensi
cbtCLI. - Lihat contoh kode sumber untuk kasus penggunaan deteksi penipuan.
- Tulis aplikasi Hello World di C#, C++, Go, Java, Node.js, PHP, Python, Ruby, atau menggunakan klien HBase untuk Java.
Membuat instance Bigtable
Menghubungkan ke instance
Membaca dan menulis data
Bigtable menyimpan data dalam tabel, yang berisi baris. Setiap baris diidentifikasi oleh kunci baris.
Data dalam baris disusun ke dalam grup kolom, yang merupakan grup kolom. Penentu kolom mengidentifikasi satu kolom dalam grup kolom.
Dapat ada beberapa sel yang diberi stempel waktu di persimpangan baris dan kolom.
Pembersihan
Agar tidak menimbulkan biaya pada akun Google Cloud Anda untuk resource yang digunakan dalam panduan memulai ini, hapus instance. Menghapus file .cbtrc membuat Anda siap mengerjakan project lain.