Tuesday, August 6, 2013

Google Compute Engine: GCE Cheatsheet

I will keep this page posted with new useful stuff. Nice reference to work with GCE.



Install gcutil:

wget https://google-compute-engine-tools.googlecode.com/files/gcutil-1.8.2.tar.gz
tar xzvpf gcutil-1.8.2.tar.gz -C $HOME



Add gcutil to your system path (assuming you extracted gcutil to $/HOME):

echo -e "\nexport PATH=\$PATH:\$HOME/gcutil-1.8.2" > $HOME/.bashrc
source $HOME/.bashrc



SSH into your VM:


(note zone = "us-central2-a" in this case)



gcutil --service_version="v1beta15" --project="<my_project>" ssh  --zone="us-central2-a" "<my_instance>"

Enable Pinging By Allowing ICMP thorught the Firewall:
$ gcutil --project=myproject addfirewall icmpfirewall --allowed=icmp # allow ICMP traffic
copy a file from local machine to your GCE instance:


# Copy local file named readme.txt up to my instance named myinst
$ gcutil --project=my-project push myinst readme.txt /home/user/.
Install a package (apache in this example) on your GCE instance:

Debian linux:

$ sudo apt-get install apache2
CenOS linux:
$ sudo yum install httpd
Running a process after logout with GNU Screen:


after we've ssh'ed into our GCE VM, we will need to:
1.Install GNU screen if you don't already have it: 
Debian linux:

sudo apt-get install screen
CenOS linux:
sudo yum install screen

2. type "screen". this will open up a new screen - kind of similar in look & feel to what "clear" would result in.
3. run the process (e.g.: ./my_cool_program.sh)
4. type: Ctrl + A, and then Ctrl + D. This will detach your screen session but leave your processes running!
5. feel free to close the SSH terminal. whenever you feel like it, ssh back into your GCE VM, and type screen -r to resume your previously detached session.

allow HTTP traffic to all instances on the default network:
gcutil addfirewall web --network=default --allowed="tcp:http" --project=<project-id>

Set a Default Project (can save you some typing if you're working with one main project):
$ gcutil getproject --project=myProject --cache_flag_values

No comments:

Post a Comment