mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #254 from bigchaindb/deploy-clients-on-aws
Deploy clients on AWS
This commit is contained in:
commit
4a6c3ba891
1
.gitignore
vendored
1
.gitignore
vendored
@ -72,3 +72,4 @@ target/
|
|||||||
deploy-cluster-aws/conf/rethinkdb.conf
|
deploy-cluster-aws/conf/rethinkdb.conf
|
||||||
deploy-cluster-aws/hostlist.py
|
deploy-cluster-aws/hostlist.py
|
||||||
deploy-cluster-aws/confiles/
|
deploy-cluster-aws/confiles/
|
||||||
|
deploy-cluster-aws/client_confile
|
||||||
|
148
deploy-cluster-aws/awsdeploy.sh
Executable file
148
deploy-cluster-aws/awsdeploy.sh
Executable file
@ -0,0 +1,148 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# The set -e option instructs bash to immediately exit
|
||||||
|
# if any command has a non-zero exit status
|
||||||
|
set -e
|
||||||
|
|
||||||
|
USAGE="usage: ./awsdeploy.sh <number_of_nodes_in_cluster> <pypi_or_branch> <servers_or_clients>"
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo $USAGE
|
||||||
|
echo "No first argument was specified"
|
||||||
|
echo "It should be a number like 3 or 15"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
NUM_NODES=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
echo $USAGE
|
||||||
|
echo "No second argument was specified, so BigchainDB will be installed from PyPI"
|
||||||
|
BRANCH="pypi"
|
||||||
|
else
|
||||||
|
BRANCH=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$3" ]; then
|
||||||
|
echo $USAGE
|
||||||
|
echo "No third argument was specified, so servers will be deployed"
|
||||||
|
WHAT_TO_DEPLOY="servers"
|
||||||
|
else
|
||||||
|
WHAT_TO_DEPLOY=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ("$WHAT_TO_DEPLOY" != "servers") && ("$WHAT_TO_DEPLOY" != "clients") ]]; then
|
||||||
|
echo "The third argument, if included, must be servers or clients"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for AWS private key file (.pem file)
|
||||||
|
if [ ! -f "pem/bigchaindb.pem" ]; then
|
||||||
|
echo "File pem/bigchaindb.pem (AWS private key) is missing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for the confiles directory
|
||||||
|
if [ ! -d "confiles" ]; then
|
||||||
|
echo "Directory confiles is needed but does not exist"
|
||||||
|
echo "See make_confiles.sh to find out how to make it"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Auto-generate the tag to apply to all nodes in the cluster
|
||||||
|
TAG="BDB-"$WHAT_TO_DEPLOY"-"`date +%m-%d@%H:%M`
|
||||||
|
echo "TAG = "$TAG
|
||||||
|
|
||||||
|
# Change the file permissions on pem/bigchaindb.pem
|
||||||
|
# so that the owner can read it, but that's all
|
||||||
|
chmod 0400 pem/bigchaindb.pem
|
||||||
|
|
||||||
|
# The following Python script does these things:
|
||||||
|
# 0. allocates more elastic IP addresses if necessary,
|
||||||
|
# 1. launches the specified number of nodes (instances) on Amazon EC2,
|
||||||
|
# 2. tags them with the specified tag,
|
||||||
|
# 3. waits until those instances exist and are running,
|
||||||
|
# 4. for each instance, it associates an elastic IP address
|
||||||
|
# with that instance,
|
||||||
|
# 5. writes the shellscript add2known_hosts.sh
|
||||||
|
# 6. (over)writes a file named hostlist.py
|
||||||
|
# containing a list of all public DNS names.
|
||||||
|
python launch_ec2_nodes.py --tag $TAG --nodes $NUM_NODES
|
||||||
|
|
||||||
|
# Make add2known_hosts.sh executable then execute it.
|
||||||
|
# This adds remote keys to ~/.ssh/known_hosts
|
||||||
|
chmod +x add2known_hosts.sh
|
||||||
|
./add2known_hosts.sh
|
||||||
|
|
||||||
|
# Rollout base packages (dependencies) needed before
|
||||||
|
# storage backend (RethinkDB) and BigchainDB can be rolled out
|
||||||
|
fab install_base_software
|
||||||
|
|
||||||
|
if [ "$WHAT_TO_DEPLOY" == "servers" ]; then
|
||||||
|
# (Re)create the RethinkDB configuration file conf/rethinkdb.conf
|
||||||
|
python create_rethinkdb_conf.py
|
||||||
|
# Rollout storage backend (RethinkDB) and start it
|
||||||
|
fab install_rethinkdb
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rollout BigchainDB (but don't start it yet)
|
||||||
|
if [ "$BRANCH" == "pypi" ]; then
|
||||||
|
fab install_bigchaindb_from_pypi
|
||||||
|
else
|
||||||
|
cd ..
|
||||||
|
rm -f bigchaindb-archive.tar.gz
|
||||||
|
git archive $BRANCH --format=tar --output=bigchaindb-archive.tar
|
||||||
|
# TODO: the archive could exclude more files besides the .gitignore ones
|
||||||
|
# such as the docs. See http://tinyurl.com/zo6fxeg
|
||||||
|
gzip bigchaindb-archive.tar
|
||||||
|
mv bigchaindb-archive.tar.gz deploy-cluster-aws
|
||||||
|
cd deploy-cluster-aws
|
||||||
|
fab install_bigchaindb_from_git_archive
|
||||||
|
rm bigchaindb-archive.tar.gz
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configure BigchainDB on all nodes
|
||||||
|
|
||||||
|
if [ "$WHAT_TO_DEPLOY" == "servers" ]; then
|
||||||
|
# The idea is to send a bunch of locally-created configuration
|
||||||
|
# files out to each of the instances / nodes.
|
||||||
|
|
||||||
|
# Assume a set of $NUM_NODES BigchaindB config files
|
||||||
|
# already exists in the confiles directory.
|
||||||
|
# One can create a set using a command like
|
||||||
|
# ./make_confiles.sh confiles $NUM_NODES
|
||||||
|
# (We can't do that here now because this virtual environment
|
||||||
|
# is a Python 2 environment that may not even have
|
||||||
|
# bigchaindb installed, so bigchaindb configure can't be called)
|
||||||
|
|
||||||
|
# Transform the config files in the confiles directory
|
||||||
|
# to have proper keyrings, api_endpoint values, etc.
|
||||||
|
python clusterize_confiles.py confiles $NUM_NODES
|
||||||
|
|
||||||
|
# Send one of the config files to each instance
|
||||||
|
for (( HOST=0 ; HOST<$NUM_NODES ; HOST++ )); do
|
||||||
|
CONFILE="bcdb_conf"$HOST
|
||||||
|
echo "Sending "$CONFILE
|
||||||
|
fab set_host:$HOST send_confile:$CONFILE
|
||||||
|
done
|
||||||
|
|
||||||
|
# Initialize BigchainDB (i.e. Create the RethinkDB database,
|
||||||
|
# the tables, the indexes, and genesis glock). Note that
|
||||||
|
# this will only be sent to one of the nodes, see the
|
||||||
|
# definition of init_bigchaindb() in fabfile.py to see why.
|
||||||
|
fab init_bigchaindb
|
||||||
|
|
||||||
|
# Start BigchainDB on all the nodes using "screen"
|
||||||
|
fab start_bigchaindb
|
||||||
|
else
|
||||||
|
# Deploying clients
|
||||||
|
# The only thing to configure on clients is the api_endpoint
|
||||||
|
# It should be the public DNS name of a BigchainDB server
|
||||||
|
fab send_client_confile:client_confile
|
||||||
|
|
||||||
|
# Start sending load from the clients to the servers
|
||||||
|
fab start_bigchaindb_load
|
||||||
|
fi
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm add2known_hosts.sh
|
15
deploy-cluster-aws/fabfile.py
vendored
15
deploy-cluster-aws/fabfile.py
vendored
@ -146,6 +146,15 @@ def send_confile(confile):
|
|||||||
run('bigchaindb show-config')
|
run('bigchaindb show-config')
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
@parallel
|
||||||
|
def send_client_confile(confile):
|
||||||
|
put(confile, 'tempfile')
|
||||||
|
run('mv tempfile ~/.bigchaindb')
|
||||||
|
print('For this node, bigchaindb show-config says:')
|
||||||
|
run('bigchaindb show-config')
|
||||||
|
|
||||||
|
|
||||||
# Initialize BigchainDB
|
# Initialize BigchainDB
|
||||||
# i.e. create the database, the tables,
|
# i.e. create the database, the tables,
|
||||||
# the indexes, and the genesis block.
|
# the indexes, and the genesis block.
|
||||||
@ -164,6 +173,12 @@ def start_bigchaindb():
|
|||||||
sudo('screen -d -m bigchaindb -y start &', pty=False)
|
sudo('screen -d -m bigchaindb -y start &', pty=False)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
@parallel
|
||||||
|
def start_bigchaindb_load():
|
||||||
|
sudo('screen -d -m bigchaindb load &', pty=False)
|
||||||
|
|
||||||
|
|
||||||
# Install and run New Relic
|
# Install and run New Relic
|
||||||
@task
|
@task
|
||||||
def install_newrelic():
|
def install_newrelic():
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
# The set -e option instructs bash to immediately exit
|
|
||||||
# if any command has a non-zero exit status
|
|
||||||
set -e
|
|
||||||
|
|
||||||
function printErr()
|
|
||||||
{
|
|
||||||
echo "usage: ./startup.sh <tag> <number_of_nodes_in_cluster> <pypi_or_branch>"
|
|
||||||
echo "No argument $1 supplied"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
printErr "<tag>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
printErr "<number_of_nodes_in_cluster>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
TAG=$1
|
|
||||||
NUM_NODES=$2
|
|
||||||
|
|
||||||
# If they don't include a third argument (<pypi_or_branch>)
|
|
||||||
# then assume BRANCH = "pypi" by default
|
|
||||||
if [ -z "$3" ]; then
|
|
||||||
echo "No third argument was specified, so BigchainDB will be installed from PyPI"
|
|
||||||
BRANCH="pypi"
|
|
||||||
else
|
|
||||||
BRANCH=$3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for AWS private key file (.pem file)
|
|
||||||
if [ ! -f "pem/bigchaindb.pem" ]; then
|
|
||||||
echo "File pem/bigchaindb.pem (AWS private key) is missing"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for the confiles directory
|
|
||||||
if [ ! -d "confiles" ]; then
|
|
||||||
echo "Directory confiles is needed but does not exist"
|
|
||||||
echo "See make_confiles.sh to find out how to make it"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Change the file permissions on pem/bigchaindb.pem
|
|
||||||
# so that the owner can read it, but that's all
|
|
||||||
chmod 0400 pem/bigchaindb.pem
|
|
||||||
|
|
||||||
# The following Python script does these things:
|
|
||||||
# 0. allocates more elastic IP addresses if necessary,
|
|
||||||
# 1. launches the specified number of nodes (instances) on Amazon EC2,
|
|
||||||
# 2. tags them with the specified tag,
|
|
||||||
# 3. waits until those instances exist and are running,
|
|
||||||
# 4. for each instance, it associates an elastic IP address
|
|
||||||
# with that instance,
|
|
||||||
# 5. writes the shellscript add2known_hosts.sh
|
|
||||||
# 6. (over)writes a file named hostlist.py
|
|
||||||
# containing a list of all public DNS names.
|
|
||||||
python launch_ec2_nodes.py --tag $TAG --nodes $NUM_NODES
|
|
||||||
|
|
||||||
# Make add2known_hosts.sh executable then execute it.
|
|
||||||
# This adds remote keys to ~/.ssh/known_hosts
|
|
||||||
chmod +x add2known_hosts.sh
|
|
||||||
./add2known_hosts.sh
|
|
||||||
|
|
||||||
# (Re)create the RethinkDB configuration file conf/rethinkdb.conf
|
|
||||||
python create_rethinkdb_conf.py
|
|
||||||
|
|
||||||
# Rollout base packages (dependencies) needed before
|
|
||||||
# storage backend (RethinkDB) and BigchainDB can be rolled out
|
|
||||||
fab install_base_software
|
|
||||||
|
|
||||||
# Rollout storage backend (RethinkDB) and start it
|
|
||||||
fab install_rethinkdb
|
|
||||||
|
|
||||||
# Rollout BigchainDB (but don't start it yet)
|
|
||||||
if [ "$BRANCH" == "pypi" ]; then
|
|
||||||
fab install_bigchaindb_from_pypi
|
|
||||||
else
|
|
||||||
cd ..
|
|
||||||
rm -f bigchaindb-archive.tar.gz
|
|
||||||
git archive $BRANCH --format=tar --output=bigchaindb-archive.tar
|
|
||||||
# TODO: the archive could exclude more files besides the .gitignore ones
|
|
||||||
# such as the docs. See http://tinyurl.com/zo6fxeg
|
|
||||||
gzip bigchaindb-archive.tar
|
|
||||||
mv bigchaindb-archive.tar.gz deploy-cluster-aws
|
|
||||||
cd deploy-cluster-aws
|
|
||||||
fab install_bigchaindb_from_git_archive
|
|
||||||
rm bigchaindb-archive.tar.gz
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure BigchainDB on all nodes
|
|
||||||
|
|
||||||
# The idea is to send a bunch of locally-created configuration
|
|
||||||
# files out to each of the instances / nodes.
|
|
||||||
|
|
||||||
# Assume a set of $NUM_NODES BigchaindB config files
|
|
||||||
# already exists in the confiles directory.
|
|
||||||
# One can create a set using a command like
|
|
||||||
# ./make_confiles.sh confiles $NUM_NODES
|
|
||||||
# (We can't do that here now because this virtual environment
|
|
||||||
# is a Python 2 environment that may not even have
|
|
||||||
# bigchaindb installed, so bigchaindb configure can't be called)
|
|
||||||
|
|
||||||
# Transform the config files in the confiles directory
|
|
||||||
# to have proper keyrings, api_endpoint values, etc.
|
|
||||||
python clusterize_confiles.py confiles $NUM_NODES
|
|
||||||
|
|
||||||
# Send one of the config files to each instance
|
|
||||||
for (( HOST=0 ; HOST<$NUM_NODES ; HOST++ )); do
|
|
||||||
CONFILE="bcdb_conf"$HOST
|
|
||||||
echo "Sending "$CONFILE
|
|
||||||
fab set_host:$HOST send_confile:$CONFILE
|
|
||||||
done
|
|
||||||
|
|
||||||
# Initialize BigchainDB (i.e. Create the RethinkDB database,
|
|
||||||
# the tables, the indexes, and genesis glock). Note that
|
|
||||||
# this will only be sent to one of the nodes, see the
|
|
||||||
# definition of init_bigchaindb() in fabfile.py to see why.
|
|
||||||
fab init_bigchaindb
|
|
||||||
|
|
||||||
# Start BigchainDB on all the nodes using "screen"
|
|
||||||
fab start_bigchaindb
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
rm add2known_hosts.sh
|
|
||||||
# rm -rf temp_confs
|
|
@ -147,24 +147,36 @@ You can look inside those files if you're curious. In step 2, they'll be modifie
|
|||||||
|
|
||||||
Step 2 is to launch the nodes ("instances") on AWS, to install all the necessary software on them, configure the software, run the software, and more.
|
Step 2 is to launch the nodes ("instances") on AWS, to install all the necessary software on them, configure the software, run the software, and more.
|
||||||
|
|
||||||
Here's an example of how one could launch a BigchainDB cluster of three (3) nodes tagged `wrigley` on AWS:
|
Here's an example of how one could launch a BigchainDB cluster of three (3) nodes on AWS:
|
||||||
```text
|
```text
|
||||||
# in a Python 2.5-2.7 virtual environment where fabric, boto3, etc. are installed
|
# in a Python 2.5-2.7 virtual environment where fabric, boto3, etc. are installed
|
||||||
cd bigchaindb
|
cd bigchaindb
|
||||||
cd deploy-cluster-aws
|
cd deploy-cluster-aws
|
||||||
./startup.sh wrigley 3 pypi
|
./awsdeploy.sh 3
|
||||||
```
|
```
|
||||||
|
|
||||||
The `pypi` on the end means that it will install the latest (stable) `bigchaindb` package from the [Python Package Index (PyPI)](https://pypi.python.org/pypi). That is, on each node, BigchainDB is installed using `pip install bigchaindb`.
|
`awsdeploy.sh` is a Bash script which calls some Python and Fabric scripts. The usage is:
|
||||||
|
|
||||||
`startup.sh` is a Bash script which calls some Python and Fabric scripts. The usage is:
|
|
||||||
```text
|
```text
|
||||||
./startup.sh <tag> <number_of_nodes_in_cluster> <pypi_or_branch>
|
./awsdeploy.sh <number_of_nodes_in_cluster> [pypi_or_branch] [servers_or_clients]
|
||||||
```
|
```
|
||||||
|
|
||||||
The first two arguments are self-explanatory. The third argument can be `pypi` or the name of a local Git branch (e.g. `master` or `feat/3752/quote-asimov-on-tuesdays`). If you don't include a third argument, then `pypi` will be assumed by default.
|
**<number_of_nodes_in_cluster>** (Required)
|
||||||
|
|
||||||
If you're curious what the `startup.sh` script does, the source code has lots of explanatory comments, so it's quite easy to read. Here's a link to the latest version on GitHub: [`startup.sh`](https://github.com/bigchaindb/bigchaindb/blob/master/deploy-cluster-aws/startup.sh)
|
The number of nodes you want to deploy. Example value: 5
|
||||||
|
|
||||||
|
**[pypi_or_branch]** (Optional)
|
||||||
|
|
||||||
|
Where the nodes should get their BigchainDB source code. If it's `pypi`, then BigchainDB will be installed from the latest `bigchaindb` package in the [Python Package Index (PyPI)](https://pypi.python.org/pypi). That is, on each node, BigchainDB will be installed using `pip install bigchaindb`. You can also put the name of a local Git branch; it will be compressed and sent out to all the nodes for installation. If you don't include the second argument, then the default is `pypi`.
|
||||||
|
|
||||||
|
**[servers_or_clients]** (Optional)
|
||||||
|
|
||||||
|
If you want to deploy BigchainDB servers, then the third argument should be `servers`.
|
||||||
|
If you want to deploy BigchainDB clients, then the third argument should be `clients`.
|
||||||
|
The third argument is optional, but if you want to include it, you must also include the second argument. If you don't include the third argument, then the default is `servers`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
If you're curious what the `awsdeploy.sh` script does, [the source code](https://github.com/bigchaindb/bigchaindb/blob/master/deploy-cluster-aws/awsdeploy.sh) has lots of explanatory comments, so it's quite easy to read.
|
||||||
|
|
||||||
It should take a few minutes for the deployment to finish. If you run into problems, see the section on Known Deployment Issues below.
|
It should take a few minutes for the deployment to finish. If you run into problems, see the section on Known Deployment Issues below.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user