[Elasticsearch] 8.2.0 Docker Compose 예제.

Elastic/Elasticsearch 2022. 5. 11. 16:42

Elasticsearch 7.x 와 다르게 8.x 에서는 기본 xpack.security.enabled: true 로 실행이 됩니다.

그래서 docker container 구성 시 보안 기능을 사용 하지 않고 예전 처럼 7.x 에서 사용 하듯이 사용 하고자 한다면 아래 예제를 참고해서 사용 하시기 바랍니다.

version: '3.7'
services:
  es-singlenode:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
    container_name: es-singlenode
    environment:
      - xpack.security.enabled=false
      - node.name=single-node
      - cluster.name=es-singlenode-c
      - discovery.type=single-node
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - es-bridge
networks:
  es-bridge:
    driver: bridge

저 같은 경우 xpack basic 을 사용 하기는 하지만 보안 기능을 사용 하지는 않습니다.

모두 private subnet 에서 구성해서 사용중이기도 하고 별도 ACL 통제를 통해서 접근 제어도 이루어 지고 있어서 인데요.

판단은 각자가 알아서 하셔야 할 것 같습니다.

 

:

[Elastic] Enterprise Search 8.2 구성 해 보기

Elastic 2022. 5. 9. 13:56

Enterprise Search (App Search) 를 사용하기 위해서는 먼저 선행 되어야 하는 것들이 있습니다.

https://www.elastic.co/guide/en/app-search/current/getting-started.html

 

App Search 이외 Workspace Search 도 있습니다.

여기서는 App Search 만 다뤘습니다.

 

1. Elasticsearch 가 설치 되어 있어야 합니다.

Enterprise Search 는 Elasticsearch 를 포함 하고 있지 않습니다.

구성 되어 있는 Elasticsearch Cluster 에 연결 해서 Enterprise Search 를 사용 할 수 있도록 해줍니다.

 

2. Kibana 가 설치 되어 있어야 합니다.

Kibana 가 필요한 이유는 Enterprise Search 의 Web UI 가 Kibana 로 통합 되었기 때문 입니다.

 

3. Enterprise Search 가 설치 되어 있어야 합니다.

Enterprise Search 를 사용하기 위해 필요 하며, Elasticsearch 는 JDK 17 을 요구 하지만, Enterprise Search JDK 11 을 요구 합니다.

사용 하는 JDK 버전을 꼭 확인 하셔야 합니다.

 

 

Elasticsearch 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

전에도 설명 했지만 8.x 부터는 기본 xpack security 기능이 enabled 입니다.

$ bin/elasticsearch
 Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  0*LbX+orEfOCQx2GPRRy

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  961aea7f1014ee94966ed79be09f3f550236389049d41b41c4dbe196e2bf7a22

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjIuMCIsImFkciI6WyIxOTIuMTY4LjAuNzo5MjAwIl0sImZnciI6Ijk2MWFlYTdmMTAxNGVlOTQ5NjZlZDc5YmUwOWYzZjU1MDIzNjM4OTA0OWQ0MWI0MWM0ZGJlMTk2ZTJiZjdhMjIiLCJrZXkiOiJpNWRvcG9BQkhoU20tOF9wY1FVYTpwdUZTMFMtM1J4aVZZUmoyaGJzajZnIn0=

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.


Kibana 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Security Enabled 이기 때문에 Kibana 실행 시 Elasticsearch 에서 생성해 준 코드를 입력해서 연결 합니다.

등록 후 ID, PWD 를 입력 하고 로그인 합니다.

$ bin/kibana
i Kibana has not been configured.

Go to http://localhost:5601/?code=917177 to get started.

# elasticsearch 실행 하면서 생성된 코드를 등록 하고 kibana 구성을 완료 합니다.
# id/pwd 를 입력 하고 로그인 합니다. (역시 elasticsearch 실행 시 생성된 코드를 입력 합니다.)

 

Enterprise Search 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Enterprise Search 의 경우 필요한 정보는 Elasticsearch 와 Kibana 정보 입니다.

Elasticsearch 의 경우 SSL 연동을 위한 정보도 함께 등록 합니다.

$ bin/enterprise-search
# java 11 버전을 요구 하기 때문에 맞춰서 실행 합니다.

--------------------------------------------------------------------------------

Invalid config file (/Users/henry/Workspace/apps/es8.2.0/enterprise-search-8.2.0/config/enterprise-search.yml):
The setting '#/secret_management/encryption_keys' is not valid
No secret management encryption keys were provided.
Your secrets cannot be stored unencrypted.
You can use the following generated encryption key in your config file to store new encrypted secrets:
todd
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]


--------------------------------------------------------------------------------

$ vi config/enterprise-search.yml
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]
allow_es_settings_modification: true
elasticsearch.username: elastic
elasticsearch.password: 0*LbX+orEfOCQx2GPRRy
elasticsearch.host: https://127.0.0.1:9200
elasticsearch.ssl.enabled: true
elasticsearch.ssl.certificate_authority: /Users/henry/Workspace/apps/es8.2.0/elasticsearch-8.2.0/config/certs/http_ca.crt
kibana.external_url: http://localhost:5601


# enterprise-search 연동을 위해 kibana 설정을 합니다.
$ vi config/kibana.yml
enterpriseSearch.host: http://localhost:3002


$ bin/enterprise-search
#########################################################

Success! Elastic Enterprise Search is starting successfully.

Advanced tooling and management interfaces are available via Kibana. Learn more about configuring and running
Kibana with Enterprise Search at https://www.elastic.co/guide/en/enterprise-search/master/user-interfaces.html.

In a few moments, you'll be able to access Enterprise Search from Kibana at the following address:

  * Kibana URL: http://localhost:5601/app/enterprise_search/overview

If this is your first time starting Enterprise Search, check the console output above for your user authentication credentials.

Visit the documentation: https://www.elastic.co/guide/en/enterprise-search/master/index.html


WARNING: A new secret session key has been generated.

Set the key in your config file to persist user sessions through process restarts:

secret_session_key: 5c6b7e6034c36ab0753033889e977624e362990f210adac99348e0e94aefb9b758ef8799d8d111b7d7c5c11383a254a50ca5322ed916ce185b2141617aa5924e


#########################################################


Kibana 에 접속해서 Enterprise Search 를 사용해 봅니다.)

# kibana 에 접속 해서 enterprise search 에서 app search 를 생성 합니다.
# app search 에서 engine 생성을 한 후 json 파일을 등록 합니다.
# [ {...}, {...} ] 형태의 개별 문서가 등록이 되어 있어야 하며, bulk request json 과 형식이 다릅니다.
# 문서 등록을 했으면 생성한 엔진으로 접근해서 검색을 실행해 봅니다.
# Relevance Tuning 이나 Search UI 에서 실행 합니다. 또는 Postman 에서 실행 하고자 할 때는
https://www.elastic.co/guide/en/app-search/8.2/search-guide.html
각각의 인증키는 Credentials 에 들어 가면, private-key 와 search-key 가 존재 합니다.

# Endpoint rule
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/query_suggestion
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/search.json

# Suggestion
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/query_suggestion' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"서울"}'

# Search
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/search.json' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query":"서울"
}'

# enterprise search 에서 제공 하는 query 에는 QueryDSL 을 사용 할 수 없습니다.
https://www.elastic.co/guide/en/app-search/8.2/search.html#search-api-request-body

# enterprise search 에서 제공 하는 synonyms 기능은 질의 시점에 적용 되는 기능입니다.
https://www.elastic.co/guide/en/app-search/8.2/synonyms.html
Kibana UI 에서 등록 시 처음에 등록 하는 동의어가 원본 동의어가 되며, 이후 등록 하는 value 들이 원본 동의어와 같이 처리가 되어야 하는 동의어가 됩니다.

통신 방법에 따라 사용 유형을 정리해 보면,

Case 1)

Elasticsearch Cluster <--> Enterprise Search <--> Kibana

 

Case 2)

Elasticsearch Cluster <--> Enterprise Search <--> External Search API

 

