Merge PR #2271: docs: automated local/remote testnet instructions

This commit is contained in:
Zach 2018-09-19 14:30:41 -04:00 committed by Christopher Goes
parent 1167e07b98
commit fcd32c2f3d
6 changed files with 215 additions and 168 deletions

View File

@ -24,8 +24,8 @@ module.exports = {
children: [
"/getting-started/voyager",
"/getting-started/installation",
"/getting-started/full-node",
"/getting-started/create-testnet"
"/getting-started/join-testnet",
"/getting-started/networks"
]
},
{

View File

@ -1,27 +0,0 @@
## Create your Own Testnet
To create your own testnet, first each validator will need to install gaiad and run gen-tx
```bash
gaiad init gen-tx --name <account_name>
```
This populations `$HOME/.gaiad/gen-tx/` with a json file.
Now these json files need to be aggregated together via Github, a Google form, pastebin or other methods.
Place all files on one computer in `$HOME/.gaiad/gen-tx/`
```bash
gaiad init --with-txs -o --chain=<chain-name>
```
This will generate a `genesis.json` in `$HOME/.gaiad/config/genesis.json` distribute this file to all validators on your testnet.
### Export state
To export state and reload (useful for testing purposes):
```
gaiad export > genesis.json; cp genesis.json ~/.gaiad/config/genesis.json; gaiad start
```

View File

@ -0,0 +1,209 @@
# Networks
There are a variety of ways to setup either local or remote networks with automation, detailed below.
All the required files are found in the [networks directory](https://github.com/cosmos/cosmos-sdk/tree/develop/networks) and additionally the `local` or `remote` sub-directories.
## Local Testnet
From the [networks/local directory](https://github.com/cosmos/cosmos-sdk/tree/develop/networks/local):
### Requirements
- [Install gaia](https://cosmos.network/docs/getting-started/installation.html)
- [Install docker](https://docs.docker.com/engine/installation/)
- [Install docker-compose](https://docs.docker.com/compose/install/)
### Build
Build the `gaiad` binary and the `tendermint/gaiadnode` docker image.
Note the binary will be mounted into the container so it can be updated without
rebuilding the image.
```
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
# Build the linux binary in ./build
make build-linux
# Build tendermint/gaiadnode image
make build-docker-gaiadnode
```
### Run a testnet
To start a 4 node testnet run:
```
make localnet-start
```
This command creates a 4-node network using the gaiadnode image.
The ports for each node are found in this table:
| Node ID | P2P Port | RPC Port |
| --------|-------|------|
| `gaianode0` | `26656` | `26657` |
| `gaianode1` | `26659` | `26660` |
| `gaianode2` | `26661` | `26662` |
| `gaianode3` | `26663` | `26664` |
To update the binary, just rebuild it and restart the nodes:
```
make build-linux localnet-stop localnet-start
```
### Configuration
The `make localnet-start` creates files for a 4-node testnet in `./build` by calling the `gaiad testnet` command.
This outputs a handful of files in the `./build` directory:
```tree -L 2 build/
build/
├── gaiacli
├── gaiad
├── gentxs
│   ├── node0.json
│   ├── node1.json
│   ├── node2.json
│   └── node3.json
├── node0
│   ├── gaiacli
│   │   ├── key_seed.json
│   │   └── keys
│   └── gaiad
│   ├── ${LOG:-gaiad.log}
│   ├── config
│   └── data
├── node1
│   ├── gaiacli
│   │   └── key_seed.json
│   └── gaiad
│   ├── ${LOG:-gaiad.log}
│   ├── config
│   └── data
├── node2
│   ├── gaiacli
│   │   └── key_seed.json
│   └── gaiad
│   ├── ${LOG:-gaiad.log}
│   ├── config
│   └── data
└── node3
├── gaiacli
│   └── key_seed.json
└── gaiad
├── ${LOG:-gaiad.log}
├── config
└── data
```
Each `./build/nodeN` directory is mounted to the `/gaiad` directory in each container.
### Logging
Logs are saved under each `./build/nodeN/gaiad/gaia.log`. Watch them stream in with, for example:
```
tail -f build/node0/gaiad/gaia.log
```
### Special binaries
If you have multiple binaries with different names, you can specify which one to run with the BINARY environment variable. The path of the binary is relative to the attached volume. For example:
```
# Run with custom binary
BINARY=gaiafoo make localnet-start
```
## Remote Testnet
The following should be run from the [networks directory](https://github.com/cosmos/cosmos-sdk/tree/develop/networks).
### Terraform & Ansible
Automated deployments are done using [Terraform](https://www.terraform.io/) to create servers on AWS then
[Ansible](http://www.ansible.com/) to create and manage testnets on those servers.
### Prerequisites
- Install [Terraform](https://www.terraform.io/downloads.html) and [Ansible](http://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on a Linux machine.
- Create an [AWS API token](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) with EC2 create capability.
- Create SSH keys
```
export AWS_ACCESS_KEY_ID="2345234jk2lh4234"
export AWS_SECRET_ACCESS_KEY="234jhkg234h52kh4g5khg34"
export TESTNET_NAME="remotenet"
export CLUSTER_NAME= "remotenetvalidators"
export SSH_PRIVATE_FILE="$HOME/.ssh/id_rsa"
export SSH_PUBLIC_FILE="$HOME/.ssh/id_rsa.pub"
```
These will be used by both `terraform` and `ansible`.
### Create a remote network
```
SERVERS=1 REGION_LIMIT=1 make validators-start
```
The testnet name is what's going to be used in --chain-id, while the cluster name is the administrative tag in AWS for the servers. The code will create SERVERS amount of servers in each availability zone up to the number of REGION_LIMITs, starting at us-east-2. (us-east-1 is excluded.) The below BaSH script does the same, but sometimes it's more comfortable for input.
```
./new-testnet.sh "$TESTNET_NAME" "$CLUSTER_NAME" 1 1
```
### Quickly see the /status endpoint
```
make validators-status
```
### Delete servers
```
make validators-stop
```
### Logging
You can ship logs to Logz.io, an Elastic stack (Elastic search, Logstash and Kibana) service provider. You can set up your nodes to log there automatically. Create an account and get your API key from the notes on [this page](https://app.logz.io/#/dashboard/data-sources/Filebeat), then:
```
yum install systemd-devel || echo "This will only work on RHEL-based systems."
apt-get install libsystemd-dev || echo "This will only work on Debian-based systems."
go get github.com/mheese/journalbeat
ansible-playbook -i inventory/digital_ocean.py -l remotenet logzio.yml -e LOGZIO_TOKEN=ABCDEFGHIJKLMNOPQRSTUVWXYZ012345
```
### Monitoring
You can install the DataDog agent with:
```
make datadog-install
```
### Single-node testnet
To create a single node testnet:
```
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
# Clear the build folder
rm -rf ./build
# Build binary
make build-linux
# Create configuration
docker run -v `pwd`/build:/gaiad tendermint/gaiadnode testnet -o . --v 1
# Run the node
docker run -v `pwd`/build:/gaiad tendermint/gaiadnode
```

View File

@ -1,65 +1,6 @@
# Terraform & Ansible
# Networks
Automated deployments are done using [Terraform](https://www.terraform.io/) to create servers on AWS then
[Ansible](http://www.ansible.com/) to create and manage testnets on those servers.
Here contains the files required for automated deployment of either local or remote testnets.
## Prerequisites
- Install [Terraform](https://www.terraform.io/downloads.html) and [Ansible](http://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on a Linux machine.
- Create an [AWS API token](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) with EC2 create capability.
- Create SSH keys
```
export AWS_ACCESS_KEY_ID="2345234jk2lh4234"
export AWS_SECRET_ACCESS_KEY="234jhkg234h52kh4g5khg34"
export TESTNET_NAME="remotenet"
export CLUSTER_NAME= "remotenetvalidators"
export SSH_PRIVATE_FILE="$HOME/.ssh/id_rsa"
export SSH_PUBLIC_FILE="$HOME/.ssh/id_rsa.pub"
```
These will be used by both `terraform` and `ansible`.
## Create a remote network
```
SERVERS=1 REGION_LIMIT=1 make validators-start
```
The testnet name is what's going to be used in --chain-id, while the cluster name is the administrative tag in AWS for the servers. The code will create SERVERS amount of servers in each availability zone up to the number of REGION_LIMITs, starting at us-east-2. (us-east-1 is excluded.) The below BaSH script does the same, but sometimes it's more comfortable for input.
```
./new-testnet.sh "$TESTNET_NAME" "$CLUSTER_NAME" 1 1
```
## Quickly see the /status endpoint
```
make validators-status
```
## Delete servers
```
make validators-stop
```
## Logging
You can ship logs to Logz.io, an Elastic stack (Elastic search, Logstash and Kibana) service provider. You can set up your nodes to log there automatically. Create an account and get your API key from the notes on [this page](https://app.logz.io/#/dashboard/data-sources/Filebeat), then:
```
yum install systemd-devel || echo "This will only work on RHEL-based systems."
apt-get install libsystemd-dev || echo "This will only work on Debian-based systems."
go get github.com/mheese/journalbeat
ansible-playbook -i inventory/digital_ocean.py -l remotenet logzio.yml -e LOGZIO_TOKEN=ABCDEFGHIJKLMNOPQRSTUVWXYZ012345
```
## Monitoring
You can install the DataDog agent with:
```
make datadog-install
```
Doing so is best accomplished using the `make` targets. For more information, see the
[networks documentation](/docs/getting-started/networks.md)

View File

@ -1,76 +0,0 @@
# Local Cluster with Docker Compose
## Requirements
- [Install gaia](https://cosmos.network/docs/getting-started/installation.html)
- [Install docker](https://docs.docker.com/engine/installation/)
- [Install docker-compose](https://docs.docker.com/compose/install/)
## Build
Build the `gaiad` binary and the `tendermint/gaiadnode` docker image.
Note the binary will be mounted into the container so it can be updated without
rebuilding the image.
```
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
# Build the linux binary in ./build
make build-linux
# Build tendermint/gaiadnode image
make build-docker-gaiadnode
```
## Run a testnet
To start a 4 node testnet run:
```
make localnet-start
```
The nodes bind their RPC servers to ports 26657, 26660, 26662, and 26664 on the host.
This file creates a 4-node network using the gaiadnode image.
The nodes of the network expose their P2P and RPC endpoints to the host machine on ports 26656-26657, 26659-26660, 26661-26662, and 26663-26664 respectively.
To update the binary, just rebuild it and restart the nodes:
```
make build-linux
make localnet-stop
make localnet-start
```
## Configuration
The `make localnet-start` creates files for a 4-node testnet in `./build` by calling the `gaiad testnet` command.
The `./build` directory is mounted to the `/gaiad` mount point to attach the binary and config files to the container.
For instance, to create a single node testnet:
```
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
# Clear the build folder
rm -rf ./build
# Build binary
make build-linux
# Create configuration
docker run -v `pwd`/build:/gaiad tendermint/gaiadnode testnet -o . --v 1
#Run the node
docker run -v `pwd`/build:/gaiad tendermint/gaiadnode
```
## Logging
Log is saved under the attached volume, in the `gaiad.log` file and written on the screen.
## Special binaries
If you have multiple binaries with different names, you can specify which one to run with the BINARY environment variable. The path of the binary is relative to the attached volume.