Skip to content

Instantly share code, notes, and snippets.

@romanz
Last active March 2, 2023 12:38
  • Star 51 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save romanz/17ff716f13a34df49ff4 to your computer and use it in GitHub Desktop.
Bitcoin Full Node on AWS Free Tier

Bitcoin Full Node on AWS Free Tier

Provisioning

  • Launch one T2 micro instance, using Ubuntu 14.04 LTS AMI.
  • Open SSH and Bitcoin Protocol TCP ports: 22, 8333.
  • Attach 40GB EBS (General-Purpose SSD) volume for blockchain storage to /dev/sdf.

The pricing should be ~3$ for the first year (assuming 30GB upload per month). See here for more details.

Installing

(based on the following reddit post)

  • Run as superuser:
$ sudo dd if=/dev/zero of=/opt/swapfile bs=1M count=1024
$ sudo mkswap /opt/swapfile
$ sudo swapon /opt/swapfile 
$ mkdir ~/.bitcoin/
$ sudo add-apt-repository -y ppa:bitcoin/bitcoin
$ sudo apt-get update -y
$ sudo apt-get install bitcoind -y
  • Add the following to /etc/fstab configuration:
# /dev/xvdf is EXT4 filesystem under /home/ubuntu/.bitcoin
/dev/xvdf /home/ubuntu/.bitcoin ext4 defaults 0 0
/opt/swapfile swap swap defaults 0 0

Mount them using:

sudo mount -a
  • Torrent bootstrap.dat for speed, as described here.
  • Use the following configuration file (.bitcoin/bitcoin.conf):
server=1
daemon=1
connections=40
rpcuser=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
rpcpassword=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
disablewallet=1
  • Use the following traffic control script (.bitcoin/utils/tc.sh) for bandwidth throttling:
#network interface on which to limit traffic
IF="eth0"
#limit of the network interface in question
LINKCEIL="1gbit"
#limit outbound Bitcoin protocol traffic to this rate
LIMIT="200kbit"
#defines the address space for which you wish to disable rate limiting
LOCALNET="172.31.0.0/16"

#delete existing rules
tc qdisc del dev ${IF} root

#add root class
tc qdisc add dev ${IF} root handle 1: htb default 10

#add parent class
tc class add dev ${IF} parent 1: classid 1:1 htb rate ${LINKCEIL} ceil ${LINKCEIL}

#add our two classes. one unlimited, another limited
tc class add dev ${IF} parent 1:1 classid 1:10 htb rate ${LINKCEIL} ceil ${LINKCEIL} prio 0
tc class add dev ${IF} parent 1:1 classid 1:11 htb rate ${LIMIT} ceil ${LIMIT} prio 1

#add handles to our classes so packets marked with <x> go into the class with "... handle <x> fw ..."
tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10
tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11

#limit outgoing traffic to and from port 8333. but not when dealing with a host on the local network
iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 8333 ! -d ${LOCALNET} -j MARK --set-mark 0x2
iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 8333 ! -d ${LOCALNET} -j MARK --set-mark 0x2
  • Use the following logrotate script (.bitcoin/utils/rotate.conf):
"/home/ubuntu/.bitcoin/debug.log" {
        daily
        missingok
        rotate 5
        copytruncate
        compress
}
  • Use the following crontab:
@reboot bitcoind
@reboot sudo /home/ubuntu/.bitcoin/utils/tc.sh
@daily logrotate /home/ubuntu/.bitcoin/utils/logrotate.conf

Testing

  • Run bitcoin server and watch its log file:
bitcoind
tail -F ~/.bitcoin/debug.log
@pejrak
Copy link

pejrak commented Oct 9, 2014

I have added a line(https://gist.github.com/pejrak/2b1cf4366ceb87968b68) for mkfs on xvdf before mounting, since I was getting errors:

sudo mount -a
mount: wrong fs type, bad option, bad superblock on /dev/xvdf,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

@nobodhi
Copy link

nobodhi commented Nov 16, 2017

bootstrap.dat is no longer used

@jaybxyz
Copy link

jaybxyz commented Nov 21, 2017

Is attaching 40GB EBS (General-Purpose SSD) volume to EC2 instance enough?

From my research, the blockchain size is 168.51 GB at this time (2017.11.21).

@ckozus
Copy link

ckozus commented Nov 22, 2017

@jaybkim1 That seems to be the case, the blockchain is way bigger now.

I'll have to start from scratch with a new volume since I didn't planned for that big info.

@Matt-Jensen
Copy link

Matt-Jensen commented Mar 16, 2018

Use the following logrotate script (.bitcoin/utils/rotate.conf):

Should be: .bitcoin/utils/logrotate.conf to match the crontab.

Also in bitcoin.conf:

connections=40

Is now: maxconnections=40

@ofarukcaki
Copy link

How 40gb storage is enough for blockchain? the size is about 180gb now

@igorgue
Copy link

igorgue commented Jun 11, 2018

@ofarukcaki How's the first comment on Oct 9, 2014 not 2017?

@inherithandle
Copy link

Now I feel bad it costs $19.25 a month or $30 without a free tier

@krtschmr
Copy link

@inherithandle yeah, i wondered about 3$ a month. lol

@gg2001
Copy link

gg2001 commented Mar 26, 2019

Would mounting S3 be cheaper than using EBS? Would using a hard drive also be cheaper as well?

@kikoncuo
Copy link

BTW you can run the node in 30GB with prune activated

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