Anda di halaman 1dari 23

Installation of CKAN 2.

5
Kamel MALLEH
Chief Computer Engineer
January 2016 @Tunisian Ministry of Culture

What is CKAN ?

CKAN is a Pylons app, built in Python.


Jinja2 the Template Engine
PostgreSQL a database backend.
SOLR a search backend.
Apache to serve as a WSGI app
NGINX as a reverse proxy cache

Install CKAN
Install from Package :
The quickest and easiest way to install CKAN.
Requires Ubuntu 14.04 64-bit or Ubuntu 12.04 64-bit.

Install from Source :


No operating system constraints,
CKAN will run on practically anything that can support Python and a web server

Complex architecture,
Separate Database or Solr host, CKAN High Availability installation

Development environment,

Install CKAN from package


Preliminary :

ssh
JDK
cURL
wget
git

Install CKAN from package


sudo apt-get update
sudo apt-get install -y nginx apache2 libpq5
libapache2-mod-wsgi redis-server
wget http://packaging.ckan.org/python-ckan_2.5trusty_amd64.deb
sudo dpkg -i python-ckan_2.5-trusty_amd64.deb

Install and configure Solr


sudo apt-get install -y solr-jetty
Javac version (sudo apt-get -y install openjdk-7-jdk)
/etc/default/jetty
NO_START=0
JETTY_HOST=127.0.0.1
JETTY_PORT=8983 # (line 19)
JETTY_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

Use the CKAN SOLR schema.xml


sudo mv /etc/solr/conf/schema.xml /etc/solr/conf/schema.xml.bak
sudo ln -s /usr/lib/ckan/default/src/ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml

Start jetty (sudo service jetty start)


Add SolrURL to /etc/ckan/default/production.ini
solr_url=http://127.0.0.1:8983/solr

Install and configure PostgreSQL


sudo apt-get install -y postgresql
Create a database user ckan_default
sudo -u postgres createuser -S -D -R -P ckan_default

Create PostgreSQL database ckan_default


sudo -u postgres createdb -O ckan_default ckan_default -E utf-8

Set in /etc/ckan/default/production.ini
sqlalchemy.url = . #set database user password
ckan.site_id = default
ckan.site_url = http://127.0.0.1

sudo ckan db init

Config file

ckan.site_title =
ckan.site_description =
ckan.datasets_per_page = 10
ckan.locale_default = fr
ckan.locales_offered = fr en ar

More details :
http://docs.ckan.org/en/latest/maintaining/configuration.html

Why Installaing CKAN


An Open source platform
Relatively easy to deploy
Provides a rich set of features for free

Data management
Publishing / Exposing metadata (API/frontend)
Searching data ~ metadata
Additional functinality via plugins

Community involvement

Why Installaing CKAN

CKAN APIs
=> http://docs.ckan.org/en/latest/api/
http://ckan_url/api/3/action/package_list ~ {group_list, user_list, tag_list, organization_list}
http://ckan_url/api/3/action/package_show?id=adur_district_spending
http://ckan_url/api/3/action/tag_show?id=gold
http://ckan_url/api/3/action/group_show?id=data-explorer
http://ckan_url/api/3/action/package_search?q=spending
http://ckan_url/api/3/action/resource_search?query=name:evolution
http://ckan_url/api/3/action/recently_changed_packages_activity_list
http://catalog.industrie.gov.tn/api/util/status

CKAN Data model

Roles & permissions


"No Role" organisation. They can only do the R in CRUD.
"Member" organisation. They can only do the R in CRUD, but can read
datasets private to that organisation.
"Editor" organisation. They can do the whole CRUD, but can't manage users
in the organisation.
"Admin" organisation. They can do the whole CRUD, and can manage users
in the organisation.
"Sysadmin" is a user that can do everything, including creating organisations.
CKAN file configuration :
ckan.auth.anon_create_dataset
ckan.auth.create_unowned_dataset
ckan.auth.create_dataset_if_not_in_organization
http://docs.ckan.org/en/latest/maintaining/authorization.html?highlight=roles

Creating a sysadmin user


Activate virtualenv :
. /usr/lib/ckan/default/bin/activate
cd /usr/lib/ckan/default/src/ckan

Create a sysadmin or promote user to sysadmin


paster sysadmin add admin -c /etc/ckan/default/production.ini

Default user ???


paster --plugin=ckan user setpass default -c
/etc/ckan/default/production.ini

FileStore and file uploads


Create the directory :
sudo mkdir -p /var/lib/ckan/default

Add the following line to CKAN config file :


ckan.storage_path = /var/lib/ckan/default

Set the permissions to the directory :


sudo chown www-data /var/lib/ckan/default
sudo chmod u+rwx /var/lib/ckan/default

sudo service apache2 reload

CKAN IS NOT
a file storage

DataStore extension 1/2


Enable the plugin :
ckan.plugins = datastore

Set-up the database :


sudo -u postgres createuser -S -D -R -P -l datastore_default
sudo -u postgres createdb -O ckan_default datastore_default -E utf-8

Set URLs in ckan file configuration


ckan.datastore.write_url =
postgresql://ckan_default:pass@localhost/datastore_default
ckan.datastore.read_url =
postgresql://datastore_default:pass@localhost/datastore_default

DataStore extension 2/2


Set permissions
Connect with progres superUser
sudo -u postgres psql
sudo ckan datastore set-permissions | sudo -u postgres psql --set ON_ERROR_STOP=1

Exit the interface


\q

How to test installation


curl -i GET
http://127.0.0.1/api/3/action/datastore_search?resource_id=_table_metadata
http://127.0.0.1/api/3/action/datastore_search?resource_id={RESOURCE_ID}

DataPusher
Automatically Add Data to the DataStore

Add in CKAN file configuration :


ckan.datapusher.url = http://0.0.0.0:8800/

Add the extension datapusher


ckan.plugins = <other plugins> datapusher

Restart apache service :


sudo service apache2 restart

Add more preview :


recline_grid_view recline_graph_view recline_map_view webpage_view

Datastore_search API
All content of resources :
http://catalog.industrie.gov.tn/api/action/datastore_search?resource_id=f28
d4664-eccf-4f8b-ac14-19da8b9a93d7
Filter content of resources By SQL :
http://catalog.industrie.gov.tn/api/action/datastore_search_sql?sql=SELECT *
from "f28d4664-eccf-4f8b-ac14-19da8b9a93d7" WHERE "Pays" LIKE '
Tunis '
Search the word Tunis :
http://catalog.industrie.gov.tn/api/action/datastore_search?resource_id=f28
d4664-eccf-4f8b-ac14-19da8b9a93d7&q=Tunis
Return only the N=5 first Item :
http://catalog.industrie.gov.tn/api/action/datastore_search?resource_id=f28
d4664-eccf-4f8b-ac14-19da8b9a93d7&limit=5

What else ?
Extension :
Install extension & configure,
Write new extension,

Theming :
Customize CKAN templates,

Not working !!!


@kamel.mellah@gmail.com
+216 97 68 48 61