AWS, Amazon Elasticsearch Service에 filebeat를 이용하여 ec2 nginx log 기록

2019. 2. 24. 12:59개발/AWS

 

아마존에서 제공해주는 Amazon Elasticsearch Service에 nginx의 log를 기록하고자 한다.

 

진행 순서

1. Amazon Elasticsearch Service 도메인 생성

2. filebeat 설치

3. filebeat.yml 설정

4. vpc 접속 방법

5. kibana 확인

 

 

1. Amazon Elasticsearch Service 도메인 생성

먼저 아마존의 Elasticsearch Service의 도메인을 생성한다.

 

Step 1.

- 기본 옵션으로 진행한다. 다음으로 넘어간다.

 

Step2

- 암호화의 '노드 간 암호화' 만 체크하고 다음으로 넘어간다.

 

Step 3

- 네트워크는 VPC로 설정했다. 이용중인 VPC, Public Subnet 1, 2 를 선택했다. 보안그룹은 test를 위해 모든 IP가 허용된 그룹을 이용했다.

- 액세스 정책은 'IAM 자격 증명으로 서명 요청이 필요하지 않음' 으로 하였다.

 

Step 4

- 검토 부분이므로 보고 확인한다.

 

 

2. filebeat 설치

로그를 수집하고 싶은 서버 (ec2)에 접속하여 filebat을 설치한다.

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.6.1-amd64.deb 

sudo dpkg -i filebeat-6.6.1-amd64.deb

 

 

3. filebeat.yml 설정

filebeat.yml을 수정한다.

sudo vi /etc/filebeat/filebeat.yml

 

filebeat.inputs:

- type: log

  enabled: true

  paths:

    - /var/log/nginx/access.log

.

.

.

#==================== Elasticsearch template setting ==========================

 

setup.template.enabled: true

setup.template.name: "example-%{+yyyy.MM.dd}"

setup.template.pattern: "example-*"

setup.template.fields: "$/fields.yml"

setup.template.overwrite: true

 

setup.template.settings:

  index.number_of_shards: 3

  #index.codec: best_compression

  #_source.enabled: false

.

.

.

#-------------------------- Elasticsearch output ------------------------------

output.elasticsearch:

  # Array of hosts to connect to.

  hosts: ["[VPC 엔드포인트]:443"]

 

  # Enabled ilm (beta) to use index lifecycle management instead daily indices.

  #ilm.enabled: false

 

  # Optional protocol and basic auth credentials.

  #protocol: "https"

  #username: "elastic"

  #password: "changeme"

 

  protocol: "https"

  index: "example-%{+yyyy.MM.dd}"

  pipeline: "example-pipeline"

 

  ssl.enabled: true

  ssl.supported_protocols: [TLSv1.2]

  ssl.cipher_suites: [ECDHE-RSA-AES-128-GCM-SHA256,ECDHE-ECDSA-AES-128-GCM-SHA256,ECDHE-RSA-AES-256-GCM-SHA384,ECDHE-ECDSA-AES-256-GCM-SHA384]

  ssl.curve_types: [P-256,P-384]

 

[VPC 엔드포인트] 는 생성한 Elasticsearch Service에서 볼 수 있다.

 

 

4. vpc 접속 방법

도움말 : https://docs.aws.amazon.com/ko_kr/elasticsearch-service/latest/developerguide/es-vpc.html#kibana-test

 

위 방법대로 해보겠다.

먼저 기본적인 EC2를 생성한다. 동일 VPC, 서브넷으로 해야한다.

그런 뒤 터미널에서 다음 명령어를 실행한다.

ssh -i "comento_example.pem" ec2-user@[퍼블릭 DNS] -N -L 9200:[VPC 엔드포인트]:443

 

 

5. kibana 확인

https://localhost:9200/_plugin/kibana 접속한다.

혹은 https://localhost:9200/_cat/indices 주소로 수집을 확인할 수 있다.