일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Minikube
- TABNET
- Tabular
- 데이터 플랫폼
- 리눅스
- Kibana
- 쿠버플로
- Python
- hive
- Kubernetes
- 파이썬처럼생각하기
- 하이브
- fluentd
- MLOps
- 데이터 아키텍처
- 파이썬답게생각하기
- Opensearch
- 머신러닝
- AWS Glue
- 쿠버네티스
- Spark
- elk
- mesos
- etl
- yarn
- gcp
- 파이썬
- Kubeflow
- 쿠버플로우
- MachineLearning
- Today
- Total
데이터를 걷는 선비
[ELK] 오픈소스(Fluentd, OpenSearch)로 ELK 스택 설치 후 실습해보기 (2) 본문
[순서]
- 1) ELK 아키텍처 개괄
- 2) Fluentd 설치
- 3) Log Generator로 로그 생성
- 4) Opensearch 설치
- 5) Fluentd로 로그파일 읽어서 보내기 <-- 여기서부터
- 6) Opensearch Dashboard로 시각화하기
https://semizero.tistory.com/38
[ELK] 오픈소스(Fluentd, OpenSearch)로 ELK 스택 설치 후 실습해보기 (1)
[순서] 1) ELK 아키텍처 개괄 2) Fluentd 설치 3) Log Generator로 로그 생성 4) Opensearch 설치 Docker 설치는 공식문서 참조!! (공식문서가 제일 깔끔한 것 같습니다.) - WSL은 amd 기반의 cpu를 기준으로 함(arm은
semizero.tistory.com
5) Fluentd로 로그파일 읽어서 보내기
0. opensearch 실행
cd opensearch-2.4.0
./bin/opensearch
1. 설정 명령들 파악
https://docs.fluentd.org/configuration/config-file
Config File Syntax - Fluentd
Fluentd accepts all non-period characters as a part of a tag. However, since the tag is sometimes used in a different context by output destinations (e.g. the table name, database name, key name, etc.), it is strongly recommended that you stick to the lowe
docs.fluentd.org
- source : 어떤 것을 읽어서 내보낼까(input source)
- match : 어떤 곳으로 내보낼까(output source)
- filter : 이벤트 처리 파이프라인의 조건들 지
- system : 시스템의 configuration
- label : internal routing 할 때 labeling 사용
- worker : worker 리소스 관련
- @include : 다른 파일들 포함여부 관련
2. fluent.conf 파일 열기
vi fluent.conf
3. Input 지정하기
- 이전 포스트에서 생성한 loggen 경로에 json 파일들을 input으로 지정한다.
<source>
@type tail
tag log.json.*
path /home/ubuntu/loggen/json-*.log
pos_file positions-json.pos
read_from_head true
follow_inodes true
<parse>
@type json
time_key datetime
time_type string
time_format %d/%b/%Y:%H:%M:%S %z
</parse>
</source>
- input plugin
- input으로 지정할 수 있는 plugin으로는 아래 공식 문서에 나와 있듯이 다양한 plugin이 존재한다.
- https://docs.fluentd.org/input
- @type이 tail인 것을 보아 text 파일의 꼬리에서 이벤트를 읽도록 작동됨을 알 수 있다.
- tag: 이벤트의 태그
- path: 읽을 경로
- pos_file : 마지막으로 읽은 위치를 기록
- read_from_head : head 부터 읽기 시작하는 지의 여
- follow_inodes : 중복된 파일을 읽는 것을 피할지의 여부
- <parser> 지시문 필수
- 등등 여러가지 plugin이 있으니 꼭 참조하자!!
Input Plugins - Fluentd
Input plugins extend Fluentd to retrieve and pull event logs from the external sources. An input plugin typically creates a thread, socket, and a listening socket. It can also be written to periodically pull data from the data sources.
docs.fluentd.org
- parse
- input 데이터를 어떻게 읽을 지에 대한 규칙은 <parse>를 통해 지시할 수 있다.
- 자세한 parsing 매뉴얼은 아래 공식문서에서 확인할 수 있다.
- https://docs.fluentd.org/configuration/parse-section
Config: Parse Section - Fluentd
array: Converts the string field into Array type. For the array type, the third field specifies the delimiter (the default is comma ","). For example, if a field item_ids contains the value "3,4,5", types item_ids:array parses it as ["3", "4", "5"]. Altern
docs.fluentd.org
4. Output 지정하기
- output에 관련된 정보를 <match>를 통해 지정한다.
- 일전에 실행시켜두었던 opensearch를 output의 경로로 지정한다.
<match log.json.**>
@type opensearch
hosts $your_opensearch_host:9200 #localhost인 127.0.0.1
logstash_format true
logstash_prefix json-timelog
include_timestamp true
time_key datetime
time_key_format %d/%b/%Y:%H:%M:%S %z
</match>
5. fluent.conf 확인하기
6. fluentd 실행 명령어
fluentd -c ./fluent.conf -vv
curl 로 index 가 생성되었는지 확인한다.
curl -XGET http://$your_opensearch_host:9200/_cat/indices?v
6) Opensearch Dashboard로 시각화하기
1. 다운로드 및 설치
wget https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/2.4.0/opensearch-dashboards-2.4.0-linux-x64.tar.gz
tar -zxf opensearch-dashboards-2.4.0-linux-x64.tar.gz
cd opensearch-dashboards-2.4.0
export OPENSEARCH_DASHBOARDS_HOME=$(pwd)
2. 설정 변경
vi config/opensearch_dashboards.yml
- server.host 를 브라우저에 입력할 주소 이름을 입력해야 CORS이슈가 발생하지 않는다.
- opensearch.hosts 연결.
- 실습을 위해서 https가 아닌 http 를 사용.
- security 관련 설정을 지운다. (실습의 편의를 위해)
server.host: $your_localhost
server.port: 5601
opensearch.hosts: [http://localhost:9200]
opensearch.ssl.verificationMode: none
opensearch.username: kibanaserver
opensearch.password: kibanaserver
# opensearch.requestHeadersWhitelist: [authorization, securitytenant]
# opensearch_security.multitenancy.enabled: false
# opensearch_security.multitenancy.tenants.preferred: [Private, Global]
# opensearch_security.readonly_mode.roles: [kibana_read_only]
# Use this setting if you are running opensearch-dashboards without https
# opensearch_security.cookie.secure: false
3. security 플러그인 삭제
./bin/opensearch-dashboards-plugin remove securityAnalyticsDashboards
./bin/opensearch-dashboards-plugin remove securitytDashboards
4. 실행!!
./bin/opensearch-dashboards
5. 접속 127.0.0.1/5601
6. Stack Management를 통해 Index Patterns 확인
- json-timelog 에 관한 Index Pattern 생성
- 세부 pattern 확인
- Discover 메뉴에서 filter를 주면 관련 log들이 들어온 것을 확인할 수 있으며,
- 나중에 이를 통해 시각화를 진행하면 된다.
'Develop > Back-End' 카테고리의 다른 글
[ELK] 오픈소스(Fluentd, OpenSearch)로 ELK 스택 설치 후 실습해보기 (1) (0) | 2023.07.29 |
---|---|
[ELK] 로그모니터링을 위한 ELK Stack 개념들!! (0) | 2023.07.29 |