|
|
419번째 줄: |
419번째 줄: |
| == Plugin == | | == Plugin == |
| | | |
− | === Plugin 구조 ===
| |
| | | |
− | <span style="color:#008000;">'''<span style="font-size: larger;">Plugin 설치 프로그램</span>'''</span>
| |
| | | |
− | 설치 프로그램 : org.elasticsearch.plugins.PluginManager
| + | [[ElasticSearch - Plugin|ElasticSearch - Plugin]] |
− | | |
− | {| border="1" cellspacing="0" cellpadding="2" style="width: 100%;"
| |
− | |-
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" rowspan="1" colspan="2" | 옵션<br/>
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 상세
| |
− | |-
| |
− | | style="text-align: center;" | -u
| |
− | | style="text-align: center;" | -url ~
| |
− | | Plugin 설치 파일 (~.zip) 다운로드 URL<br/>
| |
− | |-
| |
− | | style="text-align: center;" | -i
| |
− | | style="text-align: center;" | -install ~
| |
− | |
| |
− | 설치할 Plugin 이름<br/>plugins/Plugin_이름/ 폴더에 설치됨
| |
− | | |
− | <span style="line-height: 20.7999992370605px;">[username/]pluginname[/version]</span>
| |
− | | |
− | *user : username 사용
| |
− | *pluginname : pluginname이 "elasticsearch-" 또는 "es-"로 시작하면 이 부분을 삭제한 후 사용
| |
− | *repo : 원본 pluginname 사용
| |
− | | |
− | |-
| |
− | | style="text-align: center;" | -t
| |
− | | style="text-align: center;" | -timeout ~
| |
− | | 타임아웃 설정 (30s, 1m, 1h, ...)
| |
− | |-
| |
− | | style="text-align: center;" | -r
| |
− | | style="text-align: center;" | -remove ~
| |
− | | 삭제할 Plugin 이름
| |
− | |- | |
− | | style="text-align: center;" | -l
| |
− | | style="text-align: center;" | -list
| |
− | | 설치된 Plugin 목록 표시
| |
− | |-
| |
− | | style="text-align: center;" | -v
| |
− | | style="text-align: center;" | -verbose
| |
− | | 상세 정보 표시
| |
− | |-
| |
− | | style="text-align: center;" | -s
| |
− | | style="text-align: center;" | -silent
| |
− | | Silent 모드로 실행
| |
− | |-
| |
− | | style="text-align: center;" | -h
| |
− | | style="text-align: center;" | -help
| |
− | | 도움말 표시
| |
− | |}
| |
− | | |
− | | |
− | | |
− | <span style="color:#008000;">'''<span style="font-size:larger;">Plugin 설치 파일 다운로드 위치</span>'''</span>
| |
− | <ul style="line-height: 20.7999992370605px;">
| |
− | <li>"[https://github.com/ https://github.com/]" + user + "/" + repo + "/archive/master.zip"</li>
| |
− | <li>"[http://download.elasticsearch.org/ http://download.elasticsearch.org/]" + user + "/" + repo + "/" + repo + "-" + version + ".zip"</li>
| |
− | <li>"[http://search.maven.org/remotecontent?filepath= http://search.maven.org/remotecontent?filepath=]" + user.replace('.', '/') + "/" + repo + "/" + version + "/" + repo + "-" + version + ".zip"</li>
| |
− | <li>"[https://oss.sonatype.org/service/local/repositories/releases/content/ https://oss.sonatype.org/service/local/repositories/releases/content/]" + user.replace('.', '/') + "/" + repo + "/" + version + "/" + repo + "-" + version + ".zip"</li>
| |
− | <li>"[https://github.com/ https://github.com/]" + user + "/" + repo + "/archive/" + version + ".zip"</li>
| |
− | </ul>
| |
− | | |
− | | |
− | | |
− | <span style="color:#008000;">'''<span style="font-size:larger;">Plugin 설치 파일 폴더 구조</span>'''</span>
| |
− | | |
− | ~.zip 파일
| |
− | | |
− | {| border="1" cellspacing="0" cellpadding="2" style="width: 100%;"
| |
− | |-
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" rowspan="1" colspan="2" | 폴더<br/>
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 상세
| |
− | |-
| |
− | | 플러그인명-버전/
| |
− | | <br/>
| |
− | | <ul style="line-height: 20.7999992370605px;">
| |
− | <li>기본적으로 모든 파일은 plugins/플러그인명/ 폴더에 배포 됩니다.</li>
| |
− | <li>bin/, config/, _site/ 폴더가 없고
| |
− | *.class/.jar 파일이 없는 경우, plugins/플러그인명/_site/ 폴더에 배포 됩니다.
| |
− | *.class/.jar 파일이 있을 경우, plugins/플러그인명/ 폴더에 배포 됩니다.</li>
| |
− | | |
− | | |
− | |-
| |
− | | <br/>
| |
− | | _site/
| |
− | |
| |
− | *index.html : 시작 페이지
| |
− | | |
− | |-
| |
− | | <br/>
| |
− | | bin/
| |
− | |
| |
− | *bin/플러그인명/ 폴더에 배포 됩니다.
| |
− | | |
− | |-
| |
− | | <br/>
| |
− | | config/
| |
− | |
| |
− | *config/플러그인명/ 폴더에 배포 됩니다.
| |
− | | |
− | |-
| |
− | | <br/>
| |
− | | _dict/
| |
− | | <br/>
| |
− | |}
| |
− | | |
− | === Site Plugin ===
| |
− | | |
− | plugins/head/_site/ 폴더가 생성 됩니다.
| |
− | | |
− | [http://node111.jopenbusiness.com:9200/_plugin/head/ http://node111.jopenbusiness.com:9200/_plugin/head/] URL로 접속할 수 있습니다.
| |
− | | |
− | === JVM Plugin ===
| |
− | | |
− | jar 파일에 들어 있는 es-plugin.properties 파일
| |
− | | |
− | *plugin=org.elasticsearch.plugin.analysis.kr.AnalysisKoreanPlugin : 플러그인 설치 파일
| |
− | **org.elasticsearch.plugins.AbstractPlugin 파일을 구현한 class
| |
− | *version=~ : Plugin 버전
| |
− | *description=~ : Plugin 설명
| |
− | *lucene=~ : Lucene 버전
| |
− | | |
− | | |
− | | |
− | 플러그인 설치 파일의 구성 함수
| |
− | | |
− | {| border="1" cellspacing="0" cellpadding="2" style="width: 100%;"
| |
− | |-
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 종류
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 관련 class
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 상세
| |
− | |-
| |
− | | style="text-align: center;" | name()
| |
− | | style="text-align: center;" | <br/>
| |
− | | Plugin 이름
| |
− | |-
| |
− | | style="text-align: center;" | description()
| |
− | | style="text-align: center;" | <br/>
| |
− | | Plugin 설명
| |
− | |-
| |
− | | style="text-align: center;" | modules()
| |
− | | style="text-align: center;" | Module
| |
− | | Node level modules<br/><span style="line-height: 20.7999992370605px;">org.elasticsearch.plugins.PluginsModule</span><br/>
| |
− | |-
| |
− | | style="text-align: center;" | indexModules()
| |
− | | style="text-align: center;" | Module
| |
− | | Per index modules<br/>org.elasticsearch.plugins.IndexPluginsModule<br/>
| |
− | |-
| |
− | | style="text-align: center;" | shardModules()
| |
− | | style="text-align: center;" | Module
| |
− | | Per index shard module<br/><span style="line-height: 20.7999992370605px;">org.elasticsearch.plugins.ShardPluginsModule</span><br/>
| |
− | |-
| |
− | | style="text-align: center;" | services()
| |
− | | style="text-align: center;" | LifecycleComponent
| |
− | | Node level services<br/>
| |
− | |-
| |
− | | style="text-align: center;" | indexServices()
| |
− | | style="text-align: center;" | CloseableIndexComponent
| |
− | | Per index services
| |
− | |-
| |
− | | style="text-align: center;" | shardServices()
| |
− | | style="text-align: center;" | <span style="line-height: 20.7999992370605px; text-align: center;">CloseableIndexComponent</span><br/>
| |
− | | Per index shard services
| |
− | |-
| |
− | | style="text-align: center;" | processModule()
| |
− | | style="text-align: center;" | Module
| |
− | | <br/>
| |
− | |-
| |
− | | style="text-align: center;" | additionalSettings()
| |
− | | style="text-align: center;" | <br/>
| |
− | | Plugin이 로딩될 때 추가되는 node 설정
| |
− | |-
| |
− | | style="text-align: center;" | <span style="color:#0000FF;">onModule(AnyModule module)</span><br/>
| |
− | | style="text-align: center;" | <br/>
| |
− | | 모듈이 로딩될 때, 실행되는 함수<br/>
| |
− | |}
| |
− | | |
− | | |
− | | |
− | 참고 문헌
| |
− | | |
− | *[http://blog.iterativ.ch/2014/04/11/listindices-writing-your-first-elasticsearch-java-plugin/ http://blog.iterativ.ch/2014/04/11/listindices-writing-your-first-elasticsearch-java-plugin/]
| |
− | | |
− | === 유용한 Plugin ===
| |
− | | |
− | {| border="1" cellspacing="0" cellpadding="2" style="width: 100%;"
| |
− | |-
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 종류
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | Plugin
| |
− | | style="text-align: center; background-color: rgb(241, 241, 241);" | 상세
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Korean Analytis 한글 형태소 분석기
| |
− | | plugin -install chanil1218/elasticsearch-analysis-korean/1.3.0<br/>또는<br/>plugin -url [https://dl-web.dropbox.com/spa/grpekzky9x5y6mc/elastic-analysis-korean/public/elasticsearch-analysis-korean-1.3.0.zip https://dl-web.dropbox.com/spa/grpekzky9x5y6mc/elastic-analysis-korean/public/elasticsearch-analysis-korean-1.3.0.zip] -install analysis-korean
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Head Plugin
| |
− | | <span style="line-height: 20.7999992370605px;">인덱스와 샤드, 도큐먼트에 대한 관리 및 상태 점검</span><br/><span style="line-height: 20.7999992370605px;">기본적인 검색 질의 기능 제공</span><br/>plugin -install mobz/elasticsearch-head<br/>[http://node111.jopenbusiness.com:9200/_plugin/head/ http://node111.jopenbusiness.com:9200/_plugin/head/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | JVM/Site
| |
− | | style="text-align: center;" | Marvel Plugin
| |
− | | <span style="line-height: 20.7999992370605px;">노드에 대한 stats 정보를 인덱스에 색인하여 검색과 대시보드 형태로 제공</span><br/>[http://www.jopenbusiness.com/mediawiki/Logstash Logstash]<span style="line-height: 20.7999992370605px;">와 </span>[http://www.jopenbusiness.com/mediawiki/Kibana Kibana]<span style="line-height: 20.7999992370605px;"> 기반으로 구성</span><br/>plugin -i elasticsearch/marvel/latest<br/>[http://node111.jopenbusiness.com:9200/_plugin/marvel/ http://node111.jopenbusiness.com:9200/_plugin/marvel/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Bigdesk Plugin
| |
− | | <span style="line-height: 20.7999992370605px;">실시간으로 서버와 검색 엔진의 상태, 자원 현황을 실시간 모니터링</span><br/>plugin -install lukas-vlcek/bigdesk<br/>[http://node111.jopenbusiness.com:9200/_plugin/bigdesk/ http://node111.jopenbusiness.com:9200/_plugin/bigdesk/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Sense
| |
− | | <span style="line-height: 20.7999992370605px;">REST API를 실행하고 결과를 확인</span><br/>plugin -install bleskes/sense<br/>[http://node111.jopenbusiness.com:9200/_plugin/sense/ http://node111.jopenbusiness.com:9200/_plugin/sense/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Elasticsearch HQ<br/>
| |
− | | <span style="line-height: 20.7999992370605px;">head와 bigdesk의 기능이 합쳐진 plugin</span><br/>plugin -install royrusso/elasticsearch-HQ<br/>[http://node111.jopenbusiness.com:9200/_plugin/HQ/ http://node111.jopenbusiness.com:9200/_plugin/HQ/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Hammer Plugin<br/>
| |
− | | <span style="line-height: 20.7999992370605px;">검색 질의와 결과를 제공</span><br/>plugin -install andrewvc/elastic-hammer<br/>[http://node111.jopenbusiness.com:9200/_plugin/elastic-hammer/ http://node111.jopenbusiness.com:9200/_plugin/elastic-hammer/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Inquisitor Plugin<br/>
| |
− | | <span style="line-height: 20.7999992370605px;">검색 질의와 결과를 제공</span><br/><span style="line-height: 20.7999992370605px;">형태소 분석 기능 제공</span><br/>plugin -install polyfractal/elasticsearch-inquisitor<br/>[http://node111.jopenbusiness.com:9200/_plugin/inquisitor/ http://node111.jopenbusiness.com:9200/_plugin/inquisitor/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | Paramedic Plugin<br/>
| |
− | | <span style="line-height: 20.7999992370605px;">실시간 서버 모니터링 (bigdesk와 유사)</span><br/>plugin -install karmi/elasticsearch-paramedic<br/>[http://node111.jopenbusiness.com:9200/_plugin/paramedic/ http://node111.jopenbusiness.com:9200/_plugin/paramedic/]<br/>
| |
− | |-
| |
− | | style="text-align: center;" | Site
| |
− | | style="text-align: center;" | SegmentSpy Plugin<br/>
| |
− | | <span style="line-height: 20.7999992370605px;">인덱스와 샤드 정보 제공</span><br/>plugin -install polyfractal/elasticsearch-segmentspy<br/>[http://node111.jopenbusiness.com:9200/_plugin/segmentspy/ http://node111.jopenbusiness.com:9200/_plugin/segmentspy/]<br/>
| |
− | |}
| |
− | | |
− | === 한글 형태소 분석기 Plugin ===
| |
− | | |
− | [https://github.com/chanil1218/elasticsearch-analysis-korean Korean Analysis for ElasticSearch (http://github.com/chanil1218/elasticsearch-analysis-korean)] 사이트에서 한글 형태소 분석기 Plugin을 설치 합니다. ElasticSearch용 한글 형태소 분석기 Plugin은 "루씬 한글분석기 오픈소스 프로젝트"를 가져와 작성이 되었습니다.
| |
− | | |
− | | |
− | | |
− | 루씬 한글분석기 오픈소스 프로젝트
| |
− | | |
− | *카페 : [http://cafe.naver.com/korlucene http://cafe.naver.com/korlucene]
| |
− | *SourceForge : [http://sourceforge.net/projects/lucenekorean http://sourceforge.net/projects/lucenekorean]
| |
− | *SVN : [https://lucenekorean.svn.sourceforge.net/svnroot/lucenekorean https://lucenekorean.svn.sourceforge.net/svnroot/lucenekorean]
| |
− | *CVS : d:pserver:anonymous@lucenekorean.cvs.sourceforge.net:/cvsroot/lucenekorean
| |
− | | |
− | | |
− | | |
− | <span style="color:#008000;"><span style="font-size:larger;">'''한글 형태소 분석기 Plugin 설치'''</span></span>
| |
− | | |
− | {| cellspacing="1" cellpadding="1" style="font-size: 14px; color: rgb(37, 37, 37); font-family: sans-serif; line-height: 20.7999992370605px; width: 100%;"
| |
− | |-
| |
− | | style="background-color: rgb(241, 241, 241);" |
| |
− | bin/plugin -install chanil1218/elasticsearch-analysis-korean/1.3.0
| |
− | | |
− | 만일 위 명령어로 설치시 오류가 발생하면 아래와 명령어로 설치를 다시 진행 합니다.<br/>bin/plugin -url [https://dl-web.dropbox.com/spa/grpekzky9x5y6mc/elastic-analysis-korean/public/elasticsearch-analysis-korean-1.3.0.zip https://dl-web.dropbox.com/spa/grpekzky9x5y6mc/elastic-analysis-korean/public/elasticsearch-analysis-korean-1.3.0.zip] -install analysis-korean
| |
− | | |
− | |}
| |
− | | |
− | 설치가 정상적으로 완료되면 plugins/analysis-korean/elasticsearch-analysis-korean-1.3.0.jar 파일을 확인할 수 있습니다.
| |
− | | |
− | | |
− | | |
− | ----
| |
− | | |
− | *설치 후 확인
| |
− | | |
− | :*동작 확인
| |
− | ::*korea 인덱스 삭제
| |
− | | |
− | curl -XDELETE 'node201.hadoop.com:9200/korea?pretty'
| |
− | | |
− | ::*korea 인덱스 생성
| |
− | | |
− | #curl -XDELETE 'node201.hadoop.com:9200/korea?pretty'
| |
− | curl -XPUT 'node201.hadoop.com:9200/korea?pretty' -d '{
| |
− | "settings": {
| |
− | "index": {
| |
− | "analysis": {
| |
− | "analyzer": {
| |
− | "kr_analyzer": {
| |
− | "type": "org.elasticsearch.index.analysis.KoreanAnalyzerProvider",
| |
− | "tokenizer": "KoreanTokenizer",
| |
− | "filter": [ "trim", "lowercase", "KoreanFilter" ]
| |
− | }
| |
− | }
| |
− | }
| |
− | }
| |
− | }
| |
− | }'
| |
− | | |
− | ::*KoreanAnalyzer 동작 확인
| |
− | | |
− | ### curl -XGET 'node201.hadoop.com:9200/korea/_analyze?pretty&analyzer=kr_analyzer&text=이전 글에서 ElasticSearch와 Arirang 형태소 분석기를 살펴 보았습니다.'
| |
− | curl -XGET 'node201.hadoop.com:9200/korea/_analyze?pretty&analyzer=kr_analyzer&text=%EC%9D%B4%EC%A0%84%20%EA%B8%80%EC%97%90%EC%84%9C%20ElasticSearch%EC%99%80%20Arirang%20%ED%98%95%ED%83%9C%EC%86%8C%20%EB%B6%84%EC%84%9D%EA%B8%B0%EB%A5%BC%20%EC%82%B4%ED%8E%B4%20%EB%B3%B4%EC%95%98%EC%8A%B5%EB%8B%88%EB%8B%A4.'
| |
− |
| |
− |
| |
− | [http://node201.hadoop.com:9200/korea/_analyze?pretty&analyzer=kr_analyzer&text=이전%20글에서%20ElasticSearch와%20Arirang%20형태소%20분석기를%20살펴%20보았습니다 http://node201.hadoop.com:9200/korea/_analyze?pretty&analyzer=kr_analyzer&text=이전%20글에서%20ElasticSearch와%20Arirang%20형태소%20분석기를%20살펴%20보았습니다].
| |
− | | |
− | *elasticsearch-analysis-korean-1.3.0.jar 파일 구조
| |
− | | |
− | :*es-plugin.properties
| |
− | | |
− | plugin=org.elasticsearch.plugin.analysis.kr.AnalysisKoreanPlugin
| |
− | | |
− | :*packages
| |
− | | |
− | org.apache.lucene.analysis.kr
| |
− | dic/
| |
− | KoreanAnalyzer.java
| |
− | KoreanFilter.java
| |
− | KoreanTokenizer.java
| |
− |
| |
− | org.apache.solr.analysis.kr
| |
− | KoreanFilterFactory.java
| |
− | KoreanTokenizerFactory
| |
− |
| |
− | org.elasticsearch.index.analysis
| |
− | KoreanAnalysisBinderProcessor.java
| |
− | KoreanAnalyzerProvider.java
| |
− | KoreanFilterFactory.java
| |
− | KoreanTokenizerFactory.java
| |
− |
| |
− | org.elasticsearch.plugin.analysis.kr
| |
− | AnalysisKoreanPlugin.java
| |
− | | |
− | *프로그램 호출 구조
| |
− | | |
− | :*AnalysisKoreanPlugin.java : AnalysisModule로 KoreanAnalysisBinderProcessor 등록
| |
− | :*KoreanAnalysisBinderProcessor.java : Analyzer, Tokenizer, Filter 등록
| |
− | ::*KoreanAnalyzerProvider.java (kr_analyzer) -> KoreanAnalyzer
| |
− | ::*KoreanTokenizerFactory.java (kr_tokenizer) -> KoreanTokenizer
| |
− | ::*KoreanFilterFactory.java (kr_filter) -> KoreanFilter
| |
| | | |
| == ElasticSearch 구성 == | | == ElasticSearch 구성 == |
Lucene을 바탕으로 개발한 분산 검색엔진인 ElasticSearch를 정리 합니다.
ElasticSearch 개요
Lucene은 널리 알려진 Java 기반의 오픈소스 검색 엔진 라이브러리 입니다. 많은 곳에서 사용 되고 있지만 라이브러리 형태라 사용에 불편함이 있고 BigData 시대를 맞아 분산 환경을 지원하지 않아 새로운 대안 솔루션이 필요하게 되었습니다. 오픈소스 진영에서는 분산 환경을 지원하는 Solr와 ElasticSearch가 Lucene 기반으로 작성이 되었습니다. ElasticSearch는 RESTful API를 지원하는 특성으로 인하여 여러 환경으로 포팅이 될 수 있어서 사용이 편리한 분산 검색 엔진 입니다.
ElasticSearch의 특징
- 실시간 검색 및 분석
- 분산 구성 및 병렬 처리
- index (Database)와 Type (Table)을 사용하여 다양한 문서 처리
- JSON을 사용하는 RESTful API 지원
- Plugin 방식의 기능 확장
ElasticSearch 용어
용어
|
상세
|
Cluster
|
|
Node
|
|
Index (indice)
|
- 유사한 특징을 가진 문서들의 모음으로 DBMS에서 데이터베이스와 유사한 개념
- Term, Count, Docs로 구성
|
Shard
|
- Index의 subset 개념으로 Lucene을 사용하여 구성
- 실제 데이터와 색인을 저장하고 있으며 Primary Shard와 Replica Shard로 분류
- Primary Shard : Shard를 구성하는 기본 인덱스
- Replica Shard : 분산된 다른 node에 저장된 Primary Shard의 복제본
|
Type (Document Type)
|
- 데이터 (Document)의 종류로 index 내에서의 논리적인 category/partition
- DBMS에서 테이블과 유사한 개념
|
Mapping
|
|
Route
|
- 색인 필드 중 unique key에 해당하는 값을 routing path로 지정한 후, 이 path를 사용하여 인덱싱과 검색에 사용할 shard를 지정하여 성능할 향상할 수 있습니다.
- Routing Field : 스토어 옵션을 yes로 index not_analyzed로 설정
|
Document
|
- ElasticSearch에서 관리하는 기본적인 데이터(정보)의 저장 단위
- JSON (JavaScript Object Notaion)으로 표현
- DBMS에서 레코드와 유사한 개념
|
Field
|
- Document를 구성하고 있는 항목으로 name과 value로 구성
- DBMS에서 컬럼과 유사한 개념
|
Gateway
|
- Cluster 상태, Index 설정 등의 정보를 저장
|
Query
|
|
TermQuery
|
|
Term
|
|
Token
|
|
ElasticSearch의 개념적 구성도
- ElasticSearch Architecture
- _index : index 이름
- _type : type 이름
- _id : Document ID
- _score
- _source : Document 저장
- properties
-
ElasticSearch 관련 오픈소스
CentOS에서 ElasticSearch 설치
ElasticSearch 설치
cd install
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.tar.gz
tar -xvzf elasticsearch-1.3.2.tar.gz
chown -R hduser:hdgroup elasticsearch-1.3.2
mv elasticsearch-1.3.2 /nas/appl/elasticsearch
### ----------------------------------------------------------------------------
### ELASTICSEARCH 설정
### ----------------------------------------------------------------------------
export ELASTICSEARCH_HOME=/nas/appl/elasticsearch
export PATH=$PATH:$ELASTICSEARCH_HOME/bin
cd /nas/appl/elasticsearch
mkdir data
mkdir logs
chown hduser:hdgroup data logs
- vi /nas/appl/elasticsearch/config/elasticsearch.yml
cluster.name: elasticsearch
node.name: "node201"
path.data: /nas/appl/elasticsearch/data
path.logs: /nas/appl/elasticsearch/logs
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["node201:9200"]
bootstrap.mlockall: true
su - hduser
elasticsearch #--- Foreground로 실행
elasticsearch -d #--- Daemon으로 실행
curl localhost:9200 #--- 서비스 확인
http://node201.hadoop.com:9200/ #--- 서비스 확인
http://node201.hadoop.com:9200/_status
http://node201.hadoop.com:9200/_plugin/head/ #--- elasticsearch-head plugin이 설치된 경우
ElasticSearch 로드밸런서 설치
- ElasticSearch 로드밸런서 환경 설정
- vi /nas/appl/elasticsearch/config/elasticsearch.yml
node.master: false
node.data: false
network.bind_host: 192.168.0.1
plugin -install mobz/elasticsearch-head
plugin -install lukas-vlcek/bigdesk
환경 설정
- bin/elasticsearch 환경변수
- JAVA_OPTS
- ES_JAVA_OPTS, ES_HEAP_SIZE
- ES_MIN_MEM=256m, ES_MAX_MEM=1gb
vi /nas/appl/elasticsearch/config/elasticsearch.yml
index:
store:
type: memory
elasticsearch -Des.index.store.type=memory
curl -XPUT 'node201.hadoop.com:9200/customer/ -d '
index:
store:
type: memory
'
curl 'node201.hadoop.com:9200/_nodes/process?pretty'
- memory settings : disable swap
swapoff -a
vi /etc/fstab
#--- swap을 주석 처리
ulimit -l unlimited #--- root 사용자로 실행
mkdir /tmp/tmpJna
vi config/elasticsearch.yml
bootstrap.mlockall: true
elasticsearch -Djna.tmpdir=/tmp/tmpJna
Service로 실행
- ES_USER, ES_GROUP
- ES_HEAP_SIZE, ES_HEAP_NEWSIZE, ES_DIRECT_SIZE
- MAX_OPEN_FILES
- MAX_LOCKED_MEMORY, MAX_MAP_COUNT
- LOG_DIR, DATA_DIR, WORK_DIR
- CONF_DIR, CONF_FILE
- ES_JAVA_OPTS, RESTART_ON_UPGRADE
#--- /etc/init.d/elasticsearch
#--- /etc/sysconfig/elasticsearch
/sbin/chkconfig --add elasticsearch
Windows에서 ElasticSearch 설치
ElasticSearch 설치
ElasticSearch는 JDK 7 이상에서 실행되는 Java 기반의 애플리케이션으로 별도의 설치 과정 없이 소스를 다운로드 받아 실행하면 됩니다. 다운로드 사이트(http://www.elasticsearch.org/download/)에서 최신 버전(elasticsearch-1.3.2.zip)의 ElasticeSearch를 다운로드 합니다. 압축을 풀어 c:/appl/elasticsearch/ 폴더를 생성 합니다.
실행 및 확인
bin/ 폴더에서 elasticsearch.bat 파일을 실행 합니다.
브라우저에서 http://localhost:9200/ 로 접속하여 확인 합니다.
Cluster 정보 확인
Node 정보 확인
ElasticSarch 폴더 구조
폴더
|
설정 변수
|
상세
|
bin
|
|
윈도우용 실행 파일
- elasticsearch.bat : ElasticSearch 실행 프로그램
- service.bat : Service 형태로 ElasticSearch 실행
service.bat install | remove | start | stop | manager [SERVICE_ID]
- plugin.bat : 플러그인 설치 프로그램 (org.elasticsearch.plugins.PluginManager 프로그램이 실행됨)
Linux용 실행 파일
- elasticsearch : ElasticSearch 실행 프로그램
- plugin : 플러그인 설치 프로그램 (org.elasticsearch.plugins.PluginManager 프로그램이 실행됨)
플러그인명/ : Plugin 설치 파일의 bin/ 폴더가 여기로 이동됨
|
config
|
path.conf
|
설정 파일 폴더
- elasticsearch.yml : ElasticSearch 설정 파일
- path.plugins : 플러그인 설치 폴더 (Default. plugins/)
- logging.yml : 로그 설정 파일
플러그인명/ : Plugin 설치 파일의 config/ 폴더가 여기로 이동됨
|
data
|
path.data
|
데이터와 인덱스를 저장하는 폴더 (elasticsearch/nodes/)
- path.data: /path/to/data1,/path/to/data2
|
lib
|
|
ElasticSearch용 라이브러리
- Lucene 검색 엔진 라이브러리
- Sigar 라이브러리 : CPU, Memory, Disk 등을 모니터링
|
logs
|
path.logs
|
로그 파일 저장 폴더
|
plugins
|
path.plugins
|
ElasticSearch 플러그인 설치 폴더 플러그인명/ : Plugin 설치 파일에서 bin/ 폴더와 config/ 폴더를 제외한 파일이 설치되는 폴더
|
work
|
path.work
|
임시 작업용 폴더
|
- path.home : ElasticSearch가 설치된 폴더를 지정하는 설정 변수
Module과 Service
ElasticSearch 실행 순서
- ElasticSearch
- Bootstrap
- org.elasticsearch.node.NodeBuilder
- org.elasticsearch.node.internal.InternalNode : 생성자 -> start()
- PluginsService 생성
- Site Plugin 로딩
- JVM Plugin 등록
- onModuleReferences에 onModule(AnyModule module) 함수 등록
- Module 등록 : 여기외에 Service 등에서도 Module을 등록할 수 있음
- Google Guice의 DI (Dependency Injection) 사용
- org.elasticsearch.common.inject.Module
- org.elasticsearch.common.inject.AbstractModule
-
- Version, PageCacheRecyclerModule, CircuitBreakerModule, BigArraysModule, PluginsModule
- SettingsModule, NodeModule, NetworkModule, ScriptModule, EnvironmentModule
- NodeEnvironmentModule, ClusterNameModule, ThreadPoolModule, discoveryModule, ClusterModule
- RestModule, TransportModule, HttpServerModule, RiversModule, IndicesModule
- SearchModule, ActionModule, MonitorModule, GatewayModule, NodeClientModule
- BulkUdpModule, ShapeModule, PercolatorModule, ResourceWatcherModule, RepositoriesModule
- TribeModule, BenchmarkModule
- Service 시작 <- LifecycleComponent (start(), stop(), close(), lifecycleState())
- AllocationService, Discovery
- PluginsService를 사용하여 Plugin에 등록된 Service 시작
- MappingUpdatedAction, IndicesService, IndexingMemoryController, IndicesClusterStateService, IndicesTTLService
- RiversManager, SnapshotsService, ClusterService, RoutingService, SearchService
- MonitorService, RestController, TransportService, DiscoveryService, GatewayService
- HttpServer, BulkUdpService, ResourceWatcherService, TribeService
Plugin
ElasticSearch - Plugin
ElasticSearch 구성
elasticsearch.yml 설정
YAML 문법에 따라 elasticsearch.yml 파일에서 설정 변수를 구성 합니다.
설정 변수
|
Default
|
상세
|
cluster.name
|
elasticsearch
|
Cluster 이름 data/Cluster 이름/ 폴더가 생성됨
|
node.name
|
0, 1, 2, ... (자동 생성)
|
Node 이름 data/Cluster 이름/nodes/Node 이름/ 폴더가 생성됨
|
node.master
node.data
node.client
|
true
true
false
|
Node 종류
- Master node
- node.master: true
- Cluster와 Node의 상태 정보를 관리
- Index와 Shard의 조정자 역할
- Data node
- node.data: true
- 색인 데이터를 저장
- Load Balance node
- node.master: false, node.data: false
- 검색 요청을 받아 분산 처리
- Client node
- node.client: true, node.master: false
- Master node로 사용하지 않고 Client node로 사용하고자 할 경우
|
index.number_of_shards
|
5
|
Shard 개수
|
index.number_of_replicas
|
1
|
Replica 개수
|
http.enabled
|
true
|
http 서비스를 활성화 합니다.
|
http.port
|
9200
|
http 서비스에서 사용하는 port
|
transport.tcp.port
|
9300
|
netty의 Transport에서 사용하는 port
|
transport.tcp.compress
|
|
true이면 Transport에서 압축 허용
|
network.bind_host
|
|
Client의 요청을 접수할 IP 주소
|
network.host
|
|
ElasticSearch Node의 IP 주소
|
gateway.type
|
local
|
Cluster의 메타 정보와 Index 설정, Mapping 정보 등을 어디서 관리할 것인지 지정
Gateway 종류
- local
- shared fs
- hadoop
- s3
|
discovery.zen.minimum_master_nodes
|
1
|
최소 Master node 개수 (2개 이상 권장)
|
discovery.zen.ping.timeout
|
3s
|
|
discovery.zen.ping.multicast.enabled
|
true
|
|
discovery.zen.ping.unicast.hosts
|
|
Unicast 사용시 검색할 서버와 포트 예) ["host1", "host2:port"]
|
Schema 설계
curl -XPUT "http://localhost:9200/aaa?pretty=true" -d @aaa.json
단계
|
상세
|
Entity 정의
|
- Entity와 Entity Field 정의
- Entity간의 관계 정의
|
Field 정의
|
- 검색 필드 정의
- 통합 검색 필드 정의
- 정렬 필드 정의
- 패싯 필드 정의
- 강조 필드 정의
|
Java 개발 환경 구성
ElasticSearch Java 환경 구성
- lib/elasticsearch-1.2.1.jar
- src/main/java/ 폴더 아래의 소스 파일을 사용 합니다.
Lucene Java 환경 구성
- Lucene 사이트에서 "DOWNLOAD" 버튼을 눌러 lucene-4.8.1.zip 파일을 다운로드 합니다.
- core/lucene-core-4.8.1.jar
- Lucene 사이트에서 "DOWNLOAD" 버튼을 눌러 lucene-4.8.1-src.tgz 파일을 다운로드 합니다.
- core/src/java/ 폴더 아래의 소스 파일을 사용 합니다.
Arirang Java 환경 구성
- arirang.morph 소스를 먼저 받아 mvn install 진행
파일:Arirang 사전.zip http://www.jopenbusiness.com/mediawiki/images/5/54/Arirang_사전.zip
REST API
JAVA API
Client
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.node.Node;
private Boolean getTransportClient() {
Settings settings = null;
settings = ImmutableSettings.settingsBuilder().put("cluster.name", CLUSTER_NAME).build();
client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(HOST, PORT));
return true;
}
//--- elasticsearch.yml
//--- cluster.name=~
private Boolean getNodeClient() {
node = nodeBuilder().clusterName(CLUSTER_NAME).client(true).local(true).node();
client = node.client();
return true;
}
index java api
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import org.elasticsearch.action.index.IndexResponse;
json = jsonBuilder().startObject()
.field("name", "value")
.endObject().string();
res = client.prepareIndex("index", "type", "id").setSource(json).execute().actionGet();
UtilLogger.info.print(logCaller, "_index : " + res.getIndex());
UtilLogger.info.print(logCaller, "_type : " + res.getType());
UtilLogger.info.print(logCaller, "_id : " + res.getId());
UtilLogger.info.print(logCaller, "_version : " + res.getVersion());
UtilLogger.info.print(logCaller, "_index : " + res.getIndex());
get java api
관리자 매뉴얼
사전 구성
- 국어 사전
- 온라인 사전을 통해서 주기적으로 갱신
- 위키에 등록된 명사로 주기적으로 갱신
elasticsearch.yml
- index.query.bool.max_clause_count
오류 처리
- vi /nas/appl/elasticsearch/bin/elasticsearch.in.sh
#ES_MIN_MEM=256m
#ES_MAX_MEM=1g
ES_MIN_MEM=4g
ES_MAX_MEM=4g
- 많은 Client에서 접속하여, 파일 개수 부족으로 오류 발생시
org.elasticsearch.common.netty.channel.ChannelException: Failed to create a selector.
Caused by: java.io.IOException: Too many open files
ulimit -n
vi /etc/security/limits.conf
hduser soft nofile 999999
hduser hard nofile 999999
참고 문헌
-