3노드 클러스터 엘라스틱서치 ( elasticsearch 3node)
셋팅 관련 자료가 너무 없어서 혼자서 삽질하면서 익힌게 생각이 난다. 누군가에게 도움이 되었으면 한다.
( 물리서버가 1대인 경우 사실 이와 같은 환경은 위험이 따른다. 만약 물리서버가 죽게되면 cluster를 잃게 된다. )
물리서버 : ubuntu 20/04
작업 전 port 개방 ( root 사용자로 작업할 것 )
- centos
firewall-cmd --zone=public --permanent --add-port=9200/tcp |
firewall-cmd --reload |
- ubuntu
ufw allow 9200 ufw allow 9300 ufw allow 5601 |
elasticsearch 디렉토리 구조
서비스가 정상적으로 올라 왔는지 확인
방법1) $ ps -ef | grep elasticsearch
방법2) $ jps
4629 Elasticsearch
4935 Elasticsearch
7419 Jps
5087 Elasticsearch
[ 단 jps 명령어 사용시에는 openjdk 설치가 반드시 필요하다 ]
방법3) $ curl -XGET http://localhost:9200/_cluster/health?pretty
kibana 설정
브라우저에서
: http://xxx.xxx.xxx.xxx:5601로 접근 시도한다.
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch match-query (0) | 2020.12.23 |
---|---|
elasticsearch term query (0) | 2020.12.22 |
elasticsearch index mapping 에 관한 생각 (0) | 2020.04.17 |
logstash ruby syntax (0) | 2020.04.14 |
logstash file stdin (0) | 2020.04.14 |
elasticsearch index mapping 에 관한 생각
보통 인덱스를 생성할 때 반드시 인덱스 매핑을 먼저 정의할 것을 권유한다. 매핑 정의서가 있어야 유지 보수가 용이하기 때문이다.
매핑 타입에 맞지 않는 document 를 insert 할 시 어떤 일이 발생하는지 확인해보겠다.
1] 인덱스 정의
#!/bin/bash curl -X PUT 'http://:9200/kim?pretty' -H 'Content-Type: application/json' -d' { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 1 }, "mappings" : { "properties" : { "x" : {"type" : "integer"} } } }' |
2] 데이터 타입에 맞는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/1' -H 'Content-Type: application/json' -d' { "x": 10 }' |
{"_index":"kim","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1}
|
3] 데이터 타입에 맞지 않는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/2' -H 'Content-Type: application/json' -d' { "x": "hello world" }' |
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'","caused_by":{"type":"number_format_exception","reason":"For input string: \"hello world\""}},"status":400} |
4] 결론 : 인덱스를 생성하기 전에 매핑을 정의하는 것이 정신건강에 좋을 꺼라 생각한다.
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch term query (0) | 2020.12.22 |
---|---|
3노드 클러스터 엘라스틱서치 ( elasticsearch 3node) (0) | 2020.05.09 |
logstash ruby syntax (0) | 2020.04.14 |
logstash file stdin (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
logstash plugin install
logstash 에 내가 필요한 플러그인을 추가해보자
우선 내가 찾는 플러그인이 있는지 먼저 search
경로 : /bin $ ./logstash-plugin list elastic logstash-filter-elasticsearch logstash-input-elasticsearch logstash-output-elastic_app_search logstash-output-elasticsearch |
플러그인을 찾았으면 설치를 진행한다.
$ ./logstash-plugin install logstash-output-elasticsearch Validating logstash-output-elasticsearch Installing logstash-output-elasticsearch Installation successful |
체크
./logstash-plugin list |
테스트
input { stdin { codec => "json" } }
output { elasticsearch { hosts => ["http://192.168.42.11:9200", "http://192.168.42.11:9201", "http://192.168.42.11:9202"] index => "kim_1" } } |
'ELK > logstash' 카테고리의 다른 글
logstash file json absolute path (0) | 2020.06.17 |
---|---|
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
logstash + app-search (0) | 2019.12.10 |
logstash + python (0) | 2019.01.12 |
logstash - mysql - elasticsearch 연동 (0) | 2019.01.06 |
logstash ruby syntax
logstash conf 파일 안쪽에서 프로그래밍 언어 처럼 조건문을 넣어야 할 경우가 있다 그럴 경우 ruby 문법을 사용하여 넣으면 된다.
[ logstash conf 파일 ]
input { stdin { codec => "json" } }
filter { mutate { remove_field => ["host", "@timestamp", "@version"] } }
output { if [name] == "kimjunhyeon" { stdout {} } } |
[ json 파일 ]
{"name": "kimjunhyeon"} {"name": "LeeJung"} |
[ 실행 ]
$ logstash -f basic_02.conf < test.json |
[ 결과 ]
'ELK > elasticsearch' 카테고리의 다른 글
3노드 클러스터 엘라스틱서치 ( elasticsearch 3node) (0) | 2020.05.09 |
---|---|
elasticsearch index mapping 에 관한 생각 (0) | 2020.04.17 |
logstash file stdin (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
reindex query shellscript array (0) | 2020.02.03 |
logstash file stdin
logstash -f xxxx.conf 로 실행을 하면 언제 업무를 끝마쳤는지 알기 쉽지 않다. 그럴경우 파일을 stdin 의 redirect 값으로 던져주면 수행을 마치면 자동적으로 내려가게 된다. 구조는 다음과 같다.
logstash -f xxx.conf < yyy.json |
ㄱ] logstash conf 파일
input { stdin { codec => "json" } }
output { stdout { codec => rubydebug } } |
ㄴ] json 파일
{"name": "kimjunhyeon"} {"name": "LeeJung" |
ㄷ] 실행
$ logstash -f basic_01.conf < test.json |
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch index mapping 에 관한 생각 (0) | 2020.04.17 |
---|---|
logstash ruby syntax (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
reindex query shellscript array (0) | 2020.02.03 |
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |
보안 적용된 elasticsearch에 쿼리
#!/bin/bash
$ curl -u elastic:password -k "https://xxx.xxx.xxx.xxx:xxxx/_cluster/health?pretty"
=====================================================
$ curl -u elastic:password http://xxx.xxx.xxx.xxx:9200/_cluster/health?pretty
{
"cluster_name" : "hello_world",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 267,
"active_shards" : 533,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
'ELK > elasticsearch' 카테고리의 다른 글
logstash ruby syntax (0) | 2020.04.14 |
---|---|
logstash file stdin (0) | 2020.04.14 |
reindex query shellscript array (0) | 2020.02.03 |
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |
app-search (0) | 2020.01.06 |
reindex query shellscript array
#!/bin/bash
test_array=("sk_poc_news_itscience_sciencecomputer" "sk_poc_news_itscience_sciencecomputer_test" "sk_poc_news_itscience_sciencemobile" "sk_poc_news_itscience_sciencemobile_test" "sk_poc_news_itscience_sciencegeneralscience" "sk_poc_news_itscience_sciencegeneralscience_test" "sk_poc_news_itscience_sciencecommunicationandnewmedia" "sk_poc_news_itscience_sciencecommunicationandnewmedia_test" "sk_poc_news_social_accidnet" "sk_poc_news_social_accidnet_test" "sk_poc_news_social_labor" "sk_poc_news_social_labor_test" "sk_poc_news_politics_administ" "sk_poc_news_politics_administ_test" "sk_poc_news_itscience_scienceinternetandsns" "sk_poc_news_itscience_scienceinternetandsns_test")
for (( i=0 ; i <16 ; i=i+2 )); do
echo "${test_array[i]}"
curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -u "elastic:ezfarm123" -d"
{
\"source\": {
\"index\": \"${test_array[i]}\"
},
\"dest\": {
\"index\": \"${test_array[i+1]}\"
}
}"
done
참고
https://stackoverflow.com/questions/37202122/how-can-i-put-parameters-in-elasticsearch-curl-post
'ELK > elasticsearch' 카테고리의 다른 글
logstash file stdin (0) | 2020.04.14 |
---|---|
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |
app-search (0) | 2020.01.06 |
nginx setting (0) | 2019.12.19 |
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법
case1) 해당 인덱스의 field들
PUT test_sk_poc/_mapping
{
"properties": {
"*": {
"type": "text",
"fielddata": true
}
}
}
case2) 모든 인덱스
PUT */_mapping
{
"properties": {
"*": {
"type": "text",
"fielddata": true
}
}
}
'ELK > elasticsearch' 카테고리의 다른 글
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
---|---|
reindex query shellscript array (0) | 2020.02.03 |
app-search (0) | 2020.01.06 |
nginx setting (0) | 2019.12.19 |
python-appsearch (0) | 2019.12.19 |
app-search
from pdflib import Document
import os
import base64
import yaml
import time
from time import strftime
# app-search
from swiftype_app_search import Client
from ela_dir.Ela import Ela
#
# pdf 파일 읽어 app-search 에 insert
#
class AppSearch():
def __init__(self):
ARGS = AppSearch.getAppObj()
self._appClient = ARGS.get("client")
self._appEngine = ARGS.get("engine_name")
@classmethod
def getAppObj(cls):
try:
f=open("./app_search_info/app_info.yml", "r", encoding="utf-8")
except FileExistsError as E:
print(E)
exit(1)
else:
appArgs = yaml.safe_load(f)
arguments = dict()
client = Client(
api_key = appArgs.get("api_key"),
base_endpoint = appArgs.get("base_endpoint"),
use_https = appArgs.get("use_https")
)
engine_name = appArgs.get("engine_name")
arguments["client"] = client
arguments["engine_name"] = engine_name
return arguments
class PDFObj(AppSearch):
def __init__(self):
AppSearch.__init__(self)
self._targetPath = PDFObj.getFilePath()
self._fileTypeList = [".pdf"]
self._timeObj = strftime("%Y%m%d", time.localtime())
# ftp로 들어온 파일을 순회
def dirSearch(self):
os.chdir(self._targetPath)
cur = os.listdir()
for f in cur:
fname, fext = os.path.splitext(f)
if fext in self._fileTypeList:
doc = Document(f)
#text = []
for page, content in enumerate(doc):
print("{} 처리 중 ...".format(page+1))
strData = " ".join(content.lines).strip()
#text.append(strData)
element = {"metadata": doc.metadata, "fileName": fname, "content": strData, "cllctTime": self._timeObj,
"filepath": os.path.abspath(f)}
self._appClient.index_document(self._appEngine, element)
#resultContent = "".join(text)
@classmethod
def getFilePath(cls):
try:
f = open("./conf/info.yml", "r", encoding="utf-8")
except FileNotFoundError as E:
print(E)
exit(1)
else:
filePath = yaml.safe_load(f)
return filePath.get("target_path")
if __name__ == "__main__":
o = PDFObj()
o.dirSearch()
'ELK > elasticsearch' 카테고리의 다른 글
reindex query shellscript array (0) | 2020.02.03 |
---|---|
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |
nginx setting (0) | 2019.12.19 |
python-appsearch (0) | 2019.12.19 |
Elasticsearch + python + pipeline (0) | 2019.12.02 |
nginx setting
server {
listen 560
location / {
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Authorization "Basic ZWxhc3RpYzplbGFzdGlj"
proxy_pass http://localhost:5601
}
}
'ELK > elasticsearch' 카테고리의 다른 글
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |
---|---|
app-search (0) | 2020.01.06 |
python-appsearch (0) | 2019.12.19 |
Elasticsearch + python + pipeline (0) | 2019.12.02 |
네이버 무비 정보 크롤링 => logstash data pipe_line => kibana 시각화 (0) | 2019.11.10 |