Vertical Search Engine 으로도 사용이 가능 합니다.

Elasticsearch Cluster <--> Enterprise Search (각 서비스 또는 도메인 별 Enigne 생성) <--> External Search API (Engine 별 Endpoint)

 

단일 클러스터 운영을 하고 여러 Collection(Index) 을 사용하고자 할 때 유용하게 사용 가능해 보입니다.

:

[Thymeleaf] 간만에 FE 작업 삽질 기록

ITWeb/개발일반 2022. 4. 22. 14:31

1. bootstrap UI 에서 "dropdown require Popper" 관련 오류가 발생을 하면 아래 내용을 추가 합니다.

 

[webjars + bootstrap 4 사용 시]

build.gradle)
implementation "org.webjars:popper.js:1.6.1-lts"

fragments_jsimport.html)
<!-- jQuery 먼저 선언 합니다. -->
<script type="text/javascript" th:src="@{/webjars/popper.js/umd/popper.min.js}"></script>
<!-- Bootstrap 을 나중에 선언 합니다. -->

여기서는 선언 순서를 지켜 주셔야 합니다.

 

2. spring mvc 에서 thymeleaf 로 값 전달

Controller)
mav.addObject("key", 1);

Thymeleaf)
<a th:href="@{/goto/{id}(id=${key})}">KEY</a>
To
<a href="/goto/1">KEY</a>

 

:

[Springboot+Ajax] 데이터 통신

ITWeb/개발일반 2022. 4. 7. 15:43

Spring Domain, VO, Model

@Setter
@Getter
@ToString
public class SearchRequestModel {

    private PageModel pageModel;
    private long id;
}

@Setter
@Getter
@ToString
public class PagetModel {

    private int page;
    private int size;
    private String sort;
}

 

Spring RestController

@ResponseBody
@RequestMapping(
    value = "/api/search",
    method = RequestMethod.POST,
    produces = { MediaType.APPLICATION_JSON_VALUE }
)
public String search(
	@RequestBody SearchRequestModel m
) {
	return service.search(m)
}

 

Ajax

$.ajax({
    type: "POST",
    url: "/api/search",
    dataType: "json",
    contentType: "application/json",
    data: JSON.stringify({
        "pageModel": {
            "page": 1,
            "size": 20,
            "sort": "asc"
        },
        "id": 1
    }),
    success: function(res) {
    },
    error: function(res, status, e) {
    }
});

 

Ajax 요청 시 dataType, contentType 선언 없이 + @RequestBody 선언 없이 사용할 경우,

일반적인 POJO 스타일의 Data Binding 으로 처리가 됩니다. (Spring 에서는 자동으로 처리가 됩니다.)

또는

@RequestParam 을 이용해서 값을 전달 받을 수 있습니다.

 

오랜만에 화면 작업 하다 보니 이런것도 기억이 가물 가물 합니다.

:

[Elasticsearch] Plugin transport-netty4 MVN Repo Missing!!

Elastic/Elasticsearch 2022. 3. 28. 16:04

elasticsearch 8.x 에서 plugin 개발 시 주의 사항!!

기본적으로 plugin 을 만들기 위한 몇몇 dependency lib 들이 maven repository 에 등록이 안된 것 같습니다.
플로그인 빌드 시 아래와 같은 에러가 발생 하는 경우 꼭 관련 lib 들이 등록 되어 있는지 확인 하고 사용하시기 바랍니다.

 

빌드 시 에러 메시지)

Could not find artifact org.elasticsearch.plugin:transport-netty4:jar:8.0.0 in central
(https://repo.maven.apache.org/maven2)

 

org.elasticsearch.plugin:transport-netty4:jar 는 8.1.1 부터 등록이 되어 있습니다.
그래서 빌드 하실 때 8.0.0 이나 8.1.0 은 빌드 실패를 하게 되는데요.

꼭 확인을 해보셔야 합니다.

 

Maven Repository)
https://mvnrepository.com/artifact/org.elasticsearch.plugin
https://mvnrepository.com/artifact/org.elasticsearch.plugin/transport-netty4

 

: