본문 바로가기

Devops/모니터링 (ELK, Grafana)

(2) GCP 로그 수집 (1) - Fleet (ELK)

반응형

 

VM로그 수집 방법으로 Fleet을 이용하여 elastic agent 를 설치하여 VM 로그 수집 방법에 대해 설명한다.

 

1.Fleet Server

먼저 Fleet Server를 구축해야한다.

 

키바나 콘솔에서 Management - Fleet  - Settings를 클릭한다.

 

1) Fleet server hosts에 Fleet 서버가 VM의 될 IP:Port를 작성한다. 

 

 

2) Outputs 설정

해당 설정은 좀 더 확인해볼 예정이다.

 

 

3) Agents 항목 이동 후 Add Fleet Server 클릭

 

정보 확인 후 Generate service token 버튼 클릭

 

해당 정보에서 인증서 관련 설정 및 url 추가 후 실행

 

curl -L -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.13.1-linux-x86_64.tar.gz
tar xzvf elastic-agent-8.13.1-linux-x86_64.tar.gz
cd elastic-agent-8.13.1-linux-x86_64
sudo ./elastic-agent install \
  --url=https://10.2.0.11:8220 \
  --fleet-server-es=https://elastic.hrc0303.store:443 \
  --fleet-server-service-token=토큰 값 \
  --fleet-server-policy=fleet-server-policy \
  --fleet-server-port=8220
  --insecure

 

 

 

 

2.Elastic Agent (VM)

Agent 화면에서 Add agent 클릭

 

 


Install Elastic Agent on your host 부분에 인증서 무시 --insecure 추가 하여 VM에서 실행

 

Agent 설치 서버 정보

Rocky Linux로 테스트 하였음

 

먼저 설정해야 하는 부분이 있는데 SSL 인증서를 등록해야한다.

내가 가지고 있는 ca.crt 인증서를 /etc/pki/ca-trust/source/anchors/ 해당 위치에 업로드 후 update-ca-trust 명령어 실행 하여 인증서 적용을 해야한다.

 

 

해당 문구가 나오면 Y를 선택한다.

 

설치 성공 문구 확인 및 설치 확인

 

3. Elastic Agent(GKE)

해당 문서에 있는 자료를 바탕으로 작성 함

https://www.elastic.co/guide/en/fleet/current/running-on-kubernetes-managed-by-fleet.html 

 

Run Elastic Agent on Kubernetes managed by Fleet | Fleet and Elastic Agent Guide [8.14] | Elastic

The size and the number of nodes in a Kubernetes cluster can be large at times, and in such a case the Pod that will be collecting cluster level metrics might require more runtime resources than you would like to dedicate to all of the pods in the DaemonSe

www.elastic.co

 

해당 작업을 하면  elastic-agent-managed-kubernetes.yaml 파일이 생성됨

커스텀 작업이 필요하여 아래와 같이 변경했다.

Dockerfile 로 기존 elastic-agent에 hrc0303.store SSL 인증서 추가 후 적용

FROM docker.elastic.co/beats/elastic-agent:8.13.1

USER root
# 인증서 추가
COPY ca.crt /usr/local/share/ca-certificates/ca.crt
RUN update-ca-certificates

 

도커이미지 변경 및 env 환경 변수 내가 설정한 값으로 수정 

      containers:
        - name: elastic-agent
          image: gkfka133/fleet:8.13.1
        env:
            # Set to 1 for enrollment into Fleet server. If not set, Elastic Agent is run in standalone mode
            - name: FLEET_ENROLL
              value: "1"
            # Set to true to communicate with Fleet with either insecure HTTP or unverified HTTPS
            - name: FLEET_INSECURE
              value: "true"
            # Fleet Server URL to enroll the Elastic Agent into
            # FLEET_URL can be found in Kibana, go to Management > Fleet > Settings
            - name: FLEET_URL
              value: "https://10.2.0.11:8220"
            # Elasticsearch API key used to enroll Elastic Agents in Fleet (https://www.elastic.co/guide/en/fleet/current/fleet-enrollment-tokens.html#fleet-enrollment-tokens)
            # If FLEET_ENROLLMENT_TOKEN is empty then KIBANA_HOST, KIBANA_FLEET_USERNAME, KIBANA_FLEET_PASSWORD are needed
            - name: FLEET_ENROLLMENT_TOKEN
              value: "토큰 값 입력"
            - name: KIBANA_HOST
              value: "https://kibana.hrc0303.store:443"
            # The basic authentication username used to connect to Kibana and retrieve a service_token to enable Fleet
            - name: KIBANA_FLEET_USERNAME
              value: "elastic"
            # The basic authentication password used to connect to Kibana and retrieve a service_token to enable Fleet
            - name: KIBANA_FLEET_PASSWORD
              value: "패스워드 입력"

 

kube-system 네임스페이스에서 확인한 결과

 

 

키바나 Fleet  화면에서 추가 확인

 

 

 

 

 

반응형

'Devops > 모니터링 (ELK, Grafana)' 카테고리의 다른 글

(2) GCP 로그 수집 (2) - Fleet (ELK)  (0) 2024.07.27