How to run geth at 512Mb RAM Digital Ocean droplet

January 31st 2017
Author profile picture

@PeterPorobovPeter Porobov

Run geth with just 512Mb of RAM

This is how I run full geth node alongside 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 512 Mb RAM droplet and attach at least 20 GB volume to it (DO’s block storage). 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 is not enough. I had one kill with it within 2 mln blocks.

$ 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.

Digital Ocean’s instructions on swap are 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. So we gonna create a symbolic link.

$ 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

And add stats to enjoy even more.

Add a cron task through:

$ crontab -e

At the bottom add the following task. It will write your attached volume usage to the disk.log file every day at 4 A.M.

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 of 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

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.

Comments, questions, improvements?

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

UPDT: Had two crashes: on 17th and 25th of March. So I highly recommend monitoring geth with monit or other software.



The Noonification banner

Subscribe to get your daily round-up of top tech stories!