Installing CKAN 2.0 on mac os x 10.8.4 (mountain lion)

CKAN 2.0 설치 document 에는 Ubuntu만을 기준으로 설명되어 있고, Mac을 포함한 다른 OS에서는 source를 사용해야 합니다. 그러나 막상 진행해보면 막히는 부분이 너무 많아서, 전체 순서를 정리해두려 합니다. 기본적인 참고 문서는 http://docs.ckan.org//en/latest/install-from-source.html 입니다.

 

[required packages]

 

[virtualenv 구성]

mkdir -p ~/ckan/lib
sudo ln -s ~/ckan/lib /usr/lib/ckan
mkdir -p ~/ckan/etc
sudo ln -s ~/ckan/etc /etc/ckan
sudo mkdir -p /usr/lib/ckan/default
sudo chown $(whoami) /usr/lib/ckan/default
virtualenv --no-site-packages /usr/lib/ckan/default
. /usr/lib/ckan/default/bin/activate

 

[ckan 설치]

pip install -e 'git+https://github.com/okfn/ckan.git@ckan-2.0#egg=ckan'
pip install -r /usr/lib/ckan/default/src/ckan/pip-requirements.txt
deactivate
. /usr/lib/ckan/default/bin/activate

 

[PostgreSQL]

– 초기화, 시작

pg_ctl init -D /data/postgres
pg_ctl start -D /data/postgres

– user 생성

createuser -S -D -R -P ckan_default
createdb -O ckan_default ckan_default -E utf-8
createuser -S -D -R -P datastore_default
createdb -O ckan_default datastore_default -E utf-8

– super user 생성

createuser -S -D -R -P --superuser postgres

 

[ckan config]

sudo mkdir -p /etc/ckan/default
sudo chown -R $(whoami) /etc/ckan
cd /usr/lib/ckan/default/src/ckan/
sudo paster make-config ckan /etc/ckan/default/development.ini

– development.ini 수정/확인

sqlalchemy.url = postgresql://ckan_default:pass@localhost/ckan_default
ckan.site_id = default

 

[setup solr]

– 설치

brew tap homebrew/versions
brew install solr14
brew untap homebrew/versions

– ckan schema 연결 (solr single core 세팅: ckan 2.0만 사용할 것이므로)

cd /usr/local/Cellar/solr14/1.4.1/libexec/example
sudo mv solr/conf/schema.xml solr/conf/schema.xml.bak
sudo ln -s ~/ckan/lib/default/src/ckan/ckan/config/solr/schema-2.0.xml solr/conf/schema.xml

– ckan에 solr 세팅 (development.ini 수정)

solr_url=http://127.0.0.1:8983/solr // 주석 제거

– 시작

java -jar /usr/local/Cellar/solr14/1.4.1/libexec/example/start.jar

 * /usr/local/Cellar/solr14/1.4.1/libexec/example 하위에 수동으로 logs 폴더를 생성해줘야 에러가 발생하지 않음

 * http://localhost:8983/solr/admin/ 으로 solr admin 페이지 로딩 확인

[ckan database table 생성]

cd /usr/lib/ckan/default/src/ckan
paster db init -c /etc/ckan/default/development.ini

 

[start ckan]

paster serve /etc/ckan/default/development.ini

http://localhost:5000 으로 ckan 페이지 로딩 확인

 

[link to who.ini]

sudo ln -s /usr/lib/ckan/default/src/ckan/who.ini /etc/ckan/default/who.ini

 

[setup the datastore] 

  • http://docs.ckan.org//en/latest/datastore.html 참고

– development.ini 수정

// 현재 plugin 목록에 datastore plug-in 추가
ckan.plugins = datastore

// 아래 두 줄 주석제거
ckan.datastore.write_url = postgresql://ckan_default:ckan@localhost/datastore_default
ckan.datastore.read_url = postgresql://datastore_default:pass@localhost/datastore_default

– set permissions

paster --plugin=ckan datastore set-permissions {system-account} -c /etc/ckan/default/development.ini

예:

paster --plugin=ckan datastore set-permissions Seonho -c /etc/ckan/default/development.ini

 

– test the set-up

1. ckan 재구동

2. test resource 생성

· ckan 홈페이지에서 테스트용 dataSet 생성 및 data 등록

· 생성한 data의 정보조회 -> additional information에서 id 확인

· 계정정보에서 api key 확인

curl -X POST http://127.0.0.1:5000/api/3/action/datastore_create -H "Authorization: {YOUR-API-KEY}" -d '{"resource_id": "{RESOURCE-ID}", "fields": [ {"id": "a"}, {"id": "b"} ], "records": [ { "a": 1, "b": "xyz"}, {"a": 2, "b": "zzz"} ]}'

예:

curl -X POST http://127.0.0.1:5000/api/3/action/datastore_create -H "Authorization:035ac8a1-ef95-4a04-a9fd-3d67ec99b955" -d '{"resource_id":"c570ffc4-c0c0-4171-9a8f-f2ed8b86be31", "fields": [ {"id": "a"}, {"id": "b"} ], "records": [ { "a": 1, "b": "xyz"}, {"a": 2, "b": "zzz"} ]}'

 

3. test resource 확인

curl -X GET http://127.0.0.1:5000/api/3/action/datastore_search?resource_id={resource_id}

예:

예: curl -X GET http://127.0.0.1:5000/api/3/action/datastore_search?resource_id=c570ffc4-c0c0-4171-9a8f-f2ed8b86be31

 

4. test resource 삭제

curl -X POST http://127.0.0.1:5000/api/3/action/datastore_delete -H "Authorization: {035ac8a1-ef95-4a04-a9fd-3d67ec99b955}" -d '{"resource_id": "{c570ffc4-c0c0-4171-9a8f-f2ed8b86be31}"}'

예:

curl -X POST http://127.0.0.1:5000/api/3/action/datastore_delete -H "Authorization:035ac8a1-ef95-4a04-a9fd-3d67ec99b955" -d '{"resource_id":"c570ffc4-c0c0-4171-9a8f-f2ed8b86be31"}'

 

[ckan test]

http://docs.ckan.org//en/latest/test.html 참고

– installing additional dependencies

pip install -r /usr/lib/ckan/default/src/ckan/pip-requirements-test.txt

– testing

/usr/lib/ckan/default/src/ckan 에 development.ini 복사

cd /usr/lib/ckan/default/src/ckan
nosetests --ckan ckanext/stats
nosetests --ckan ckanext
nosetests --ckan

 

Author: Seonho Kim