How to setup your Pocket Relay Node on AWS
We at Pocket Network are proud to announce that our first Ethereum Relay Node, RED, is up and serving Relays to the Rinkeby Testnet. Why RED you ask? Because all of our Relay Nodes will be named after the Pokemon main series games (RED, BLUE, YELLOW, etc.).
This guide will serve as a quick-start on how to setup your own node on AWS and start relaying transactions right away.
Get an AWS Account
Just head over to the AWS Homepage and sign up for an account. If you’re just trying stuff out, you can opt for the AWS Free Tier Plan.
Create a Security Group
A security group is a set of rules on how inbound and outbound networking to your EC2 Instance behaves.
For our Relay Node we will need the following Inbound rules:
A little explanation for each of these:
- TCP Port 80: The HTTP rule, so other computers can connect on the HTTP port to submit relays to our Node.
- TCP Port 22: The SSH rule, so we can connect over SSH to our Node.
- TCP Port 30303: This is one of the ports that Geth (ethereum node) uses to talk to other Ethereum nodes.
- UDP Port 30303: This is the other port that Geth uses to talk to other Ethereum nodes.
And the following Outbound Rules:
We want our server to be able to respond to any other computer talking to it, so we have the All Traffic rule with 0.0.0.0/0 as our destination. For more on how EC2 Security Groups work, head over to this link for a guide on it.
Launch and connect to your Linux EC2 Instance
AWS has a great guide on how to launch your own Linux instance, which you can check out here. For the rest of this guide I’m assuming you chose Ubuntu Server 16.04 as your server OS. During the Launch Wizard remember to select the Security Group you created in the previous step.
EC2 instances are not accesed by username/password, instead AWS provides you with a *.pem
file. To connect to your instance, just use the ssh
command if you’re in a *Nix environment, by using the *.pem
file you provided to you in the AWS EC2 Portal:
ssh -i /path/to/my-instance.pem ubuntu@<ec2 instance public IP>
You can also use a SSH client like Putty and provide the *.pem
file in the settings to authenticate.
Install and configure Go Ethereum (Geth)
For a basic installation of Geth you can follow the official guide. Now we want to configure Geth to run as a service in our EC2 Instance, and for that we will use Monit. After you finish up installing Geth, follow these steps to configure Monit:
- Install Monit:
sudo apt-get install monit
- Create and save the Monit service script:
sudo vim /etc/monit/conf-enabled/geth
with the following content:
# GETH
CHECK PROCESS geth MATCHING "[g]eth.*fast"
start program = "/bin/bash -c 'geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --syncmode fast --unlock <your ETH address> --password <password file path> > /dev/null 2> <log file path>'"
stop program = "/bin/bash -c 'kill -HUP $(ps aux | grep '[g]eth' | awk '{print $2}')'"
if not exist then alert
if not exist then restart
You need to customize the script with the following 3 values:
- Your ETH address: The Ethereum address that owns this node.
- Password file path: An non-encrypted file with the Ethereum account password.
- Log file path: The log file to which Geth will do it’s ouput.
To start Geth you just need to execute the following command sudo monit start geth
and to stop it sudo monit stop geth
and to verify it’s running succesfullysudo monit status
Register your node on the Pocket Network
We have created the Pocket Dashboard to help with this part of the process, just head over there and register your Node, you will need your registration information afterwards to complete your setup.
Install and configure Pocket Node (pocket-node)
We have created Pocket Node as a client of the Pocket Network, and its main functions are:
- Relay incoming transactions to their appropriate destinations.
- Interface with the Pocket Network smart contracts.
We have a guide on how to install and configure the Pocket Node application in the project’s Github page.
To run pocket-node
in the background we will be using the following command:
nohup pocket-node start &> ~/logs/pocket-node.log &
This will start the pocket-node
application on the default port (3000).
Install and configure Nginx as a reverse proxy
For this guide we will be using Nginx as our reverse proxy, but those of you who prefer Apache are welcome to use it instead. First start by installing Nginx:
sudo apt-get install nginx
Then create the following Nginx site configuration using: sudo vim /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://localhost:<pocket node app port>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Basically we’re telling Nginx to:
- Forward all requests from the root of the domain to our Pocket Node app running in the port you specified (default is 3000).
- Set some headers for our Pocket Node app to parse.
- To bypass the Proxy Cache.
After saving your configuration file, just restart Nginx:
sudo systemctl restart nginx
Connecting to your Pocket Relay Node
Now time to send some relays! Just follow our guide on how to connect to your Node. You can query your Node information as well as submitting a transaction to whatever networks your Node supports.
Keep in touch
If you need further help or just wanna reach out to :
Gotta relay ’em all!,
Luis