Skip to content

Install Native

Robert Hafner edited this page Apr 15, 2018 · 3 revisions

Dependencies

First install a few dependencies that will be needed later.

sudo apt-get -f -y install git nano man python3-pip python3-dev virtualenv

RabbitMQ

Nebula needs a queuing service. Any AQMP service will do, and RabbitMQ is as good as any on the scale we need.

sudo apt-get -f -y install rabbitmq-server

PostgreSQL

Install the postgresql packages, including some extensions.

sudo apt-get -f -y install postgresql postgresql-contrib libpq-dev

Now create the user and database (make sure to replace password with something more secure).

sudo -u postgres psql -c "CREATE USER nebula WITH PASSWORD 'password';"
sudo -u postgres psql -c "create database \"nebula\" with owner \"nebula\" encoding='utf8' template template0"

User

Next create the system level user to run the application.

sudo useradd -N -M --system -s /bin/bash nebula
sudo groupadd nebula
sudo adduser nebula nebula

Nebula Install

First clone the repository and enter it on your local system.

git clone https://github.com/tedivm/nebula.git
cd nebula

At this point you can switch to a different tag or branch depending on your requirements.

Now to configure Nebula. You should start with the example configuration file and edit as needed, referencing the configuration documentation for any questions.

cp settings.dist.yaml settings.yaml
nano settings.yaml

Next create the virtualenv and install the project dependencies.

virtualenv -p /usr/bin/python3 env
source env/bin/activate
pip install -r requirements.txt

If there are any errors during the install make sure to deal with them now.

Once that's done (and assuming there are no errors), deactivate the virtualenv and return to the parent directory.

deactivate
cd ..

Now move the files into /opt/nebula and set their owner to root, and then enter that directory.

sudo cp -R nebula /opt/nebula
sudo chown -R root:root /opt/nebula
cd /opt/nebula

Finally, lets activate the virtualenv and flask app to configure and upgrade the database.

source venv/bin/activate
export SETTINGS=/opt/settings
export FLASK_APP=/opt/nebula/nebula.py
python db/manage.py version_control
python db/manage.py upgrade

Configure Services (upstart)

App

Create this file at /etc/init/nebula_app.conf.

description "Nebula Gunicorn application"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid nebula
setgid www-data

env PATH=/opt/nebula/env/bin
env SETTINGS=/opt/nebula/settings.yaml
env FLASK_APP=/opt/nebula/nebula/nebula.py
chdir /opt/nebula
exec /opt/nebula/env/bin/gunicorn --workers 3 --bind unix:/tmp/nebula.sock -m 007 nebula:app

Worker

Create this file at /etc/init/nebula_worker.conf.

description "Nebula Celery Worker"

start on runlevel [2345]
stop on runlevel [!2345]

kill timeout 20
setuid nebula
setgid nebula

respawn
chdir /opt/nebula/project/
exec /home/nebula/bin/worker.sh

Start the Services

sudo systemctl enable nebula_app
sudo systemctl start nebula_app
sudo systemctl enable nebula_worker
sudo systemctl start nebula_worker

NGINX Proxy

/etc/nginx/nginx.conf

worker_processes 1;

events {
    worker_connections 1024;
}

http {

    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration containing list of application servers
    upstream app_servers {
        server unix:/tmp/nebula.sock;
    }

    # Configuration for Nginx
    server {

        # Running port
        listen 80;

        # Settings to serve static files 
        location ^~ /static/  {
            root /opts/nebula/nebula/static/;
        }

        # Proxy connections to the application servers
        # app_servers
        location / {

            proxy_pass         http://app_servers;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

        }
    }
}

Now restart nginx

sudo systemctl stop nginx
sudo systemctl start nginx