Solution to a recruitment task for Statis.im.
Create N
geth nodes in AWS that will mine ether in Ropsten and it will be easy to scale the number of nodes and monitor them.
Monitoring can be ad hoc, no need to get deep into visualization/graphs.
Document your solution so anyone can scale this up given access to the machine.
NOTE: Only CPU mining is required.
In order to create the mining infractructure you will need to provide the required variables.
You can do that by creating a terraform/terraform.tfvars
file.
Example:
pub_key_path = "~/.ssh/id_rsa.pub"
private_key_path = "~/.ssh/id_rsa"
# name of key pair to create in AWS for SSH access
key_name = "miner-admin"
# domain to which entries for created hosts should be added
domain = "mydomain.com"
# prefix for domain before hostnames, ex: miner-01.geth.mydomain.com
env = "geth"
# ethereum address for receiving mining rewards
etherbase = "CHANGE ME PLZ"
# type of instance used for collecting metrics
sentry_params {
type = "t2.medium"
}
# number and type of miner instances to start
miner_params {
type = "t2.small"
count = "2"
}
Once that exists you can simply go into the terraform
directory and run terraform plan
and then terraform apply
if you like what you see.
To configure miner hosts separately you can run ansible
:
cd ansible && ansible-playbook miner.yml -e "etherbase=$CHANGE_ME" -e "monitor_host=$HOSTNAME"
Same can be done for the sentry host:
cd ansible && ansible-playbook sentry.yml -e "monitor_host=$HOSTNAME"
The repo is divided into two sections:
terraform
- Contains configuration that creates the AWS infrastructureansible
- Contains provisioning for mining instances in AWS.
There are two types of hosts this creates:
miners
- Hosts that rungeth
for mining.sentry
- Hosting Graphite and Grafana for metrics.
The miners are mining in Ropsten Proof-of-Work chain using CPU. This is inefficient but good enough for a test.
The sentry is there to collect metrics and provide a UI for exploring them.
Using terraform
4 types of resources are created:
aws_security_group
- One for SSH access and one for exposing30303
port for Ethereum nodes.aws_key_pair
- RSA key pair used to give remote SSH access to the created instances.aws_instance
- Instances that will run the Geth processes for mining.aws_route53_record
- Route53 DNS entries for easier access to the instances.
In the modules
directory reside files defining these resources.
The main configuration files are:
terraform/main.tf
- Defines which modules to run and provisioning afterwards.terraform/variables.tf
- Requried and optional variables for infrastructure. Some provided byterraform.tfvars
.terraform/data.tf
- Pulls information from AWS, in this case about AMI and Route53 zone ID.terraform/output.tf
- Defines what informationterraform
will return after successful run.
NOTE: If you wish to run ansible
separately comment out the null_resource
section in terraform/main.tf
.
Using ansible
provisioned hosts are configured for their respective roles using playbooks:
ansible/miner.yml
- Configures miners to rungeth
and send metrics.ansible/sentry.yml
- Configures sentry to run Graphite and Grafana
A set of roles configures the necessary services:
ansible/roles/common
- Installs common utilities likehtop
ornetstat
.ansible/roles/docker
- Installs Docker to enable use of containersansible/roles/miner
- Configuresgo-ethereum
clientansible/roles/monitoring-client
- Configures netdata for monitoring minersansible/roles/monitoring-server
- Configures Graphite and Grafana
- SSL certificates for web services like Grafana
- Auth for netdata running on miners
- Backups of Grafana dashboards
- Backups of
geth
blockchain to reduce sync time - Find why metrics not starting with
eth
don't get saved in graphite
- Infrastructure
- Provisioning
- Terraform Inventory
- Mining
- Monitoring
- Metrics