Skip to content
Diego Rabatone Oliveira edited this page Dec 14, 2015 · 5 revisions

#Pre-setup

Run as root when needed, at your best judgment.

Before setting up the opendatacensus requested packages, we need to install some general system packages:

  • curl
  • build-essential (To compile and install native addons from npm)
  • git

# apt install -y curl build-essential git

Installing node.js

The current version of node.js requested by opendatacensus is 4.1

Reference on how to install it

# curl -sL https://deb.nodesource.com/setup_4.x | bash -
# apt install -y nodejs

Setting up Postgresql

The current requested version of Postgresql is 9.4

Installing Postgresql: # apt install postgresql-9.4

As an example, we will run the OpenDataCensus app with the opendatacensus user. This will also be the name of the postgresql user. If you wish you can use other names to the system user and postgresql user, but you will need to correctly set the names on the config files.

First Steps

First connect/login as root, and then su to postgresql user

$ su
# su - postgres
$ psql
postgres=# help

Create a schema called opendatacensus in the default database called postgres

postgres=# CREATE SCHEMA opendatacensus;

Create a role (user) with password. Here we will name the role (user) as opendatacensus

postgres=# CREATE USER opendatacensus PASSWORD 'yyy';

Grant privileges (like the ability to create tables) on new schema to new role

postgres=# GRANT ALL ON SCHEMA opendatacensus TO xxx;

Grant privileges (like the ability to insert) to tables in the new schema to the new role

postgres=# GRANT ALL ON ALL TABLES IN SCHEMA test TO xxx;

Grant privilege to create databases to the xxx user:

ALTER ROLE xxx CREATEDB;

Disconnect

postgres=# \q

Became a standard user.

$ exit
# exit

Setting up nginx as reverse proxy to node/npm [optional]

If you want the OpenDataCensus app to run on the port 80, the best way is to use a reverse proxy setup instead of running node directly on the 80 port. Here we will use nginx as the reverse proxy. The default port for opendatacensus is 5000.

Installing nginx

Not yet working ....

apt install -y nginx-light

nginx reverse_proxy setup

Edit the /etc/nginx/sites-enabled/default file with these contents, changing any values as required:

server {
    listen 80;
    server_name phili.okfn.diraol.eng.br system.okfn.diraol.eng.br;
    access_log /var/log/nginx/foo.log;
    
    location / {
        proxy_pass http://127.0.0.1:5000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        #proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header Host $http_host;
        #proxy_redirect off;
    }
}