Google Cloud Servers
Sources:
- GCloud
- GCloud: Install GPU drivers
Note: I find Google Cloud too be over complicated and the billing is insane. So I do not recommend using it.
Intro
GCloud offers 300 USD credits for first year.
->Source
If you're an education account, i.e., your email account ends with .edu
, then you'll get additional 100 USD credis.
So, I got 400 USD credits.
Now I'll show you how to rent a GPU server on GCloud and config it.
-->Control Panel for Google Cloud Instances.
Rent A Server
Go to Marketplace, choose your desired config.
Remember to select "GPU".
Now you can create your instance (your server based on this configuration).
Config SSH Connection
Now you can use to connect to your server. But many people prefer to use ssh (or "OpenSSH").
Normally, following thses instructions will suffice. However, in GCloud, you need to do two things in advance:
1. Authentication
Install the Google Cloud CLI, then
initialize it by running the following command:
1
gcloud init
If you installed the gcloud CLI previously, make sure you have the latest version by running
gcloud components update
.During initialization, you must choose your
Zone
the same as the one of your VM. E.g., if your VM's zone isus-central-1
, then your config in your authentication should be it as well1
2
3
4
5
6
7> gcloud init Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [default] are:
compute:
region: us-central1
zone: us-central1-a # The same!
<...>
2. Choose an access method
Choose an access method
It's recommended to choose OS Login. We need to set OS Login at the instance level (You can also set it at the project level but it's more complicated).
Know how to set custom data at the instance level (->Source): Use the
project-info add-metadata
command.1
gcloud compute project-info add-metadata --metadata=KEY=VALUE
Replace the following:
KEY
: the name of your metadata keyVALUE
: the value stored for this key
Example
For example to set two new entries
foo=bar
andbaz=bat
on a project, run the following command:1
2gcloud compute project-info add-metadata \
--metadata=foo=bar,baz=batYou can optionally specify one or more files from which to read metadata by using the
--metadata-from-file
flag.Now plugin the parameters to enable OS Login (->Source):
- Key:
enable-oslogin
- Value:
TRUE
Briefly
1
gcloud compute project-info add-metadata --metadata=enable-oslogin=TRUE
- Key:
3. Establish SSH Connection
Connect to Linux VMs
Connect to the VM by running the following command:
1 | ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP |
Replace the following:
PATH_TO_PRIVATE_KEY
: the path to the private SSH key file that corresponds to the public key you added to the VM.USERNAME
: your username. If you manage your SSH keys in metadata (We don't use this method), the username is what you specified when you created the SSH key. For OS Login accounts, the username is defined in your Google profile. For example,cloudysanfrancisco_example_com
orcloudysanfrancisco
. You can view your username after finishing the authentication.EXTERNAL_IP
: the external IP address of the VM.
To login witouout need to enter passeord, you can upload your ssh public key to the server:
1 | ssh-copy-id PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP |
Install Nvidia Driver and CUDA
Install GPU drivers
You can also refer to Pytorch GPU Setup Guide tough the instructions here are easier.
First, select and install a CUDA toolkit that supports the minimum driver that you need.
Then install the Nvidia driver:
Ensure that Python 3 is installed on your operating system.
Download the installation script.
1
curl https://raw.githubusercontent.com/GoogleCloudPlatform/compute-gpu-installation/main/linux/install_gpu_driver.py --output install_gpu_driver.py
Run the installation script.
1
sudo python3 install_gpu_driver.py
The script takes some time to run. It might restart your VM. If the VM restarts, run the script again to continue the installation.
Verify the installation. See Verifying the GPU driver install.
This should be OK. There's no need to reboot your system.
Assign a Static IP
By default, the instance will have a new enternal IP each time it starts. For convinence, you can reserve (aka, buy) a static external IP and attach to the instance.
- Reserve a new static external IP address
- Change or assign an external IP address to an existing VM
Others
- Add disk storage of VM.
What is OSLogin
https://cloud.google.com/compute/docs/oslogin
So, with OSLogin, a weird thing happens. My username after ssh is lykuni_ucdavis_edu
:
1 | $ whoami |
However, I can't search this account name in the /etc/passwd
!
Billing account
Close your billing account and remove your payment method