[ELK] 2. Elastic Search 설정 및 실행
[ELK] 2. Elastic Search 설정 및 실행 — #개발자의도구들 #ElasticSearch #Elasticsearchconfiguration AI스쿨 msa기반 java 백엔드 코스 중에...
#개발자의도구들 #ElasticSearch #Elasticsearchconfiguration
AI스쿨 msa기반 java 백엔드 코스 중에 공부한 내용을 작성하였습니다
\* 현재 Spring x 프로젝트를 진행하고 있습니다. 전체 목차를 보시려면 여기를 눌러주세요.
\* Devops stack: 여기
\* 리눅스 기본기: 여기
Before
Logstash를 공부하고 오면 더 좋아요.
👉 Logstash(링크 추가 예정)
Elastic Search 아키텍처는 여기 있어요 좀 더 깊게 이해하고 싶다면 보고 와주세요.
Elastic Search 설치
# 설치 명령어
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.3-linux-x86_64.tar.gz
⚠️ 버전 확인이 필요합니다.
Elastic Search 설정하기
⚠️ Elastic Search 설정을 깊게 이해하기 위해서는 반드시 Before-Elastiscearch 깊게 보기를 보고 와주세요.
Elastic Search의 설정은 크게 두분류로 나눠집니다.
- 클러스터 구축
- 연결(Logstash → Elastic → Kibana)
- 보안
- 네트워크
클러스터의 경우에는 노드가 많이 필요하기 때문에 실습단계에서 어려움이 있습니다. 또한 개발 단계에서 중요한건 연결 부분입니다. 그래서 이번 글은 연결에 초점을 맞춰서 진행하도록 하겠습니다.
📦 One node cluster 구축
elasticsearch.yml에 작성하세요.
cluster.name: my-practice-cluster
node.name: node-1
# Set to single-node discovery type
discovery.type: single-node
# path
path.data: <your-path> # ✍️ stores all its data files
path.logs: <your-path> # ✍️ startup log, error log, query performances ...
# Network set
network.host: 127.0.0.1
http.port: 9200 # default
# security
👉 관련설정은 아래 x-pack 관련 오류에서 확인
path를 통해 데이터가 들어있는 공간을 직접 확인하실 수 있습니다.
🔐 pw/id
x-pack을 사용하였기 때문에 기본적으로 id/pw 로 요청을 수행해야합니다. 아직 등록전이라면 아래 명령어를 통해 등록해봅시다(사실 초기화 개념).
$ ./bin/elasticsearch-setup-passwords auto
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This command will be removed in a future release.
******************************************************************************
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y
Changed password for user apm_system
PASSWORD apm_system = <pw>
Changed password for user kibana_system
PASSWORD kibana_system = <pw>
Changed password for user kibana
PASSWORD kibana = <pw>
Changed password for user logstash_system
PASSWORD logstash_system = <pw>
Changed password for user beats_system
PASSWORD beats_system = <pw>
Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = <pw>
Changed password for user elastic
PASSWORD elastic = <pw>
🧹 elastic search 기본 정보 받아보기
$ curl -u elastic:<pw> -X GET "http://localhost:9200/"
👉 response
{
"name" : "node-1",
"cluster_name" : "my-practice-cluster",
"cluster_uuid" : "hPnIhFfTT3KjRmBUzVmCYQ",
"version" : {
"number" : "8.14.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d55f984299e0e88dee72ebd8255f7ff130859ad0",
"build_date" : "2024-07-07T22:04:49.882652950Z",
"build_snapshot" : false,
"lucene_version" : "9.10.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
json 형식으로 데이터가 오는 것을 볼 수 있네요.
데이터 저장 및 검색
간단한 데이터를 저장해봅시다.
#index 생성 - lowercase 만 사용
curl -u elastic:<pw> -X put "http:localhost:9200/text"
👉 response
{"acknowledged":true,"shards_acknowledged":true,"index":"test"}
# HTTP Json 통신
curl -u elastic:9jgjqri6igh5DCKtEyq2
-X POST "http://localhost:9200/test/_doc" -H 'Content-Type: application/json' -d '{
"title": "Sample Document",
"content": "This is some data saved via curl."
}'
👉 response
{
"_index": "test",
"_id": "hiQDNpgBnZBPcwzw0c29",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1
}
정상적으로 저장된 로그를 확인하실 수 있습니다. 이번에는 해당 \_id를 가진 데이터를 조회해봅시다.
$ curl -u elastic:9jgjqri6igh5DCKtEyq2 -X GET "http://localhost:9200/test/_doc/hiQDNpgBnZBPcwzw0c29?pretty=true"
👉 response
{
"_index" : "test",
"_id" : "hiQDNpgBnZBPcwzw0c29",
"_version" : 1,
"_seq_no" : 3,
"_primary_term" : 1,
"found" : true,
"_source" : {
"title" : "Sample Document2",
"content" : "This is some data saved via curl."
}
}
pretty=true 옵션을 넘겨주면 json 데이터가 깔끔한 format으로 응답됩니다.
Next
- Logstash와 연동하기
발생한 오류들
- x-pack 관련
- 보러가기
