Membuat instance Filestore menggunakan gcloud CLI

Panduan memulai ini menunjukkan cara menyiapkan dan menjalankan Filestore dengan cepat menggunakan Google Cloud CLI. Dalam panduan memulai ini, Anda akan mempelajari cara:

  • Buat instance Filestore.
  • Pasang fitur berbagi file dari instance tersebut di VM klien Compute Engine.
  • Buat file di berbagi file yang di-mount.
  • Hapus instance Filestore.

Sebelum memulai

  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. Install the Google Cloud CLI.

  3. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  4. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  5. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • 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.

  6. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika Anda membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the Filestore API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable file.googleapis.com
  9. Install the Google Cloud CLI.

  10. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  11. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  12. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • 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.

  13. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika Anda membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  14. Verify that billing is enabled for your Google Cloud project.

  15. Enable the Filestore API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable file.googleapis.com
  16. Peran yang diperlukan

    Untuk mendapatkan izin yang Anda perlukan untuk menyelesaikan panduan memulai cepat ini, minta administrator Anda untuk memberi Anda peran IAM berikut di project Anda:

    Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.

    Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.

    Setelah menyelesaikan tugas yang dijelaskan dalam dokumen ini, Anda dapat menghindari penagihan berkelanjutan dengan menghapus resource yang Anda buat. Untuk mengetahui informasi selengkapnya, lihat Pembersihan.

    Membuat VM Compute Engine

    Linux

    1. Create a Compute Engine instance. Configure the instance as follows:
      • Name the instance nfs-client.
      • Tetapkan flag --zone ke us-central1-c.
      • Tetapkan flag --image-project ke debian-cloud.
      • Tetapkan flag --image-family ke debian-11.
      • Tetapkan flag --tags ke http-server,.
      • gcloud compute instances create nfs-client --zone=us-central1-c --image-project=debian-cloud --image-family=debian-11 --tags=http-server,

    Windows

    1. Create a Compute Engine instance. Configure the instance as follows:
      • Name the instance nfs-client.
      • Tetapkan flag --zone ke us-central1-c.
      • Tetapkan flag --image-project ke windows-cloud.
      • Tetapkan flag --image-family ke windows-2012-r2.
      • Tetapkan flag --tags ke http-server,http-server,.
      • gcloud compute instances create nfs-client --zone=us-central1-c --image-project=windows-cloud --image-family=windows-2012-r2 --tags=http-server,http-server,

    Membuat instance Filestore

    Panduan memulai ini menunjukkan cara membuat instance di tingkat layanan regional dengan performa kustom yang diaktifkan. Untuk mengetahui detail tentang cara membuat instance, lihat membuat instance.

    1. Buat instance Filestore. Konfigurasikan instance sebagai berikut:

      • Beri nama instance nfs-server.
      • Tetapkan flag --region ke us-central1.
      • Tetapkan flag --tier ke REGIONAL.
      • Tetapkan flag --performance ke max-iops-per-tb=17000.

      • Tetapkan flag --file-share ke name="vol1",capacity=1TB.

      • Tetapkan flag --network ke name="default".

        gcloud filestore instances create nfs-server --region=us-central1 --tier=REGIONAL --performance=max-iops-per-tb=17000 --file-share=name="vol1",capacity=1TB --network=name="default"
    2. Dapatkan informasi tentang instance Filestore yang Anda buat:

        gcloud filestore instances describe nfs-server --region=us-central1 

      Perintah ini akan menampilkan sesuatu seperti:

          createTime: '2025-02-12T09:15:08.163246004Z'
          customPerformanceSupported: true
          fileShares:
           -capacityGb: '1024'
              name: vol1
          name: projects/yourproject/locations/us-central1/instances/nfs-server
          networks:
          -connectMode: DIRECT_PEERING
            ipAddresses:
             - 10.0.0.2
            network: default
            reservedIpRange: 10.0.0.2/26
          performanceConfig:
            iopsPerTb:
              maxIopsPerTb: '17000'
          performanceLimits:
            maxIops: '17000'
            maxReadIops: '17000'
            maxReadThroughputBps: '417792000'
            maxWriteIops: '5100'
            maxWriteThroughputBps: '139264000'
          protocol: NFS_V3
          state: READY
          tier: REGIONAL

    Salin alamat IP instance untuk digunakan saat memasang fitur berbagi file. Untuk panduan memulai ini, kita menggunakan alamat IP 10.0.0.2.

    Pasang berbagi file Filestore di instance nfs-client

    Linux

    1. Establish an SSH connection to the nfs-client instance:
      gcloud compute ssh nfs-client

    1. Instal NFS dengan menjalankan perintah berikut di jendela terminal nfs-client:

      sudo apt-get -y update &&
      sudo apt-get -y install nfs-common
      
    2. Buat direktori pemasangan di instance nfs-client untuk berbagi file Filestore:

      sudo mkdir /mnt/test
      
    3. Pasang fitur berbagi file ke instance nfs-client dengan perintah mount dengan menentukan alamat IP instance Filestore, nama fitur berbagi file, dan direktori pemasangan yang akan dipasang:

      sudo mount MOUNT-POINT-DIRECTORY /mnt/test
      

      dengan:

      MOUNT-POINT-DIRECTORY adalah jalur ke direktori tempat berbagi file Filestore dipasang. Contoh: 10.0.0.2:/vol1

    4. Opsional: Konfirmasi bahwa berbagi file Filestore telah di-mount:

      df -h --type=nfs

    5. Buat berbagi file dapat diakses dengan mengubah izinnya:

      sudo chmod go+rw /mnt/test
      

    Windows

    Login ke instance nfs-client dan buka Command Prompt sebagai administrator

    1. Buat akun dan tetapkan sandi awal untuk instance nfs-client:

      gcloud compute reset-windows-password nfs-client
      
    2. Konfigurasi instance Anda untuk mengaktifkan koneksi ke port serial:

      gcloud compute instances add-metadata nfs-client --metadata=serial-port-enable=1
      
    3. Masukkan sesi interaktif:

      gcloud compute connect-to-serial-port nfs-client --port=2
      
    4. Pada prompt SAC>, buat channel baru:

      cmd
      

      Channel dengan nama Cmd0001 dibuat.

    5. Hubungkan ke channel:

      ch -sn Cmd0001
      
    6. Masukkan nama pengguna dan sandi instance nfs-client, lalu kosongkan kolom Domain. Anda terhubung ke antarmuka Command Prompt dari instance nfs-client.

    Menginstal klien NFS

    1. Di Command Prompt nfs-client, beralihlah ke Windows PowerShell:

      powershell
      
    2. Instal klien NFS:

      Install-WindowsFeature -Name NFS-Client
      
    3. Mulai ulang instance nfs-client saat diminta:

      restart-computer
      
    4. Pada perintah SAC>, tunggu hingga notifikasi berikut muncul:

      EVENT: The CMD command is now available.

      Kemudian, jalankan perintah cmd dan ch -sn seperti yang diinstruksikan sebelumnya untuk login dan menghubungkan kembali ke instance nfs-client.

    Mengonfigurasi ID pengguna yang digunakan oleh klien NFS

    1. Di Command Prompt, jalankan powershell untuk beralih ke Windows PowerShell.
    2. Di PowerShell, jalankan perintah berikut untuk membuat dua entri registri baru, AnonymousUid dan AnonymousGid:

      New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
          -Name "AnonymousUid" -Value "0" -PropertyType DWORD
      
      New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
          -Name "AnonymousGid" -Value "0" -PropertyType DWORD
      
    3. Mulai ulang layanan klien NFS:

      nfsadmin client stop
      
      nfsadmin client start
      

    Petakan berbagi file vol1 ke instance nfs-client

    1. Keluar dari PowerShell:

      exit
      
    2. Dari Command Prompt, pasang fitur berbagi file ke instance nfs-client dengan perintah mount dengan menentukan alamat IP instance Filestore, nama fitur berbagi file, dan huruf drive yang akan dipasang:

      mount -o mtype=hard 10.0.0.2:/vol1 z:
      

    Membuat file di berbagi file yang di-mount

    Linux

    1. Di jendela terminal nfs-client, buat file bernama testfile dengan menjalankan perintah berikut:

      echo 'This is a test' > /mnt/test/testfile
      
    2. Pastikan file telah dibuat dengan menjalankan perintah berikut dan memverifikasi bahwa testfile ada dalam konten direktori yang ditampilkan:

      ls /mnt/test
      

    Windows

    1. Di jendela Command Prompt instance nfs-client, buat file bernama testfile:

      echo 'This is a test' > Z:\testfile
      
    2. Konfirmasi bahwa file telah dibuat dengan menjalankan perintah berikut:

      dir Z:
      

      dan memverifikasi bahwa testfile ada dalam konten direktori yang ditampilkan.

    Pembersihan

    Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, hapus project Google Cloud yang berisi resource tersebut.

    Menghapus Google Cloud project

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    Hapus instance Filestore

    Hapus instance nfs-server:

    gcloud filestore instances delete nfs-server --zone=us-central1-c
    

    Menghapus instance Compute Engine

    Hapus instance:
    gcloud compute instances delete nfs-client

    Langkah berikutnya