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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with 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_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Bigtable and Cloud Bigtable Admin APIs:
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.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with 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_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Bigtable and Cloud Bigtable Admin APIs:
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.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- Jalankan perintah berikut untuk menginstal
cbt
CLI :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
cbt
untuk menggunakan project dan instance Anda dengan membuat file.cbtrc
, menggantiPROJECT_ID
dengan ID untuk project tempat Anda membuat instance Bigtable:echo project = PROJECT_ID >> ~/.cbtrc && echo instance = quickstart-instance >> ~/.cbtrc
Pastikan Anda menyiapkan file
.cbtrc
dengan benar:cat ~/.cbtrc
Terminal akan menampilkan isi file
.cbtrc
, yang terlihat mirip dengan berikut:project = PROJECT_ID instance = quickstart-instance
Sekarang Anda dapat menggunakan
cbt
CLI 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-table
Tambahkan 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-value1
dantest-value2
ke barisr1
, menggunakan grup kolomcf1
dan penentu kolomc1
:cbt set my-table r1 cf1:c1=test-value1 cbt set my-table r1 cf1:c1=test-value2
Gunakan perintah
cbt read
untuk 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
cbt
CLI. - 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 dengan 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.