ElasticSearch+LogStash+ElasticSearchHQ 사용해보기!

2015. 10. 30. 14:16OpenSource/ElasticSearch

반응형

https://brunch.co.kr/@acet/7 에 대한 구현 방법을 설명하고자 한다.


1. 엘라스틱서치 설치

  • curl로 다운로드



curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

100 27.1M 100 27.1M 0 0 4662k 0 0:00:05 0:00:05 --:--:-- 6335k

  • 압축해제

tar xvfz elasticsearch-1.7.1.tar.gz / 권한이 없다면 chmod로 권한을 준다.


  • 실행
    • 아래처럼 클러스터명과 노드명을 수행 시에 설정할 수 있긴하다.

elasticsearch의 bin으로 가서 수행한다.

nohup ./elasticsearch --cluster.name acet_cluster --node.name acet_node &


테스트

curl 'http://localhost:9200/?pretty'

결과

test result
localhost:~ terrypark$ curl 'http://localhost:9200/?pretty'
{
"status" : 200,
"name" : "acet_node",
"cluster_name" : "acet_cluster",
"version" : {
"number" : "1.7.1",
"build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
"build_timestamp" : "2015-07-29T09:54:16Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"

}

중지 시키려면? 컨트롤+C나 shutdown api를 제공한다.

localhost:~ terrypark$ curl -XPOST 'http://localhost:9200/_shutdown'
{"cluster_name":"acet_cluster","nodes":{"nWlsi2xXRSSkIlT-J2Psig":{"name":"acet_node"}}}localhost:~ terrypark$

돌고 있던 엘라스틱서치쪽 상황~
[2015-08-17 01:31:14,760][INFO ][action.admin.cluster.node.shutdown] [acet_node] initiating requested shutdown...
[2015-08-17 01:31:14,760][INFO ][node ] [acet_node] stopping ...
[2015-08-17 01:31:14,774][INFO ][node ] [acet_node] stopped
[2015-08-17 01:31:14,774][INFO ][node ] [acet_node] closing ...
[2015-08-17 01:31:14,778][INFO ][node ] [acet_node] closed

자! 이제 엘라스틱 서치가 설치가 완료되었습니다.



2. LOGSTASH 설치 및 활용하기


logstash 역시 다운받아서 압축풀고 conf 파일 수정 후 띄워주면 끝!! 참 쉽죵?

yum install logstash
Loaded plugins: security
Repository RHEL5.4 is listed more than once in the configuration
Repository RHEL5.5 is listed more than once in the configuration
Repository RHEL5.6 is listed more than once in the configuration
Repository RHEL5.7 is listed more than once in the configuration
Repository RHEL5.8 is listed more than once in the configuration
Repository RHEL5.9 is listed more than once in the configuration
Repository EPEL5 is listed more than once in the configuration
You need to be root to perform this command.



[hanadmin@search-sitebo-dev /daum/program/neosite_elastic] curl -L -O https://download.elastic.co/logstash/logstash/logstash-1.4.5.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 70.4M 100 70.4M 0 0 2885k 0 0:00:25 0:00:25 --:--:-- 7558k


<설정 파일 내용>
input {
file {
path => "/kakao/service/neosite/logs/bo.log"
start_position => "beginning"
}
}

filter {
grok{
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}

output {
elasticsearch {
host => "해당 아이피를 적어줍니다."
port => "9300"
cluster => "neosite_realbo_cluster"
embedded => false
}
stdout { codec => rubydebug }
}

/kakao/program/neosite_elasticsearch/logstash-1.4.5/config/logstash-realbo.conf

엘라스틱을 띄우고 로그스태쉬도 띄웁니다~
nohup ./elasticsearch --cluster.name neosite_realbo_cluster --node.name neosite_real_node01 &
nohup ./elasticsearch &
nohup ./bin/logstash -f ./config/logstash-realbo.conf &


mobz 사용.

참고 : http://d2.naver.com/helloworld/273788


# 클러스터를 식별하기 위한 이름이므로 유일성과 의미를 가진 이름을 사용하자
cluster.name: es-cluster

# 노드 이름은 자동으로 생성되지만 호스트명과 같이 클러스터 내에서 식별 가능한 이름을 활용하는 것이 좋다.
node.name: "es-node1"

# 기본값은 아래 두 값이 모두 true다. node.master는 노드가 마스터가 될 수 있지에 대한 설정이고, node.data는 데이터를 저장하는 노드인지에 대한 설정이다. 보통은 두 값을 true로 설정하면 되고, 클러스터의 규모가 큰 경우에는 3가지 종류의 노드를 구성하기 위해 이 값을 노드별로 조정해 설정한다. 자세한 사항은 토폴로지(topology) 설정에서 다시 설명하겠다.
node.master: true  
node.data: true

# 샤드와 리플리카 수를 변경하는 설정이다. 아래 값은 기본값이다. 
index.number_of_shards: 5  
index.number_of_replicas: 1



#JVM의 스왑을 방지하려면 아래 설정 값을 true로 한다.
bootstrap.mlockall: true

# 클러스터 내의 각 노드의 상태 체크를 위한 타임아웃 값으로, 너무 작게 하면 노드가 클러스터에서 자주 이탈하는 문제가 발생할 수 있어 적절한 값을 설정한다. 기본값은 3초다.
discovery.zen.ping.timeout: 10s

# 기본값은 멀티캐스트를 사용하지만, 실환경에서는 다른 클러스터와 노드가 섞이는 위험이 발생할 수 있으므로 유니캐스트를 사용하고 두 번째 설정 값에 마스터가 될 수 있는 서버들의 목록을 나열하는 것이 좋다.
discovery.zen.ping.multicast.enabled: false  
discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]  


ElasticSearchHQ 설치

HQ는 플러그인이다. 보통 노드와 클러스터를 모니터링하는데 많이 사용되며 HQ보다 KIBANA라는 녀석을 선호

되긴 한다 그래서 보통 ELK라고들 부른다. 



bin/plugin -i HQ -u file:///kakao/program/neosite_elastic/elasticsearch-1.7.1/royrusso-elasticsearch-HQ-603ae9e.zip

플러그인을 셋팅한 뒤 아래처럼 접속하여보자!
http://ip쓰시고~:9200/_plugin/HQ



마지막으로 들이는 시간보다 가성비가 정말 좋은것 같다. 덕분에 리펙토링 후 빠른 오류를 감지하여 수정할 수 있었던 케이스도 있다.

한곳에서 모든 로그를 볼수 있다는 메리트는 정말 좋은것 같다. 

이상 끝~



 

반응형

'OpenSource > ElasticSearch' 카테고리의 다른 글

es 버전이 낮으면..  (0) 2021.06.27
elk  (0) 2021.04.30
kibana 잘 안띄워 진다면? 확인해보면 좋다!  (0) 2017.08.28
log 모니터링을 위한 아키텍처  (0) 2016.06.15
Curator를 사용해보자(인덱스 관리)  (0) 2015.12.16