Skip to content

Instantly share code, notes, and snippets.

@porobov

porobov/geth.md Secret

Created January 31, 2017 12:20
Show Gist options
  • Save porobov/b02ae998b69efac4cd5d1710fb3858d7 to your computer and use it in GitHub Desktop.
Save porobov/b02ae998b69efac4cd5d1710fb3858d7 to your computer and use it in GitHub Desktop.

How to run geth at 512Mb RAM Digital Ocean droplet?

This is how I run full geth node and TheMillionEtherHomepage.com python back-end on a low-cost Digital Ocean (DO) Ubuntu droplet. With this config I'm in full sync (currently at block 3097083) with no crashes at all.

Create a droplet.

Buy a 512Mb RAM droplet and attach at least 20GB volume (DO's block storage) to it. Just click Create droplet button and DO will guide you through.

Setup a swapfile

I tried to run geth with no swap, but it crashes in about 10-30 minutes after start. Here I'm setting up 2 Gigs of swap. One gig should be enough though, but I'm a paranoid... And I bet you too...

$ sudo fallocate -l 2G /swapfile  # Creates a file of a preallocated size
$ sudo chmod 600 /swapfile  # adjust the permissions
$ sudo mkswap /swapfile  # set up the swap space
$ sudo echo '/swapfile none swap sw 0 0' >> /etc/fstab  # enable swap
$ sudo echo 'vm.swappiness=30' >> /etc/sysctl.conf  # optional. The default swappiness (i.e. system willingness to use swap) is 60. You can set it to 30 if you care. As swap gradually kills SDDs. In my experience 30 is enough and it feels more eco-friendly.
$ sudo /sbin/shutdown -r now  # reboot
$ free -mh  # now you should see your swap usage.

This is from standard Digital Ocean's instructions available here: How To Add Swap on Ubuntu 14.04

Install geth

$ sudo apt-get install software-properties-common  
$ sudo add-apt-repository -y ppa:ethereum/ethereum  
$ sudo apt-get update  
$ sudo apt-get install geth  

Official Installation Instructions for Ubuntu

Put geth's database to the block storage volume

You can run geth with --datadir "/mnt/your-volume-name/ethereum/" key (Geth Command Line Options), but I find the following approach simpler as you may have other software using the same ~/.ethereum folder by default.

$ sudo mkdir /mnt/your-volume-name/ethereum  # create an empty directory 
$ sudo chown username:username /mnt/your-volume-name/ethereum/  # set directory owner to username (you)
$ sudo chmod 775 /mnt/your-volume-name/ethereum/  # set directory permissions
$ ln -s /mnt/your-volume-name/ethereum/ ~/.ethereum  # create symbolic link from your home directory to the volume

Run geth and enjoy!

$ geth --fast --cache=16
$ ls /mnt/your-volume-name/ethereum/  # see if geth is writing to the rigth place

Add some stats to enjoy even more.

Add a cron task:

$ crontab -e

Add at the bottom add the following task. It will write your attached volume usage to the disk.log file.

0 4 * * * echo `date` `df -m | grep sda` >> /home/username/disk.log

And in a couple of days check the logs to see your disk usage stats. If you see disk space running low, it is time to think about buying up more space.

$ tail /home/username/disk.log
Sun Jan 22 04:00:01 UTC 2017 /dev/sda 20031 14582 4410 77% /mnt/volume
Mon Jan 23 04:00:01 UTC 2017 /dev/sda 20031 14809 4182 78% /mnt/volume
Tue Jan 24 04:00:01 UTC 2017 /dev/sda 20031 15041 3950 80% /mnt/volume
Wed Jan 25 04:00:01 UTC 2017 /dev/sda 20031 15294 3698 81% /mnt/volume
Thu Jan 26 04:00:01 UTC 2017 /dev/sda 20031 15522 3470 82% /mnt/volume
Fri Jan 27 04:00:02 UTC 2017 /dev/sda 20031 15739 3253 83% /mnt/volume
Sat Jan 28 04:00:01 UTC 2017 /dev/sda 20031 15956 3036 85% /mnt/volume
Sun Jan 29 04:00:01 UTC 2017 /dev/sda 20031 16161 2830 86% /mnt/volume
Mon Jan 30 04:00:01 UTC 2017 /dev/sda 20031 16041 2950 85% /mnt/volume
Tue Jan 31 04:00:01 UTC 2017 /dev/sda 20031 16271 2721 86% /mnt/volume

And set up monit to monitor Geth and enjoy even when you go to sleep.

To feel safer you can set up monit to monitor Geth status. It will restart geth if anything happens to it and inform you by email.

If there is no link here, it means that I'm still writing the article. Will add it here soon.

Comments, questions, improvements?

You can post them here or at the stackexchange thread: How to run geth at 512Mb RAM Digital Ocean droplet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment