[Filebeat] setup.ilm & setup.template 잘 쓰려면.

Elastic/Beats 2020. 5. 25. 17:09

가끔 설정은 yml 에 잘 했는데 안될 때가 있습니다.

이게 어디에서 뭘로 했느냐에 따라 다른데요.

 

보통 beats 를 이용할 경우 자동으로 alias 생성 및 설정이 됩니다.

이 경우 elasticsearch 에서 동일하게 사용 하기 위한 ilm 과 template 설정을 하게 되면 동작이 잘 안되는 경우가 있는데요.

 

큰 차이는 is_write_index 설정 때문 입니다.

뭐 이것도 경우에 따라 다르게 나올 수 있지만 일반적이라면 저 설정 때문이다 생각 하시면 됩니다.

 

beats 에서는 libbeat 에서 자동으로 설정을 해줍니다.

 

// CreateAlias sends request to Elasticsearch for creating alias.
func (h *ESClientHandler) CreateAlias(alias Alias) error {
	// Escaping because of date pattern
	// This always assume it's a date pattern by sourrounding it by <...>
	firstIndex := fmt.Sprintf("<%s-%s>", alias.Name, alias.Pattern)
	firstIndex = url.PathEscape(firstIndex)

	body := common.MapStr{
		"aliases": common.MapStr{
			alias.Name: common.MapStr{
				"is_write_index": true,
			},
		},
	}

	// Note: actual aliases are accessible via the index
	status, res, err := h.client.Request("PUT", "/"+firstIndex, "", nil, body)
	if status == 400 {
		// HasAlias fails if there is an index with the same name, that is
		// what we want to check here.
		_, err := h.HasAlias(alias.Name)
		if err != nil {
			return err
		}
		return errOf(ErrAliasAlreadyExists)
	} else if err != nil {
		return wrapErrf(err, ErrAliasCreateFailed, "failed to create alias: %s", res)
	}

	return nil
}

하지만, elasticsearch 에서 수동으로 설정을 한다고 하면 꼭 "is_write_index:true" 설정을 해주셔야 alias 생성 및 등록이 잘 된다는거 알고 넘어 가자고요.

 

: