Create a Filestore instance by using the gcloud CLI
This quickstart shows you how to get up and running quickly with Filestore using the Google Cloud CLI. In this quickstart, you learn how to:
- Create a Filestore instance.
- Mount the file share from that instance on a Compute Engine client VM.
- Create a file on the mounted file share.
- Delete the Filestore instance.
Before you begin
Select or create a project:
Create a project
gcloud projects create project-id
Select a project
gcloud config set project project-id
where project-id is the ID of the Google Cloud project.
Make sure that billing is enabled for your project. Learn how to enable billing.
Install and initialize the gcloud CLI.
If you already have the gcloud CLI installed, run the following command to update it:
gcloud components update
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.
Create a Compute Engine VM to be the client
Linux
-
Create a Compute Engine instance. Configure the instance as follows:
-
Name the instance
nfs-client
. -
Set the
--zone
flag tous-central1-c
. -
Set the
--image-project
flag todebian-cloud
. -
Set the
--image-family
flag todebian-11
. -
Set the
--tags
flag tohttp-server,
.
gcloud compute instances create nfs-client --zone=us-central1-c --image-project=debian-cloud --image-family=debian-11 --tags=http-server,
-
Name the instance
Windows
-
Create a Compute Engine instance. Configure the instance as follows:
-
Name the instance
nfs-client
. -
Set the
--zone
flag tous-central1-c
. -
Set the
--image-project
flag towindows-cloud
. -
Set the
--image-family
flag towindows-2012-r2
. -
Set the
--tags
flag tohttp-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,
-
Name the instance
Create a Filestore instance
Create a Filestore instance. Configure the instance as follows:
- Name the instance
nfs-server
. - Set the
--zone
flag tous-central1-c
. - Set the
--tier
flag toBASIC_HDD
. - Set the
--file-share
flag toname="vol1",capacity=1TB
. - Set the
--network
flag toname="default"
.
gcloud filestore instances create nfs-server --zone=us-central1-c --tier=BASIC_HDD --file-share=name="vol1",capacity=1TB --network=name="default"
- Name the instance
Get information about the Filestore instance you created:
gcloud filestore instances describe nfs-server --zone=us-central1-c
The command returns something like:
createTime: '2019-10-11T17:28:23.340943077Z' fileShares: - capacityGb: '1024' name: vol1 name: projects/yourproject/locations/us-central1-c/instances/nfs-server networks: - ipAddresses: - 10.0.0.2 network: default reservedIpRange: 10.0.0.0/29 state: READY tier: BASIC_HDD
Copy down the IP address of the instance for use when mounting the file share. For this quickstart, we use the IP address
10.0.0.2
.
Mount the Filestore file share on the nfs-client
instance
Linux
-
Establish an SSH connection to the
nfs-client
instance:gcloud compute ssh nfs-client
Install NFS by running the following commands on the terminal window of
nfs-client
:sudo apt-get -y update && sudo apt-get -y install nfs-common
Create a mount directory on the
nfs-client
instance for the Filestore file share:sudo mkdir /mnt/test
Mount the file share to the
nfs-client
instance with themount
command by specifying the IP address of the Filestore instance, the name of the file share, and the mount directory to mount to:sudo mount 10.0.0.2:/vol1 /mnt/test
Make the file share accessible by changing its permissions:
sudo chmod go+rw /mnt/test
Windows
Sign in to the nfs-client
instance and open a Command Prompt as an administrator
Create an account and set an initial password for the
nfs-client
instance:gcloud compute reset-windows-password nfs-client
Configure your instance to enable connecting to serial ports:
gcloud compute instances add-metadata nfs-client --metadata=serial-port-enable=1
Enter an interactive session:
gcloud compute connect-to-serial-port nfs-client --port=2
At the
SAC>
prompt, create a new channel:cmd
A channel with the name
Cmd0001
is created.Connect to the channel:
ch -sn Cmd0001
Enter the username and password of the
nfs-client
instance and leave theDomain
field blank. You are connected to theCommand Prompt
interface of thenfs-client
instance.
Install NFS client
In the
Command Prompt
ofnfs-client
, switch toWindows PowerShell
:powershell
Install the
NFS
client:Install-WindowsFeature -Name NFS-Client
Restart the
nfs-client
instance when prompted:restart-computer
At the
SAC>
prompt, wait for the following notification to appear:EVENT: The CMD command is now available.
Then, run the
cmd
andch -sn
commands as previously instructed to sign in and reconnect to thenfs-client
instance.
Configure the user ID used by the NFS client
- In the Command Prompt, run
powershell
to switch to Windows PowerShell. In
PowerShell
, run the following commands to create two new registry entries,AnonymousUid
andAnonymousGid
: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
Restart the NFS client service:
nfsadmin client stop nfsadmin client start
Map the vol1
file share to the nfs-client
instance
Exit
PowerShell
:exit
From
Command Prompt
, mount the file share to thenfs-client
instance with themount
command by specifying the IP address of the Filestore instance, the name of the file share, and the drive letter to mount to:mount -o mtype=hard 10.0.0.2:/vol1 z:
Create a file on the mounted file share
Linux
In the
nfs-client
terminal window, create a file namedtestfile
by running the following command:echo 'This is a test' > /mnt/test/testfile
Confirm the file was created by running the following command and verifying that
testfile
is in the directory contents returned:ls /mnt/test
Windows
In the Command Prompt window of the
nfs-client
instance, create a file namedtestfile
:echo 'This is a test' > Z:\testfile
Confirm the file was created by running the following command:
dir Z:
and verifying that
testfile
is in the directory contents returned.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.
Delete the Google Cloud project
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Delete the Filestore instance
Delete the nfs-server
instance:
gcloud filestore instances delete nfs-server --zone=us-central1-c
Delete the Compute Engine instance
Delete the instance:gcloud compute instances delete nfs-client
What's next
- Read the Filestore Overview to learn more about the basics of Filestore.
- Set up a Filestore instance on your own by following the instructions at Creating Instances.
- Read Access Control to learn how to control access to Filestore operations and the resources on an instance.
- See how to copy data to or from a Filestore instance.
- See how to transfer large datasets from Cloud Storage to Filestore.