본문 바로가기
1인 프로젝트/나만의 도서관

Elasticsearch 서버 연결

by kirope 2024. 7. 31.
반응형

아래는 기본적인 설정이 포함된 완전한 `elasticsearch.yml` 파일입니다. 


```yaml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: C:\elasticsearch\data
#
# Path to log files:
#
path.logs: C:\elasticsearch\logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

# ---------------------------------- Security ----------------------------------
#
# Enable security features
xpack.security.enabled: false

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: false

# ---------------------------------- Other -------------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

# For single-node development clusters, use this setting:
discovery.type: single-node
```

이 설정 파일은 다음과 같은 주요 설정을 포함하고 있습니다:

1. 클러스터 이름과 노드 이름 설정
2. 데이터와 로그 파일의 경로 설정
3. 네트워크 호스트와 포트 설정 (localhost에서만 접근 가능)
4. 보안 기능 비활성화 (개발 환경용)
5. 단일 노드 디스커버리 타입 설정

이 설정을 사용하여 `elasticsearch.yml` 파일을 교체한 후 Elasticsearch를 실행해보세요. 대부분의 기본적인 개발 환경에서는 이 설정으로 문제없이 실행될 것입니다.

실행 후 문제가 발생하면 로그 파일을 확인하여 구체적인 오류 메시지를 확인할 수 있습니다. 로그 파일은 `C:\elasticsearch\logs` 폴더에 있습니다.

 

 

축하드립니다! Elasticsearch가 성공적으로 실행되고 있습니다. curl 명령을 통해 받은 응답은 Elasticsearch 서버가 정상적으로 작동하고 있음을 보여줍니다. 

응답에서 확인할 수 있는 중요한 정보들:

1. `"name" : "node-1"`: 이는 elasticsearch.yml 파일에서 설정한 노드 이름입니다.
2. `"cluster_name" : "my-application"`: 이는 설정한 클러스터 이름입니다.
3. `"version" : { "number" : "8.14.3" }`: 현재 실행 중인 Elasticsearch의 버전입니다.

이제 Elasticsearch가 정상적으로 실행되고 있으므로, 다음과 같은 작업을 수행할 수 있습니다:

1. 인덱스 생성 및 데이터 입력
2. 검색 쿼리 실행
3. 클러스터 상태 모니터링
4. Kibana, Logstash 등의 추가 도구 연동

예를 들어, 간단한 인덱스를 생성하고 데이터를 입력하려면 다음과 같은 curl 명령을 사용할 수 있습니다:

```
curl -X PUT "localhost:9200/my-index-000001?pretty"
curl -X POST "localhost:9200/my-index-000001/_doc?pretty" -H "Content-Type: application/json" -d"{\"name\": \"John Doe\", \"age\": 30}"
```

그리고 데이터를 검색하려면:

```
curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H "Content-Type: application/json" -d"{\"query\": {\"match_all\": {}}}"
```

이제 Elasticsearch를 사용하여 다양한 데이터 작업을 수행할 수 있습니다. 추가적인 설정이나 사용 방법에 대해 궁금한 점이 있으면 언제든 물어보세요!

728x90
반응형