2014-12-17 4 views
5

나는 시스템 로그를 수집하는 logstash + elasticsearch를 사용하고은 내가, elasticsearch-template.json

내가 logstash에서 elasticsearch-template.json라는 이름의 파일을 찾을 노화 로그의 TTL을 설정할 통해 기본 elasticsearch 매핑을 logstash 설정할 수 있습니다

{ 
    "template" : "logstash-*", 
    "settings" : { 
    "index.refresh_interval" : "5s" 
    }, 
    "mappings" : { 
    "_default_" : { 
     "_all" : {"enabled" : true}, 
     "dynamic_templates" : [ { 
     "string_fields" : { 
      "match" : "*", 
      "match_mapping_type" : "string", 
      "mapping" : { 
      "type" : "string", "index" : "analyzed", "omit_norms" : true, 
       "fields" : { 
       "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256} 
       } 
      } 
     } 
     } ], 
     "_ttl": { 
     "enabled": true, 
     "default": "1d" 
     }, 
     "properties" : { 
     "@version": { "type": "string", "index": "not_analyzed" }, 
     "geoip" : { 
      "type" : "object", 
      "dynamic": true, 
      "path": "full", 
      "properties" : { 
       "location" : { "type" : "geo_point" } 
      } 
     } 
     } 
    } 
    } 
} 

다음 logstash를 다시 시작, 삭제 : 경로가 logstash/logstash-1.4.2/logstash/출력 elasticsearch/elasticsearch-template.json

이 같은 파일에 TTL 정보를 추가 lib 디렉토리//입니다 모든 elasticsearch 지수. elasticsearch에서 새 색인의 매핑을 확인했지만이 방법으로 작동하지 않았습니다.

인덱스 템플릿은 어떻게 구성합니까?

+0

있다, 기능이 많은 "KOPF"라는 이름의 플러그인이있다. 그 중 하나는 템플릿을 쉽게 편집하고 편집기에 저장하는 것입니다. 클러스터 등을 기반으로 한 파편/복제본 수 변경과 같은 일이 있습니다. – Maziyar

답변

2

JSON 파일이 올바른 폴더에없는 것처럼 보입니다. 폴더 정보 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html :

구성

인덱스 템플릿도 템플릿 디렉토리 (참고 아래의 설정 위치 (path.conf) 내에 배치 할 수 있도록 다음 템플릿을 사용하는 방법에 대한 설명서입니다 모든 마스터 적합한 노드에 배치해야합니다. 예를 들어, template_1.json이라는 파일은 config/templates 아래에 배치 할 수 있으며 인덱스와 일치하는 경우 추가됩니다. 다음은 언급 된 파일의 샘플입니다.

+0

답변 해 주셔서 감사합니다. "/elasticsearch-1.4.0/config/elasticsearch.yml"에서 config (path.conf)를 찾았지만 인덱스 템플릿을이 방법으로 설정하는 방법은 무엇입니까? 샘플 파일이 보이지 않아서 미안해. – user4369887

+0

config 폴더 내에 템플릿 폴더를 만들고 JSON 파일을 복사하십시오. 그런 다음 ES를 다시 시작하면 매핑이 있어야합니다. –

8

로깅 설정을 변경해야합니다.

기본 설정을 따른 경우 logstash는 이미 elasticsearch logstash 안에 템플릿을 만들었습니다. logstash는 명시 적으로 말하지 않는 한 elasticsearch에 저장된 템플릿을 계속 사용합니다.

당신이 발견 템플릿 파일을 수정하지만, 그 외에, 당신의 logstash 구성에서 다음을 설정합니다

내가 elasticsearch 출력 블록으로 새로운 template.json 파일을 생성 경로를 정의한
output { 
    elasticsearch { 
    ... 
    template_overwrite => true 
    ... 
    } 
} 
+1

Logstash 템플릿 파일에 액세스하려면 어떻게해야합니까? 그것이 어디에 있습니까? – learner

+1

logstash 디렉토리에 있어야합니다. 찾을 수없는 경우 자신 만의 로그 저장소를 만들 수 있으며 logstash의 구성 파일에서 사용자 정의 된 템플릿 파일을 사용하도록 logstash에 요청하십시오. 'template => "/ path/to/elasticsearch_template을 추가하십시오.json "\ n template_name =>"the_name_you_want "를 logstash 구성에서 사용하고 있습니다. 여기에 예제가 있습니다 : https://github.com/xialingxiao/andokaelk/blob/master/roles/logstash/templates/logstash_connector.conf elasticsearch_template에 대한 https://github.com/xialingxiao/andokaelk/blob/master/roles/logstash/templates/elasticsearch_template.json – lingxiao

+0

'elasticsearch_template.json'의'template' 필드는 elasticsearch'와 호환되어야합니다' index' name logstash는'logstash.conf'에 설정되어 있습니다 .. – lingxiao

0

logstash.yml 구성 파일 :

input { 

file { 
path => "/your-path-to-directory/*.log" 
type => "name-of-type" 
} 
} 
,174 : 탄성 대

stdout { codec => json_lines } 

elasticsearch { 

"hosts" => ["ip:port"] 
"index" => "name-of-index-%{+dd.MM.YYYY}" 
template => "/{path-to-logstash-folder}/templates/your-template.json" 
template_overwrite => true 
manage_template => false 
} 

DOCUMENT_TYPE 난 logstash.yml 설정 파일의 입력 블록으로 정의

새로운 방문자를위한 내 template.json 파일

{ 
"name-of-index": { 
"order": 0, 
"version": 50001, 
"template": "name-of-index-*", 
"settings": { 
    "index": { 
    "refresh_interval": "5s" 
    } 
}, 
"mappings": { 
    "_default_": { 
    "dynamic_templates": [ 
     { 
     "message_field": { 
      "path_match": "message", 
      "mapping": { 
      "norms": false, 
      "type": "text" 
      }, 
      "match_mapping_type": "string" 
     } 
     }, 
     { 
     "string_fields": { 
      "mapping": { 
      "norms": false, 
      "type": "text", 
      "fields": { 
       "keyword": { 
       "type": "keyword" 
       } 
      } 
      }, 
      "match_mapping_type": "string", 
      "match": "*" 
     } 
     } 
    ], 
    "_all": { 
     "norms": false, 
     "enabled": true 
    }, 
    "properties": { 
     "@timestamp": { 
     "include_in_all": false, 
     "type": "date" 
     }, 
     "geoip": { 
     "dynamic": true, 
     "properties": { 
      "ip": { 
      "type": "ip" 
      }, 
      "latitude": { 
      "type": "half_float" 
      }, 
      "location": { 
      "type": "geo_point" 
      }, 
      "longitude": { 
      "type": "half_float" 
      } 
     } 
     }, 
     "@version": { 
     "include_in_all": false, 
     "type": "keyword" 
     } 
    } 
    } 
}, 
"aliases": {} 
} 
}