This is a repository containing scripts and automation for NEAR StakeWars part3:
You can find the whole deployment guide at my blog:
https://blog.gritsly.link/stake-wars-challenge-005/
-
Terraform : defined three resources - two main nodes and one monitoring node using Hetzner cloud
-
Ansible: defined multiple playbooks:
- setup_user.yml - connects to root and sets up non-root sudo user on all servers
- setup_node.yml - deploys all required packages and configurations for running the node including prometheus exporter. User then must do the near-cli parts manually (login, create pool, etc.)
- setup_monit.yml - deploys prometheus and grafana on monit node.
- configure_postfix.yml - configures postfix for use with amazon SES service for sending emails.
- generate_keys.yml - generates validator_key.json and node_key.json for active and backup nodes and syncs all to both
- start_active_node.yml - starts validating on node defined in ansible inventory as "active"
- stop_backup_node.yml - stops validating on node defined in ansible inventory as "backup"
- hardfork.yml - redownloads nearcore, genesis etc. Automates hard fork of shardnet
- newbinary.yml - only recompiles nearcore to new commit and backs up old version
Disclaimer! If you want to make a failover then the right order of running operations is:
- Switch nodes in ansible inventory
- Run stop_backup_node.yml
- Run start_active_node.yml
- Manually start neard service on backup node (after checking if everything went well)
- Create a Hetzner account, generate an API key through cloud panel.
- Create a 'terraform.tfvars' file with the API key and hostname (it will be used for PTR record):
hcloud_token = "xxxxxxxxxxxxxxxxxxxxxxx"
- Run Terraform
- Populate ansible/hosts file with your variables
- Run ansible playbooks:
ansible-playbook -i hosts setup_user.yml
ansible-playbook -i hosts setup_node.yml --ask-become-pass
ansible-playbook -i hosts setup_monit.yml --ask-become-pass
ansible-playbook -i hosts configure_postfix.yml --ask-become-pass #optional
ansible-playbook -i hosts generate_keys.yml --ask-become-pass
- Proceed to initialize stake pool etc.
- Run another playbook:
ansible-playbook -i hosts start_active_node.yml --ask-become-pass
- Check up on your node - journalctl, email sending, set up grafana dashboards etc.