메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다. 문의사항은 gooper@gooper.com로 메일을 보내주세요.


0. hadoop, hbase, tomcat등이 이미 서버에 설치되어 있어야 한다.


1. eclipse에서 https://github.com/Merck/Halyard를 import한다.

  가. File->Import->Projects from Git를 선택한다.

  나. Select Repository Source를 Clone URI를 선택한다.

  다. URI에 https://github.com/Merck/Halyard를 입력한다.

  라. Branch Selection에서 master를 선택한다.

  마. Local Destination의 Directory를 디폴트로 선택한다

  바. Finish를 선택하면 github에서 소스를 받아 로컬 리포지토리에 저장하고 eclipse 프로젝트를 생성해준다.


* verion up등으로 git pull했을때 충돌이 발생하면 git stash -> git pull -> git pop순서데로 처리해서 로컬에 반영해준다.

           (참조 : http://vezi95.blogspot.kr/2016/05/git-pull.html)


2. halyard를 eclipse에서 build 한다.

  가. halyard폴더의 pom.xml을 선택하고 -> Run As -> Maven Build..-> goal에 package를 입력및 Skip Tests선택후 Run한다.

  나. 이때 몇가지 오류가 발생하는데 Windows RegCreateKeyEx(...) returned error code 5. 가 발생하면 아래를 참조한다.

  다. halyard-sail, halyard-tools 프로젝트에서 halyard-common.jar관련 dependency오류가 발생하면 아래처럼 주석처리한다.

        <!--  dependency>

            <groupId>${project.groupId}</groupId>

            <artifactId>halyard-common</artifactId>

            <version>${project.version}</version>

            <type>test-jar</type>

            <scope>test</scope>

        </dependency -->


3. web모듈을 tomcat서버에 deploy한다.

 가. Halyard/webapps/target에 생성된 rdf4j-server.war, rdf4j-workbench.war를 tomcat webapps에 복사하여 디플로이한다.

     (halyard-webapps-1.1-SNAPSHOT.zip파일에도 동일한 파일이 압축되어있다)

 나. http://sda1/rdf4j-server/, http://sda1/rdf4j-workbench/로 웹에서 접근가능하나 rdf4j-server는 workbench에서 사용되므로 외부에 노출시켜서는 안된다.

 다. tomcat의 bin 폴더에 setenv.sh파일을 생성하고 아래의 내용을 추가한후 tomcat를 재기동한다.(이것을 설정하지 않으면 rdf4j-workbench를 브라우저에서 조회시 Hbase class관련 오류를 방지할 수 있다)

export CLASSPATH=$CLASSPATH:"$JAVA_HOME/jre/lib/ext/servlet-api.jar:"`$HOME/hadoop/bin/hadoop classpath`:`$HOME/hbase/bin/hbase classpath`


4. Halyard SDK를 서버에 복사/압축해제한다.

  가. RDF4J에서 제공하는 기능에 Hbase를 추가한 버젼이며 repository를 생성하고 삭제하는 등의 작업을 command라인에서 수행할 수 있다.

    (http://sda1/rdf4j-workbench/를 이용하면 web에서 동일한 작업을 할 수 있다)

  나. 서버의 특정 위치에 폴더(예, halyard-sdk)를 만들고 Halyard/sdk/target/halyard-sdk-1.1-SNAPSHOT.zip를 업로드 한후 압축을 푼다.(unzip halyard-sdk-1.1-SNAPSHOT.zip)

  다. 압축을 풀면 폴더내에 아래와 같은 실행파일등이 생성된다.

LICENSE  LICENSES_THIRD_PARTY  bulkload  bulkupdate  console  export  halyard-sdk-1.1-SNAPSHOT.zip  hiveload  img  index.html  lib  pexport  update


  라.RDF4J console 실행(테스트)

     - ./console

   * console실행시 오류가 발생하면 아래를 참조하여 정확한 경로를 지정해준다.

 

-bash-4.1$ cat console
#!/bin/sh
lib="$(dirname "${0}")/lib"
#java -Xmx2G -cp "$lib/halyard-tools-1.1-SNAPSHOT.jar:"`hadoop classpath`":"`hbase classpath` org.eclipse.rdf4j.console.Console "$@"
java -Xmx2G -cp "$lib/halyard-tools-1.1-SNAPSHOT.jar:"`hadoop classpath`":"`$HOME/hbase/bin/hbase classpath` org.eclipse.rdf4j.console.Console "$@"

5. console작업(예시)

  가. Repository생성 (query timeout : 604800(60*60*24*7), defualt: 180초)

    

> create hbase   
Please specify values for the following variables:
Repository ID: testRepo
Repository title: 
HBase Table Name: 
Create HBase Table if missing (true|false) [true]: 
HBase Table presplit bits [0]: 
Use Halyard Push Evaluation Strategy (true|false) [true]: 
Query Evaluation Timeout [180]: 604800
Repository created


  나. 생성된 Repository에 접속

> open testRepo
Opened repository 'testRepo'


  다. sparql실행(등록된 데이타 없는 상태)(여러줄을 입력할 수 있고 마지막 줄에 '.'을 입력하면 쿼리가 수행된다.)

testRepo> sparql
enter multi-line SPARQL query (terminate with line containing single '.')
select * where {?s ?p ?o} limit 10
.
Evaluating SPARQL query...
+------------------------+------------------------+------------------------+
| s                      | p                      | o                      |
+------------------------+------------------------+------------------------+
+------------------------+------------------------+------------------------+
0 result(s) (27 ms)

  라. data파일 로드(약 905336건)

testRepo> load /home/gooper/aa/test.nq
Loading data...
Data has been added to the repository (83878 ms)


  마. sparql 실행(등록된 데이타 있음)

testRepo> sparql
enter multi-line SPARQL query (terminate with line containing single '.')
select * where {?s ?p ?o} limit 10
.
Evaluating SPARQL query...
+------------------------+------------------------+------------------------+
| s                      | p                      | o                      |
+------------------------+------------------------+------------------------+
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.w3.org/2000/01/rdf-schema#label>| ","                    |
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://purl.org/dc/elements/1.1/creator>| "TAS"                  |
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/hasLastModifiedDate>| "2015-12-23T19:34:08"^^<http://www.w3.org/2001/XMLSchema#dateTime>|
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/isContentInstanceOf>| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data>|
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>| <http://www.gooper.com/m2m/ContentInstance>|
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/hasContentValue>| "26.3"^^<http://www.w3.org/2001/XMLSchema#double>|
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/resourceName>| "CONTENT_INST_167822"  |
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/hasCreateDate>| "2015-12-23T19:34:08"^^<http://www.w3.org/2001/XMLSchema#dateTime>|
| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data/CONTENT_INST_167822>| <http://www.gooper.com/m2m/hasParentResource>| <http://www.gooper.com/herit-in/herit-cse/TempSensor_LR0001TS0004/status/Data>|
| <http://www.gooper.com/herit-in/herit-cse/UserInOutInfo_u00002/status/Data/CONTENT_INST_158789>| <http://www.w3.org/2000/01/rdf-schema#label>| ","                    |
+------------------------+------------------------+------------------------+
10 result(s) (102 ms)


* 쿼리결과가 특정시간내에 산출되지 않으면 exception이 발생한다.(Query evaluation error: Query evaluation exceeded specified timeout 180s)

* 개수 카운트

testRepo> sparql
enter multi-line SPARQL query (terminate with line containing single '.')
select (count(*) as ?cnt) where {?s ?p ?o}
.
Evaluating SPARQL query...
+-----------------------------------------------------------------------------+
| cnt                                                                           |
+-----------------------------------------------------------------------------+
| "919049"^^<http://www.w3.org/2001/XMLSchema#integer>                        |
+-----------------------------------------------------------------------------+
1 result(s) (8468 ms)


   바. console명령어

List of all commands:
help        Displays this help message
info        Shows info about the console
connect     Connects to a (local or remote) set of repositories
disconnect  Disconnects from the current set of repositories
create      Creates a new repository
federate    Federate existing repositories.
drop        Drops a repository
open        Opens a repository to work on, takes a repository ID as argument
close       Closes the current repository
show        Displays an overview of various resources
load        Loads a data file into a repository, takes a file path or URL as argument
verify      Verifies the syntax of an RDF data file, takes a file path or URL as argument
clear       Removes data from a repository
sparql      Evaluate a SPARQL query
serql       Evaluate a SeRQL query
set         Allows various console parameters to be set
exit, quit  Exit the console


6. bulkload쉘 사용(예시)

  가. bulkload파일을 현재 상황에 맞게 패스등을 변경한다.

-bash-4.1$ cat bulkload 
#!/bin/sh
lib="$(dirname "${0}")/lib"
libjars="$(echo "$lib"/*.jar | tr ' ' ',')"
export HADOOP_CLASSPATH=`$HOME/hadoop/bin/hadoop classpath`:`$HOME/hbase/bin/hbase classpath`
#hadoop jar lib/halyard-tools-1.1-SNAPSHOT.jar com.msd.gin.halyard.tools.HalyardBulkLoad -conf /etc/hbase/conf/hbase-site.xml -libjars $libjars "$@"
hadoop jar lib/halyard-tools-1.1-SNAPSHOT.jar com.msd.gin.halyard.tools.HalyardBulkLoad -conf $HOME/hbase/conf/hbase-site.xml -libjars $libjars "$@"

  나. bulkload 실행(데이타 파일은 test.nq.gz파일을 이용함)

    - halyard 작업디렉토리 생성 : hdfs dfs -mkdir halyard

    - data저장 디렉토리 생성 : hdfs dfs -mkdir halyard/input

    - data upload : hdfs dfs -put test.nq.gz halyard/input

    - bulkload실행(오류가 발생하면 Exception발생) : ./bulkload halyard/input halyard/temp testRepo

    - bulkload실행(오류가 있어도 Exception발생하지 않고 진행함) : ./bulkload -Dhalyard.parser.skipinvalid=true halyard/input halyard/temp testRepo

   


A personal place to organize information learned during the development of such Hadoop, Hive, Hbase, Semantic IoT, etc.
We are open to the required minutes. Please send inquiries to gooper@gooper.com.

위로