Skip to content

Installation

Tom Steele edited this page Dec 5, 2016 · 26 revisions

These install instructions will walk you through installing individual server components. Most users will prefer using Lair Manager (coming soon) over this method.

For simplicity and for this guide to deal with various operating systems and configurations, each of these services will not run in the background. It is up to the reader to determine the best tools (upstart, systemd, etc) and configuration to use outside of this.

Lair requires the following services to be fully functional:

  • Lair App is the Meteor server used to drive the UI.
  • Lair API is the HTTP JSON API used by drones to import and export data. This is also used for file uploads.
  • Mongodb is the database.
  • Reverse HTTPS proxy which is used for TLS and to proxy requests to the app and API through a single service. We'll be using Caddy, but nginx will also work.

The rest of this guide will assume you are using a clean install of Ubuntu 14.04 with the "build-essential" package installed. Not much changes for other operating systems beyond downloading dependencies.

Setup

Start off by creating a tmux session and a directory to house all of our dependencies:

$ tmux
$ mkdir lair
$ cd lair

Mongodb

Next, we will download, start, and configure Mongodb. Download Mongodb for your operating system here. I suggest using the version marked "Linux 64-bit legacy".

Download and extract:

$ curl -o mongodb.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz
$ tar -zxvf mongodb.tgz

Create a directory to hold our database:

$ mkdir db

Start Mongodb with the following options:

$ ./mongodb-linux-x86_64-ubuntu1404-3.0.6/bin/mongod --dbpath=db --bind_ip=localhost --quiet --nounixsocket --replSet rs0

If you choose to install Mongodb in some other way, the most important thing to note is that it must be configured to use a replica set, and will have to be configured to be the primary.

Configure Mongodb to be the primary in the replica set:

Login to Mongodb:

$ ./mongodb-linux-x86_64-ubuntu1404-3.0.6/bin/mongo admin
MongoDB shell version: 3.0.6
connecting to: admin

From the console, configure the replica set:

> rs.initiate({_id:"rs0", members: [{_id: 1, host: "localhost:27017"}]})
{ "ok" : 1 }
rs0:OTHER> quit()

Lair APP

Next, we will download and run the lair app. In a new tab:

Download and extract the latest app tarball for your operating system from here:

$ wget https://github.com/lair-framework/lair/releases/download/v2.5.0/lair-v2.5.0-linux-amd64.tar.gz
$ tar -zxvf lair-v2.5.0-linux-amd64.tar.gz
$ cd bundle

The app runs with the latest versions of node. We'll use nvm to install this along side any existing node.js installs. Install nvm (piping into sh here, feel free to use the manual instructions):

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash
$ source ~/.bashrc

Next, find the latest LTS version of node from the Node.js site here. As of the writing of this document, this version is v6.9.1. Install this with nvm:

$ nvm install v6.9.1

You are now using node.js v6.9.1. You can use this version whenever you need to with nvm use v6.9.1

Now we need to install node.js dependencies using npm:

$ cd programs/server
$ sudo apt-get install g++
$ npm i
$ cd ../../

Next, we'll setup our required environment variables, consult Meteor documentation or the README in the current directory for more information:

$ export ROOT_URL=http://localhost
$ export PORT=11014
$ export MONGO_URL=mongodb://localhost:27017/lair
$ export MONGO_OPLOG_URL=mongodb://localhost:27017/local

Finally, start the service:

$ node main.js
Created admin@localhost with password e5a8c667aafbec3

On first run, the app will create the user admin@localhost with a random password. This will be how you initially login to the app.

Lair API

Next, we will download run our API. In a new tab:

Download the latest binary for your operating system here:

$ cd ../../../
$ wget https://github.com/lair-framework/api-server/releases/download/v1.1.0/api-server_linux_amd64
$ chmod +x api-server_linux_amd64

Setup the needed environment variables and start:

$ export MONGO_URL=mongodb://localhost:27017/lair
$ export API_LISTENER=localhost:11015
$ ./api-server_linux_amd64 
2015/09/10 07:25:42 Listening on localhost:11015

Reverse HTTPS Proxy

Finally, we'll use Caddy as a reverse HTTPS proxy. In a new tab:

Download and extract Caddy for your operating system:

$ curl -L -o caddy.tar.gz https://github.com/mholt/caddy/releases/download/v0.8.1/caddy_linux_amd64.tar.gz
$ tar -zxvf caddy_linux_amd64_custom.tar.gz 

Generate SSL certificate:

$ openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 9999

Write the following into a file called Caddyfile:

# Change localhost to the interface you want to listen on.
0.0.0.0:11013
tls cert.pem key.pem
proxy /api localhost:11015
proxy / localhost:11014 {
  websocket
}

Start the proxy:

$ ./caddy --conf=Caddyfile
0.0.0.0:11013

You can now browse to lair at https://127.0.0.1:11013.

Using Docker

https://github.com/ryhanson/lair-docker

Start up script

f41c0r has provided the script below that will manage starting and stopping lair and it's required dependencies. Copy the below into a file and execute it, it will launch all the necessary components. Hitting any key while the script is running should kill all the necessary processes and shut down all the components:

export ROOT_URL=http://localhost
export PORT=11014
export MONGO_URL=mongodb://localhost:27017/lair
export MONGO_OPLOG_URL=mongodb://localhost:27017/local
export API_LISTENER=localhost:11015
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

./mongodb-linux-x86_64-3.2.1/bin/mongod --dbpath=db --bind_ip=localhost --quiet --nounixsocket --replSet rs0 &
MONGOPROCESS=$!
sleep 3
cd bundle; nvm use v6.9.1; node main.js &
cd ../; ./api-server_linux_amd64 &
APIPROCESS=$(ps aux | grep "\.\/api-server_linux_amd64" | grep -v "grep" | tr -s ' ' | cut -f 2 -d ' ')
sleep 2
./caddy --conf=Caddyfile &
CADDYPROCESS=$!

trap "{ kill $MONGOPROCESS ; kill $CADDYPROCESS ; kill $APIPROCESS ; exit 1 }" SIGINT SIGTERM EXIT

read towait