Skip to content

Instantly share code, notes, and snippets.

@mks-m
Forked from romanz/fullnode.md
Last active November 13, 2023 14:26
Show Gist options
  • Save mks-m/e0f1c7555e8f3e7da4a103c2418e82d8 to your computer and use it in GitHub Desktop.
Save mks-m/e0f1c7555e8f3e7da4a103c2418e82d8 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 150GB EBS (General-Purpose SSD) volume for blockchain storage to /dev/sdf.

The pricing would be ~$15/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 /home/ubuntu/.bitcoin ext4 noatime,nodiratime,data=writeback,barrier=0,errors=remount-ro 0 0
/opt/swapfile swap swap defaults 0 0

Mount them using:

sudo mount -a

If you're getting an error when mounting a volume that you've created manually, you need to create a filesystem on it (and optionally tune it):

sudo mkfs.ext4 /dev/xvdf
sudo tune2fs -O has_journal -o journal_data_writeback /dev/xvdf
sudo tune2fs -O dir_index /dev/xvdf
sudo e2fsck -D /dev/xvdf
  • 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
#verify that subnet matches eth0 by running ifconfig
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
}
  • Add the following to crontab by running crontab -e:
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment