Automation of multi node BigchainDB deployment for dev/test

- Setup single/multi node BigchainDB cluster using
  - Vagrant
  - Ansible
- Updated documentation
This commit is contained in:
muawiakh 2017-10-18 17:59:08 +02:00
parent a4140e92a6
commit 241af47a32
57 changed files with 830 additions and 240 deletions

View File

@ -2,8 +2,8 @@
**NOT for Production Use**
You can use the following instructions to deploy a BigchainDB node for
dev/test using Ansible. Ansible will setup a BigchainDB node along with
You can use the following instructions to deploy a single or multi node
BigchainDB setup for dev/test using Ansible. Ansible will setup BigchainDB node(s) along with
[Docker](https://www.docker.com/), [Docker Compose](https://docs.docker.com/compose/),
[MongoDB](https://www.mongodb.com/), [BigchainDB Python driver](https://docs.bigchaindb.com/projects/py-driver/en/latest/).
@ -26,36 +26,113 @@ Navigate to `bigchaindb/pkg/scripts` and run the `bootstrap.sh` script to instal
for your OS. The script also checks if the OS you are running is compatible with the
supported versions.
**Note**: `bootstrap.sh` only supports Ubuntu >= 16.04, CentOS >= 7 and Fedora >=24.
```text
$ cd bigchaindb/pkg/scripts/
$ sudo ./bootstrap.sh
```
### Local Setup | Ansible
You can safely run the `quickstart` playbook now and everything will be taken care of by `ansible` on your host. `quickstart` playbook only supports deployment on your dev/local host. To run the playbook please navigate to the ansible directory inside the BigchainDB repository and run the `quickstart` playbook.
### BigchainDB Setup Configuration(s) | Ansible
#### Local Setup | Ansible
You can run the Ansible playbook `bdb-deploy.yml` on your local dev machine and set up the BigchainDB node where
BigchainDB can be run as a process or inside a Docker container(s) depending on your configuratin.
Before, running the playbook locally, you need to update the `hosts` and `bdb-config.yml` configuration, which will notify Ansible that we need to run the play locally.
##### Update Hosts | Local
Navigate to `bigchaindb/pkg/configuration/hosts` inside the BigchainDB repository.
```text
$ cd bigchaindb/pkg/ansible/
# All the services will be deployed as processes
$ sudo ansible-playbook quickstart.yml -c local
OR
# To deploy all services inside docker containers
$ sudo ansible-playbook quickstart.yml --extra-vars "with_docker=true" -c local
$ cd bigchaindb/pkg/configuration/hosts
```
After successfull execution of the playbook, you can verify that BigchainDB docker/process is running.
Edit `all` configuration file:
```text
# Delete any existing configuration in this file and insert
localhost ansible_connection=local
```
##### Update Configuration | Local
Navigate to `bigchaindb/pkg/configuration/vars` inside the BigchainDB repository.
```text
$ cd bigchaindb/pkg/configuration/vars/bdb-config.yml
```
Verify BigchainDB process:
Edit `bdb-config.yml` configuration file as per your requirements, sample configuration file(s):
```text
---
deploy_docker: false #[true, false]
docker_replset_size: 1 # Only needed if `deploy_docker` is true
bdb_hosts:
- name: "<LOCAL_DEV_HOST_HOSTNAME>"
```
**Note**: You can also orchestrate a multi-node BigchainDB cluster on a local dev host using Docker containers.
Here is a sample `bdb-config.yml`
```text
---
deploy_docker: true #[true, false]
docker_replset_size: 3
bdb_hosts:
- name: "<LOCAL_DEV_HOST_HOSTNAME>"
```
#### Remote Setup | Ansible
You can also run the Ansible playbook `bdb-deploy.yml` on remote machine(s) and set up the BigchainDB node where
BigchainDB can be run as a process or inside a Docker container(s) depending on your configuration.
Before, running the playbook on a remote host, you need to update the `hosts` and `bdb-config.yml` configuration, which will notify Ansible that we need to run the play on a remote host.
##### Update Hosts | Remote
Navigate to `bigchaindb/pkg/configuration/hosts` inside the BigchainDB repository.
```text
$ cd bigchaindb/pkg/configuration/hosts
```
Edit `all` configuration file:
```text
# Delete any existing configuration in this file and insert
<Remote_Host_IP/Hostname> ansible_ssh_user=<USERNAME> ansible_sudo_pass=<ROOT_PASSWORD>
```
**Note 1**: You can multiple hosts to `all` configuration file. Root password is needed because ansible
will run some tasks that require root permissions.
**Note 2**: You can also use other methods to get inside the remote machines instead of password based SSH. For other methods
please consult [Ansible Documentation](http://docs.ansible.com/ansible/latest/intro_getting_started.html).
##### Update Configuration | Remote
Navigate to `bigchaindb/pkg/configuration/vars` inside the BigchainDB repository.
```text
$ cd bigchaindb/pkg/configuration/vars/bdb-config.yml
```
Edit `bdb-config.yml` configuration file as per your requirements, sample configuration file(s):
```text
---
deploy_docker: false #[true, false]
docker_replset_size: 1 # Only needed if `deploy_docker` is true
bdb_hosts:
- name: "<REMOTE_MACHINE_HOSTNAME>"
```
### BigchainDB Setup | Ansible
Now, You can safely run the `bdb-deploy.yml` playbook and everything will be taken care of by `Ansible`. To run the playbook please navigate to the `bigchaindb/pkg/configuration` directory inside the BigchainDB repository and run the `bdb-deploy.yml` playbook.
```text
$ cd bigchaindb/pkg/configuration/
$ sudo ansible-playbook bdb-deploy.yml -i /bigchaindb/configuration/hosts/all
```
After successfull execution of the playbook, you can verify that BigchainDB docker(s)/process(es) is(are) running.
Verify BigchainDB process(es):
```text
$ ps -ef | grep bigchaindb
```
OR
Verify BigchainDB Docker:
Verify BigchainDB Docker(s):
```text
$ docker ps | grep bigchaindb
```

View File

@ -2,10 +2,10 @@
**NOT for Production Use**
You can use the following instructions to deploy a BigchainDB node
for dev/test using Vagrant. Vagrant will setup a BigchainDB node with
all the dependencies along with MongoDB, BigchainDB Python driver. You
can also tweak the following configurations for the BigchainDB node.
You can use the following instructions to deploy a single or multi node
BigchainDB setup for dev/test using Vagrant. Vagrant will set up the BigchainDB node(s)
with all the dependencies along with MongoDB and BigchainDB Python driver. You
can also tweak the following configurations for the BigchainDB node(s).
- Vagrant Box
- Currently, we support the following boxes:
- `ubuntu/xenial64 # >=16.04`
@ -19,10 +19,11 @@ can also tweak the following configurations for the BigchainDB node.
- Network Type
- Currently, only `private_network` is supported.
- IP Address
- Setup type
- `quickstart`
- Deploy node with Docker
- Deploy all the services in Docker containers or as processes.
- Size of Replica Set(Number of cluster member)
- If you want to deploy the services inside Docker containers, you
can specify number of member(s) in the MongoDB/BigchainDB cluster.
- Upstart Script
- Vagrant Provider
- Virtualbox
@ -38,64 +39,84 @@ $ git clone https://github.com/bigchaindb/bigchaindb.git
```
## Configuration | Vagrant
Navigate to `bigchaindb/pkg/config/` inside the repository.
Navigate to `bigchaindb/pkg/config/` inside the BigchainDB repository.
```text
$ cd bigchaindb/pkg/config/
```
Edit the `bdb-config.yaml` as per your requirements. Sample `bdb-config.yaml`:
Edit `bdb-config.yml` as per your requirements. Sample `bdb-config.yml`:
```text
---
- name: "bdb-node-01"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
setup_type: "quickstart"
deploy_docker: false
network:
ip: "10.20.30.40"
type: "private_network"
upstart: "/bigchaindb/scripts/bootstrap.sh"
deploy_docker: false #[true, false]
docker_replset_size: 1
upstart: "/bigchaindb/scripts/bootstrap.sh"
bdb_hosts:
- name: "bdb-node-01"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
network:
ip: "10.20.30.40"
type: "private_network"
```
**Note**: You can spawn multiple instances as well using `bdb-config.yaml`. Here is a sample `bdb-config.yaml`:
**Note**: You can spawn multiple instances to orchestrate a multi-node BigchainDB cluster.
Here is a sample `bdb-config.yml`:
```text
---
- name: "bdb-node-01"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
setup_type: "quickstart"
deploy_docker: false
network:
ip: "10.20.30.40"
type: "private_network"
upstart: "/bigchaindb/scripts/bootstrap.sh"
- name: "bdb-node-02"
box:
name: "ubuntu/xenial64"
ram: "4096"
vcpus: "3"
setup_type: "quickstart"
deploy_docker: false
network:
ip: "10.20.30.50"
type: "private_network"
upstart: "/bigchaindb/scripts/bootstrap.sh"
deploy_docker: false #[true, false]
docker_replset_size: 1
upstart: "/bigchaindb/scripts/bootstrap.sh"
bdb_hosts:
- name: "bdb-node-01"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
network:
ip: "10.20.30.40"
type: "private_network"
- name: "bdb-node-02"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
network:
ip: "10.20.30.50"
type: "private_network"
```
**Note**: You can also orchestrate a multi-node BigchainDB cluster on a single dev host using Docker containers.
Here is a sample `bdb-config.yml`
```text
---
deploy_docker: true #[true, false]
docker_replset_size: 3
upstart: "/bigchaindb/scripts/bootstrap.sh"
bdb_hosts:
- name: "bdb-node-01"
box:
name: "ubuntu/xenial64"
ram: "8192"
vcpus: "4"
network:
ip: "10.20.30.40"
type: "private_network"
```
The above mentioned configuration will deploy a 3 node BigchainDB cluster with Docker containers
on your specified host.
## Local Setup | Vagrant
To bring up the BigchainDB node, run the following command:
## BigchainDB Setup | Vagrant
To bring up the BigchainDB node(s), run the following command:
```text
$ vagrant up
```
*Note*: There are some vagrant plugins required for the installation, user will be prompted to install them if they are not present. Instructions to install the plugins can be extracted from the message.
**Note**: There are some vagrant plugins required for the installation,
user will be prompted to install them if they are not present. Instructions
to install the plugins can be extracted from the message.
```text
$ vagrant plugin install <plugin-name>
@ -108,16 +129,17 @@ $ vagrant ssh <instance-name>
```
## Make your first transaction
Once you are inside the BigchainDB node, you can verify that BigchainDB docker/process is running.
Once you are inside the BigchainDB node, you can verify that BigchainDB
docker(s)/process(es) is(are) running.
Verify BigchainDB process:
Verify BigchainDB process(es):
```text
$ ps -ef | grep bigchaindb
```
OR
Verify BigchainDB Docker:
Verify BigchainDB Docker(s):
```text
$ docker ps | grep bigchaindb
```

62
pkg/Vagrantfile vendored
View File

@ -9,10 +9,12 @@ Vagrant.require_version '>= 1.6.0'
VAGRANTFILE_API_VERSION = '2'
# Configuration files
CONFIGURATION_FILE = 'config/bdb-config.yaml'
CONFIGURATION_FILE = 'configuration/vars/bdb-config.yml'
HOSTS_FILE = 'configuration/hosts/all'
HOST_VARS_PATH = 'configuration/host_vars'
# Validate if all the required plugins are present
required_plugins = ["vagrant-cachier"]
required_plugins = ["vagrant-cachier", "vagrant-vbguest", "vagrant-hosts"]
required_plugins.each do |plugin|
if not Vagrant.has_plugin?(plugin)
raise "Required vagrant plugin #{plugin} not found. Please run `vagrant plugin install #{plugin}`"
@ -21,10 +23,22 @@ end
# Read configuration file(s)
instances_config = YAML.load_file(File.join(File.dirname(__FILE__), CONFIGURATION_FILE))
#TODO: (muawiakh) Add support for Docker, AWS, Azure
hosts_config = File.open(HOSTS_FILE, 'w+')
# TODO: (muawiakh) Add support for Docker, AWS, Azure
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
instances_config.each do |instance|
instances_config["bdb_hosts"].each do |instance|
# Workaround till canonical fixes https://bugs.launchpad.net/cloud-images/+bug/1569237
# using -u ubuntu as remote user, conventionally vagrant boxes use `vagrant` user
if instance["box"]["name"] == "ubuntu/xenial64"
hosts_config.puts("#{instance["name"]} ansible_user=ubuntu")
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
config.vbguest.no_install = true
config.vbguest.no_remote = true
end
else
hosts_config.puts("#{instance["name"]} ansible_user=vagrant")
end
config.vm.define instance['name'] do |bdb|
# Workaround until vagrant cachier plugin supports dnf
if !(instance["box"]["name"].include? "fedora")
@ -40,14 +54,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
else
raise "Invalid network type: Please specify one of the following: [private_network, public_network]"
end
bdb.vm.provision :hosts, :sync_hosts => true
bdb.vm.box = instance["box"]["name"]
bdb.vm.synced_folder ".", "/bigchaindb"
bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instance["upstart"]}"
if instance["setup_type"] == "quickstart"
bdb.vm.provision :shell, inline: "PYTHONBUFFERED=1 ansible-playbook \
/bigchaindb/ansible/quickstart.yml --extra-vars \"with_docker=#{instance["deploy_docker"]}\" -c local"
end
File.open("#{HOST_VARS_PATH}/#{instance["name"]}", "w+") {|f| \
f.write("ansible_ssh_private_key_file: /bigchaindb/.vagrant/machines/#{instance["name"]}/virtualbox/private_key") }
bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instances_config["upstart"]}"
bdb.vm.provider 'vmware_fusion' do |vmwf, override|
vmwf.vmx['memsize'] = instance["ram"]
vmwf.vmx['numvcpus'] = instance['vcpus']
@ -59,4 +71,32 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end
end
end
hosts_config.close
config.vm.define "config-node" do |bdb|
bdb.vm.box = "ubuntu/xenial64"
bdb.vm.hostname = "config-node"
bdb.vm.provision :hosts, :sync_hosts => true
bdb.vm.synced_folder ".", "/bigchaindb"
bdb.vm.network "private_network", ip: "192.168.100.200"
bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instances_config["upstart"]}"
bdb.vm.provision :shell, inline: "PYTHONUNBUFFERED=1 ansible-playbook /bigchaindb/configuration/bdb-deploy.yml \
-c /bigchaindb/configuration/hosts/all"
bdb.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.memory = 2048
vb.cpus = 2
end
bdb.vm.provider 'vmware_fusion' do |vmwf|
vmwf.vmx['memsize'] = 2048
vmwf.vmx['numvcpus'] = 2
end
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
config.vbguest.no_install = true
config.vbguest.no_remote = true
end
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
end
end

View File

@ -1,10 +0,0 @@
- hosts: localhost
remote_user: vagrant
vars:
with_docker: "{{ deploy_docker | default(false) }}"
roles:
- { role: docker, when: with_docker|bool }
- { role: docker-compose, when: with_docker|bool }
- mongodb
- bigchaindb
- bigchaindb-driver

View File

@ -1,16 +0,0 @@
---
- include: with_docker.yml
when: with_docker|bool
tags: [bigchaindb]
- include: debian.yml
when: not with_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu")
- include: centos.yml
when: not with_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux")
- include: fedora.yml
when: not with_docker|bool and (distribution_name == "fedora")
- include: common.yml
when: not with_docker|bool

View File

@ -1,25 +0,0 @@
---
- name: Configuring BigchainDB Docker
docker_container:
name: "{{ bigchaindb_docker_name }}"
image: "{{ bigchaindb_image_name }}"
volumes: "{{ bigchaindb_docker_volumes }}"
pull: false
env:
BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}"
BIGCHAINDB_DATABASE_HOST: "{{ bigchaindb_database_host }}"
entrypoint: "bigchaindb -y configure mongodb"
register: result
tags: [bigchaindb]
- name: Start BigchainDB Docker
docker_container:
name: "{{ bigchaindb_docker_name }}"
image: "{{ bigchaindb_image_name }}"
published_ports: "{{ bigchaindb_docker_published_ports }}"
restart_policy: always
volumes: "{{ bigchaindb_docker_volumes }}"
state: started
pull: false
when: result|succeeded
tags: [bigchaindb]

View File

@ -1,10 +0,0 @@
---
- name: MongoDB Process Check
shell: pgrep mongod | wc -l
register: command_result
tags: [mongodb]
- name: Run MongoDB
shell: "mongod --replSet=bigchain-rs --logpath {{ mongodb_log_path }}/mongod.log &"
when: command_result.stdout| int != 1
tags: [mongodb]

View File

@ -1,31 +0,0 @@
---
- name: Creating directories
file:
path: "{{ item }}"
state: directory
mode: 0700
with_items: "{{ directories }}"
tags: [mongodb]
- include: with_docker.yml
when: with_docker|bool
- name: Verify logfiles exist | Debian
file:
path: "{{ mongodb_log_path }}/mongod.log"
state: touch
mode: 0755
when: not with_docker|bool
tags: [mongodb]
- include: debian.yml
when: not with_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu")
- include: centos.yml
when: not with_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux")
- include: fedora.yml
when: not with_docker|bool and (distribution_name == "fedora")
- include: common.yml
when: not with_docker|bool

View File

@ -1,20 +0,0 @@
---
- name: Check Docker Service
systemd:
name: docker
enabled: yes
state: started
tags: [docker]
- name: Running MongoDB Docker
docker_container:
name: "{{ mongodb_docker_name }}"
image: "{{ mongodb_docker_image }}"
detach: True
published_ports: "{{ mongodb_docker_published_ports }}"
restart_policy: always
volumes: "{{ mongodb_docker_volumes }}"
state: started
pull: false
entrypoint: /entrypoint.sh --replSet=bigchain-rs
tags: [mongodb]

View File

@ -1,14 +0,0 @@
---
- name: "bdb-node-01" # Instance name
box:
name: "ubuntu/xenial64" # Box name
ram: "2048"
vcpus: "2"
setup_type: "quickstart" # Currently, only quickstart is supported.
deploy_docker: true # [true, false]
network:
ip: "10.20.30.50"
type: "private_network"
# Active network interface on host, Only required for public network e.g "en0: Wi-Fi (AirPort)"
bridge: "<network-interface-host>"
upstart: "/bigchaindb/scripts/bootstrap.sh" # Path to upstart script

View File

@ -0,0 +1,12 @@
- import_playbook: pre_req.yml
- hosts: all
vars_files:
- vars/bdb-config.yml
serial: 1
roles:
- bigchaindb
- bigchaindb-driver
- import_playbook: multi_node.yml
when: (bdb_hosts|length > 1) or docker_replset_size|int > 1

View File

@ -0,0 +1,5 @@
---
ansible_connection: ssh
ansible_ssh_port: 22
ansible_become: yes
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'

View File

@ -0,0 +1,5 @@
# Place holder file for users, running Ansible playbooks manually. Otherwise Vagrant
# populates this dynamically.
# Only needed for logging into remote hosts and adding host specific variables e.g.
#ansible_ssh_private_key_file: "/path/to/private/key"

View File

@ -0,0 +1,8 @@
# Place holder file for users, running Ansible playbooks manually. Otherwise Vagrant
# populates this dynamically.
# For local host
#localhost ansible_connection=local
# For remote host(s)
#<Remote_Host_IP/Hostname> ansible_ssh_user=<USERNAME> ansible_sudo_pass=<ROOT_PASSWORD>

View File

@ -0,0 +1,5 @@
- hosts: all
vars_files:
- vars/bdb-config.yml
roles:
- key-exchange

View File

@ -0,0 +1,8 @@
- hosts: all
vars_files:
- vars/bdb-config.yml
serial: 1
roles:
- { role: docker, when: deploy_docker|bool }
- { role: docker-compose, when: deploy_docker|bool }
- mongodb

View File

@ -23,4 +23,9 @@ dependencies_dnf:
- python3-pip
python_pip_upgrade: true
python_setuptools_upgrade: true
python_setuptools_upgrade: true
# Host configuration
distribution_name: "{{ ansible_distribution|lower }}"
distribution_codename: "{{ ansible_distribution_release|lower }}"
distribution_major: "{{ ansible_distribution_major_version }}"

View File

@ -1,12 +1,12 @@
---
- include: debian.yml
- import_tasks: debian.yml
when: distribution_name == "debian" or distribution_name == "ubuntu"
- include: centos.yml
- import_tasks: centos.yml
when: distribution_name == "centos" or distribution_name == "red hat enterprise linux"
- include: fedora.yml
- import_tasks: fedora.yml
when: distribution_name == "fedora"
- include: common.yml
- import_tasks: common.yml

View File

@ -27,21 +27,24 @@ dependencies_dnf:
python_pip_upgrade: true
python_setuptools_upgrade: true
# Host configuration
distribution_name: "{{ ansible_distribution|lower }}"
distribution_codename: "{{ ansible_distribution_release|lower }}"
distribution_major: "{{ ansible_distribution_major_version }}"
directories:
- /data
backend_db: mongodb #[rethinkdb, mongodb]
backend_db: mongodb #[mongodb]
bigchaindb_config_path: /data/.bigchaindb
bigchaindb_server_bind: "0.0.0.0:9984"
bigchaindb_database_host: "172.17.0.1"
bigchaindb_log_file: "{{ ansible_env.HOME }}/bigchaindb.log"
# Docker configuration
backend_db_image: "mongo:3.4.1"
backend_db_name: "mongodb"
bigchaindb_image_name: "bigchaindb/bigchaindb"
bigchaindb_docker_name: "bigchaindb"
bigchaindb_docker_published_ports:
- 59984:9984
bigchaindb_docker_volumes:
- "{{ ansible_env.HOME }}/bigchaindb_docker:/data"
bigchaindb_default_port: 9984
bigchandb_host_port: 59984
bigchaindb_host_mount_dir: "{{ ansible_env.HOME }}/bigchaindb_docker"
bdb_docker_net_name: "bdb_network"

View File

@ -13,10 +13,18 @@
shell: "pip3 install bigchaindb"
tags: [bigchaindb]
- name: Check if BigchainDB node is already configured
stat:
path: "{{ bigchaindb_config_path }}"
register: stat_result
- name: Configure BigchainDB
shell: "bigchaindb -y configure {{ backend_db }}"
environment:
BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}"
BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path }}"
BIGCHAINDB_DATABASE_HOST: "{{ ansible_hostname }}"
when: stat_result.stat.exists == False
tags: [bigchaindb]
- name: MongoDB Process Check
@ -30,7 +38,22 @@
tags: [bigchaindb]
- name: Start BigchainDB
become: yes
shell: "bigchaindb start > {{ bigchaindb_log_file }} 2>&1 &"
environment:
BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path }}"
when: mdb_pchk.stdout| int >= 1 and bdb_pchk.stdout| int == 0
tags: [bigchaindb]
async: 10
poll: 0
tags: [bigchaindb]
- name: Get BigchainDB node public key
shell: "cat {{ bigchaindb_config_path }}"
register: bdb_node_config
tags: [bigchaindb]
- name: Set Facts BigchainDB
set_fact:
pub_key="{{ ( bdb_node_config.stdout|from_json).keypair.public }}"
hostname="{{ ansible_hostname }}"
bdb_config="{{ bigchaindb_config_path }}"
tags: [bigchaindb]

View File

@ -0,0 +1,51 @@
---
- name: Check if BigchainDB Dockers are already configured
stat:
path: "{{ bigchaindb_host_mount_dir }}{{ item|string }}/.bigchaindb"
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
register: stat_result
- name: Configuring BigchainDB Docker
docker_container:
name: "{{ bigchaindb_docker_name }}{{ item }}"
hostname: "{{ bigchaindb_docker_name }}{{ item }}"
image: "{{ bigchaindb_image_name }}"
volumes:
- "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data"
env:
BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}"
BIGCHAINDB_DATABASE_HOST: "{{ hostvars[ansible_hostname]['mongodb' + item|string] }}"
entrypoint: "bigchaindb -y configure mongodb"
networks:
- name: "{{ bdb_docker_net_name }}"
when: stat_result.results[item|int].stat.exists == False
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [bigchaindb]
- name: Start BigchainDB Docker
docker_container:
name: "{{ bigchaindb_docker_name }}{{ item }}"
image: "{{ bigchaindb_image_name }}"
detach: true
published_ports:
- "{{ bigchandb_host_port|int + item|int }}:{{ bigchaindb_default_port }}"
restart_policy: always
volumes:
- "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data"
networks:
- name: "{{ bdb_docker_net_name }}"
state: started
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [bigchaindb]
- name: Get BigchainDB node public key
shell: "cat {{ bigchaindb_host_mount_dir + item|string }}/.bigchaindb"
register: bdb_node_config
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [bigchaindb]
- name: Set facts for BigchainDB containers
set_fact:
pub_key_{{ bigchaindb_docker_name }}{{ item }}="{{ (bdb_node_config.results[item|int].stdout|from_json).keypair.public }}"
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [mongodb]

View File

@ -0,0 +1,20 @@
---
- import_tasks: deploy_docker.yml
when: deploy_docker|bool
tags: [bigchaindb]
- import_tasks: debian.yml
when: not deploy_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu")
tags: [bigchaindb]
- import_tasks: centos.yml
when: not deploy_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux")
tags: [bigchaindb]
- import_tasks: fedora.yml
when: not deploy_docker|bool and (distribution_name == "fedora")
tags: [bigchaindb]
- import_tasks: common.yml
when: not deploy_docker|bool
tags: [bigchaindb]

View File

@ -1,11 +1,11 @@
---
- include: debian.yml
- import_tasks: debian.yml
when: distribution_name == "debian" or distribution_name == "ubuntu"
- include: centos.yml
- import_tasks: centos.yml
when: distribution_name == "centos" or distribution_name == "red hat enterprise linux"
- include: fedora.yml
- import_tasks: fedora.yml
when: distribution_name == "fedora"
- name: Create Docker group

View File

@ -0,0 +1,13 @@
keyring_script_host: /tmp/keyring.py
bigchaindb_log_file_host: "{{ ansible_env.HOME }}/bigchaindb.log"
bigchaindb_config_path_host: /data/.bigchaindb
# Docker configuration
keyring_script_docker: "{{ ansible_env.HOME }}/config/keyring.py"
bigchaindb_config_path_docker: "{{ ansible_env.HOME }}/bigchaindb_docker"
bigchaindb_docker_name: bigchaindb
bigchaindb_default_port: 9984
bigchandb_host_port: 59984
bigchaindb_host_mount_dir: "{{ ansible_env.HOME }}/bigchaindb_docker"
bigchaindb_image_name: "bigchaindb/bigchaindb"
bdb_docker_net_name: "bdb_network"

View File

@ -0,0 +1,8 @@
---
- include_tasks: pub_key_exchange_host.yml
when: not deploy_docker|bool
tags: [bigchaindb]
- include_tasks: pub_key_exchange_docker.yml
when: deploy_docker|bool
tags: [bigchaindb]

View File

@ -0,0 +1,31 @@
---
- name: Creating files for key exchange
template: src=exchange_keyring_docker.j2 dest="{{ keyring_script_docker }}"
tags: [keyex]
- name: Setting permissions
file:
path: "{{ keyring_script_docker }}"
mode: "0777"
tags: [keyex]
- name: Update Keyring Configuration
shell: "python {{ keyring_script_docker }}"
tags: [keyex]
- name: Restart BigchainDB Docker after keyring update
docker_container:
name: "{{ bigchaindb_docker_name }}{{ item }}"
image: "{{ bigchaindb_image_name }}"
detach: true
published_ports:
- "{{ bigchandb_host_port|int + item|int }}:{{ bigchaindb_default_port }}"
restart_policy: always
volumes:
- "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data"
state: started
restart: true
networks:
- name: "{{ bdb_docker_net_name }}"
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [bigchaindb]

View File

@ -0,0 +1,28 @@
---
- name: Creating files for key exchange
template: src=exchange_keyring_host.j2 dest="{{ keyring_script_host }}"
tags: [keyex]
- name: Setting permissions
file:
path: "{{ keyring_script_host }}"
mode: "0777"
tags: [keyex]
- name: Update Keyring Configuration
shell: "python {{ keyring_script_host }}"
tags: [keyex]
- name: Stop BigchainDB
shell: pkill bigchaindb
register: bdb_stop
tags: [keyex]
- name: Start BigchainDB
shell: "bigchaindb start > {{ bigchaindb_log_file_host }} 2>&1 &"
environment:
BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path_host }}"
async: 10
poll: 0
when: bdb_stop|succeeded
tags: [bigchaindb]

View File

@ -0,0 +1,18 @@
#!/usr/bin/python
import json
{% set keyring = {} %}
{% for docker in range(0, docker_replset_size|int, 1) %}
{{- keyring.update({'pub_key_' + bigchaindb_docker_name + docker|string: hostvars[ansible_hostname]['pub_key_' + bigchaindb_docker_name + docker|string]}) -}}
{%- endfor -%}
{% for docker in range(0, docker_replset_size|int, 1) %}
keyring = {{ keyring }}
keyring.pop('{{ 'pub_key_' + bigchaindb_docker_name + docker|string }}', None)
with open('{{ bigchaindb_config_path_docker + docker|string }}/.bigchaindb', 'r+') as f:
data = json.load(f)
del data['keyring'][:]
for key, value in keyring.iteritems():
data['keyring'].append(value)
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
{% endfor %}

View File

@ -0,0 +1,21 @@
{%- set keyring = [] -%}
{%- set bdb_config_path = {'path': ''} -%}
{%- for host in bdb_hosts -%}
{%- if host["name"] != ansible_hostname -%}
{{- keyring.append(hostvars[host["name"]]["pub_key"]) -}}
{%- else -%}
{%- if bdb_config_path.update({'path': hostvars[host["name"]]["bdb_config"]}) -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if keyring|length != 0 -%}
#!/usr/bin/python
import json
with open('{{ bdb_config_path['path'] }}', 'r+') as f:
data = json.load(f)
del data['keyring'][:]
data['keyring'] = {{ keyring }}
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
{%- endif -%}

View File

@ -17,20 +17,27 @@ mongodb_dnf_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower }
mongodb_storage_path: /data/db/main
mongodb_log_path: /var/log/mongodb
mongodb_config_path: /data/configdb
se_linux: "TODO: (muawiakh)"
directories:
- "{{ mongodb_storage_path }}"
- "{{ mongodb_log_path }}"
- "{{ mongodb_config_path }}"
mongodb_conf_file: /etc/mongod.conf
mongodb_conf_files: [
{ src: "mongod.conf", dest: "{{ mongodb_conf_file }}"}
]
mongodb_port: 27017
mongodb_admin_user: "adminUser"
mongodb_admin_password: "superstrongpassword"
replica_set_name: bigchain-rs
bdb_docker_net_name: "bdb_network"
bdb_docker_default_subnet: "172.18.0.0/16"
bdb_docker_default_gw: "172.18.0.1"
# Docker configuration
mongodb_default_port: 27017
mongodb_docker_image: "mongo:3.4.4"
mongodb_docker_image: "mongo:3.4.9"
mongodb_docker_name: "mongodb"
mongodb_docker_published_ports:
- 172.17.0.1:27017:27017
mongodb_host_mount_dir_db: /tmp/mongodb_docker/db
mongodb_host_mount_dir_config: /tmp/mongodb_docker/configdb
mongodb_docker_volumes:
- "{{ mongodb_host_mount_dir_db }}:{{ mongodb_storage_path }}"
- "{{ mongodb_host_mount_dir_config }}:{{ mongodb_config_path }}"
mongodb_host_mount_dir: "{{ ansible_env.HOME }}/mongodb_docker"
mongodb_host_config: "{{ ansible_env.HOME }}/config"

View File

@ -0,0 +1,101 @@
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
verbosity: 0
# traceAllExceptions: true
timeStampFormat: iso8601-utc
component:
accessControl:
verbosity: 0
command:
verbosity: 0
control:
verbosity: 0
ftdc:
verbosity: 0
geo:
verbosity: 0
index:
verbosity: 0
network:
verbosity: 0
query:
verbosity: 0
replication:
verbosity: 0
sharding:
verbosity: 0
storage:
verbosity: 0
journal:
verbosity: 0
write:
verbosity: 0
processManagement:
fork: false
pidFilePath: /tmp/mongod.pid
net:
port: 27017
bindIp: 0.0.0.0
maxIncomingConnections: 8192
wireObjectCheck: false
unixDomainSocket:
enabled: false
pathPrefix: /tmp
filePermissions: 0700
http:
enabled: false
compression:
compressors: snappy
# ssl:
# mode: requireSSL
# PEMKeyFile: MONGODB_KEY_FILE_PATH
# PEMKeyPassword: MONGODB_KEY_FILE_PASSWORD
# CAFile: MONGODB_CA_FILE_PATH
# CRLFile: MONGODB_CRL_FILE_PATH
# allowConnectionsWithoutCertificates: false
# allowInvalidHostnames: false
# weakCertificateValidation: false
# allowInvalidCertificates: false
#security:
# authorization: enabled
# clusterAuthMode: x509
#setParameter:
# enableLocalhostAuthBypass: true
# #notablescan: 1
# logUserIds: 1
# authenticationMechanisms: MONGODB-X509,SCRAM-SHA-1
storage:
dbPath: /data/db/main
indexBuildRetry: true
journal:
enabled: true
commitIntervalMs: 100
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
journalCompressor: snappy
# configString: cache_size=STORAGE_ENGINE_CACHE_SIZE
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true # TODO false may affect performance?
operationProfiling:
mode: slowOp
slowOpThresholdMs: 100
replication:
replSetName: bigchain-rs
enableMajorityReadConcern: true

View File

@ -15,4 +15,11 @@
name: "{{ mongodb_package }}"
state: present
update_cache: yes
tags: [mongodb]
- name: Install pip | CentOS
yum:
name: python-pip
state: present
update_cache: yes
tags: [mongodb]

View File

@ -0,0 +1,25 @@
---
- name: MongoDB config files are copied
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
with_items: "{{ mongodb_conf_files }}"
tags: [mongodb]
- name: MongoDB Process Check
shell: pgrep mongod | wc -l
register: command_result
tags: [mongodb]
- name: Install pymongo
pip:
name: pymongo
state: present
tags: [mongodb]
- name: Run MongoDB
shell: "mongod --config {{ mongodb_conf_file }} 2>&1 &"
when: command_result.stdout| int != 1
async: 5
poll: 0
tags: [mongodb]

View File

@ -3,8 +3,6 @@
apt_key:
keyserver: "{{ apt_keyserver }}"
id: "{{ apt_key_fingerprint }}"
state: present
ignore_errors: true
tags: [mongodb]
- name: Add MongoDB repo and update cache | Debian
@ -16,6 +14,9 @@
- name: Install MongoDB | Debian
apt:
name: "{{ mongodb_package }}"
name: "{{ item }}"
state: present
with_items:
- "{{ mongodb_package }}"
- python-pip
tags: [mongodb]

View File

@ -0,0 +1,48 @@
---
- name: Check Docker Service
systemd:
name: docker
enabled: yes
state: started
tags: [mongodb]
- name: Creating BDB Docker network
docker_network:
name: "{{ bdb_docker_net_name }}"
ipam_options:
subnet: "{{ bdb_docker_default_subnet }}"
driver_options:
com.docker.network.bridge.enable_icc": "true"
com.docker.network.bridge.enable_ip_masquerade": "true"
com.docker.network.bridge.host_binding_ipv4": "0.0.0.0"
com.docker.network.driver.mtu: "1500"
state: present
tags: [mongodb]
- name: Running MongoDB Docker
docker_container:
name: "{{ mongodb_docker_name }}{{ item }}"
hostname: "{{ mongodb_docker_name }}{{ item }}"
image: "{{ mongodb_docker_image }}"
detach: true
published_ports:
- "{{ bdb_docker_default_gw }}:{{ (mongodb_port|int + item|int)|string }}:{{ mongodb_port }}"
restart_policy: always
volumes:
- "{{ mongodb_host_mount_dir }}{{ item|string }}/db:{{ mongodb_storage_path }}"
- "{{ mongodb_host_mount_dir }}{{ item|string }}/configdb:{{ mongodb_config_path }}"
- "{{ mongodb_host_config }}:/bdb_config"
state: started
keep_volumes: true
entrypoint: /entrypoint.sh --replSet=bigchain-rs
networks:
- name: "{{ bdb_docker_net_name }}"
register: mongo_container_info
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [mongodb]
- name: Set facts for MongoDB containers
set_fact:
mongodb{{ item }}={{ mongo_container_info.results[item|int].ansible_facts.docker_container.NetworkSettings.IPAddress }}
with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1
tags: [mongodb]

View File

@ -12,6 +12,8 @@
- name: Install MongoDB | Fedora
dnf:
name: "{{ mongodb_package }}"
name: "{{ item }}"
state: present
with_items:
- "{{ mongodb_package }}"
tags: [mongodb]

View File

@ -0,0 +1,6 @@
---
- import_tasks: initiate_repl_set_host.yml
when: (ansible_hostname == bdb_hosts[bdb_hosts|length-1]['name']) and not deploy_docker|bool
- import_tasks: initiate_repl_set_docker.yml
when: deploy_docker|bool

View File

@ -0,0 +1,13 @@
---
- name: Creating files to initialize MongoDB Replica Set | Docker
template: src=replSet_init_docker.j2 dest="{{ mongodb_host_config }}/replSet_init.js"
tags: [mongodb]
- name: Initializing Replica Set and Adding AdminUser | Docker
run_once: true
shell:
cmd:
"docker exec {{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }} bash -l -c
'/usr/bin/mongo --host {{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }}
--port {{ mongodb_port }} < /bdb_config/replSet_init.js'"
tags: [mongodb]

View File

@ -0,0 +1,20 @@
---
- name: Creating files to initialize MongoDB Replica Set
template: src=replSet_init_host.j2 dest=/tmp/replSet_init.js
tags: [mongodb]
- name: Initializing Replica Set
shell: "/usr/bin/mongo --host {{ ansible_hostname }} --port {{ mongodb_port }} < /tmp/replSet_init.js"
tags: [mongodb]
- name: Adding AdminUser to MongoDB
run_once: true
mongodb_user:
database: admin
login_host: "{{ ansible_hostname }}"
login_port: "{{ mongodb_port }}"
name: "{{ mongodb_admin_user }}"
password: "{{ mongodb_admin_password }}"
roles: readWriteAnyDatabase,clusterManager
state: present
tags: [mongodb]

View File

@ -0,0 +1,31 @@
---
- name: Creating directories
file:
path: "{{ item }}"
state: directory
mode: 0700
with_items: "{{ directories }}"
when: not deploy_docker|bool
tags: [mongodb]
- import_tasks: deploy_docker.yml
when: deploy_docker|bool
tags: [mongodb]
- import_tasks: debian.yml
when: not deploy_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu")
tags: [mongodb]
- import_tasks: centos.yml
when: not deploy_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux")
tags: [mongodb]
- import_tasks: fedora.yml
when: not deploy_docker|bool and (distribution_name == "fedora")
tags: [mongodb]
- import_tasks: common.yml
when: not deploy_docker|bool
tags: [mongodb]
- import_tasks: initiate_repl_set.yml

View File

@ -0,0 +1,30 @@
rs.initiate({
"_id": "{{ replica_set_name }}",
"members": [
{
"_id": 0,
"host": "{{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }}:{{ mongodb_port }}"
}
]
});
sleep(5000);
{% for docker in range(0, docker_replset_size|int, 1) %}
{%- if docker != (docker_replset_size|int - 1) -%}
rs.add("{{ mongodb_docker_name }}{{ docker }}:{{ mongodb_port }}");
{% endif %}
{%- endfor -%}
use admin;
db.createUser(db.createUser({
"user": "{{ mongodb_admin_user }}",
"pwd": "{{ mongodb_admin_password }}",
"roles": [
{
"role": "userAdminAnyDatabase",
"db": "admin"
},
{
"role": "clusterManager",
"db": "admin"
}
]
});

View File

@ -0,0 +1,7 @@
rs.initiate( { _id : "{{ replica_set_name }}", members: [ { _id : 0, host :"{{ bdb_hosts[bdb_hosts|length-1]['name'] }}:{{ mongodb_port }}" } ] } )
sleep(5000);
{% for host in bdb_hosts %}
{%- if ansible_hostname != host["name"] -%}
rs.add("{{ host["name"] }}:{{ mongodb_port }}");
{% endif %}
{%- endfor -%}

View File

@ -0,0 +1,13 @@
---
deploy_docker: false #[true, false]
docker_replset_size: 1
upstart: "/bigchaindb/scripts/bootstrap.sh"
bdb_hosts:
- name: "config-node"
box:
name: "ubuntu/xenial64"
ram: "2048"
vcpus: "2"
network:
ip: "10.20.30.40"
type: "private_network"

View File

@ -28,7 +28,7 @@ validate_os_version_and_deps(){
fi
;;
fedora)
dnf install bc -y > /dev/null 2>&1
dnf install bc python2-dnf libselinux-python -y > /dev/null 2>&1
if [[ ($(echo $3 | bc) > $MINIMUM_FEDORA_VERSION)
|| ($(echo $3 | bc) == $MINIMUM_FEDORA_VERSION) ]]; then
rpm -q "${OS_DEPENDENCIES[@]}" > /dev/null 2>&1
@ -71,20 +71,22 @@ install_dependencies() {
# multiple dependencies)
install_deps_deb() {
echo "Installing Dependencies..."
apt-get update -y
apt-get install -y software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install -y --force-yes ansible
apt-get update -y
apt-get install -y "${OS_DEPENDENCIES[@]}"
}
install_deps_centos() {
echo "Installing Dependencies..."
yum install epel-release -y
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
yum install ansible -y
yum install "${OS_DEPENDENCIES[@]}" -y
}
install_deps_fedora() {
echo "Installing Dependencies..."
export LC_ALL=C
dnf makecache
dnf -y install ansible python2-dnf
}
echo "${OS_DEPENDENCIES[@]}"
dnf -y install "${OS_DEPENDENCIES[@]}"
}