• 2021. 3. 25.

    by. 윈썸지니

    반응형

    로그를 수집하는 오픈소스인 filebeat 설치 및 환경 설정 파일 구성에 대한 내용 입니다.

     

    Filebeat를 간략히 소개하자면 경량 로그 수집기로 filebeat가 설치된 시스템에서 발생한 로그 데이터를 Elasticsearch, Logstash 또는 kafka로 전달할 수 있습니다.

     

    제가 설치한 환경은 windows 10 환경에 설치하여 로그를 수집해 보았습니다.

     

    1. filebeat 설치 파일을 다운로드

    먼저 filebeat 설치 파일이 필요하므로 아래 사이트에서 다운로드 합니다.

     

    다운로드 사이트 :   https://www.elastic.co/kr/downloads/beats/filebeat

     

    filebeat download

     

    2. 압축 해제

    위에서 다운 받은 압축 파일을 풀어 줍니다.

    따로 설치가 필요하지는 않고 압축을 해제 하는 것으로 설치는 되는 것이므로 실체 설치할 위치에 압축을 풀어 줍니다.

     

    filebeat zip 파일 풀기
    filebeat 설치 파일들

     

    3.  Filebeat를 Windows 서비스로 등록

    Windows 서비스로 등록하여 자동 시작 및 제어를 편리하게 하기 위해 PowerShell을 관리자 권한으로 실행합니다.

    Windows아이콘 -> PowserShell -> 관리자 권핸으로 실행

    powsershell 관리자 권한으로 실행

    2번에서 압축 파일을 푼 폴더를 확인하면 install-service-Filebeat.ps1 파일이 있습니다.

    이 파일을 아래와 같이 파워셀에서 실행 해 줍니다.

     

    PS C:\> cd "Program Files

    PS C:\Program Files> cd filebeat

    PS C:\Program Files\filebeat> dir

        디렉터리: C:\Program Files\filebeat

    Mode                LastWriteTime     Length Name

    ----                -------------     ------ ----

    d----      2021-01-13   오전 8:11            kiba

    d----      2021-01-13   오전 8:11            modu

    d----      2021-01-27   오후 5:26            modu

    -a---      2021-01-13   오전 8:16         41 .bui

    -a---      2021-01-13   오전 8:11    3703475 fiel

    -a---      2021-01-13   오전 8:14   79626752 file

    -a---      2021-01-13   오전 8:11     135562 file

    -a---      2021-01-13   오전 8:11       9982 file

    -a---      2021-01-13   오전 8:16        879 inst

    -a---      2021-01-13   오전 6:58      13675 LICE

    -a---      2021-01-13   오전 7:00    8566190 NOTI

    -a---      2021-01-13   오전 8:16        814 READ

    -a---      2021-01-13   오전 8:16        250 unin

    PS C:\Program Files\filebeat> .\install-service-Filebeat.ps1

    Status   Name               DisplayName

    ------   ----               -----------

    Stopped  filebeat           filebeat

    PS C:\Program Files\filebeat>

    참고로 보안상의 문제로 설치가 되지 않는다면 cmd 창에서 아래와 같이 실행 해 줍니다.

     

    Powershell.exe -ExecutionPolicy UnRestricted -File .\install-service-filebeat.ps1

     

    4. Config 설정

    설치 폴더에서 filebeat.yml 파일을 열어서 편집을 시작합니다

     

    Input 설정 : 수집할 대상 로그 파일 설정.

    다른 위치의 파일 수집을 추가하고자 할 경우는 paths 부분 아래에 추가하면 됩니다.

    # ============================== Filebeat inputs ===============================

    filebeat.inputs:

    # Each - is an input. Most options can be set at the input level, so

    # you can use different inputs for various configurations.

    # Below are the input specific configurations.

    - type: log

      # Change to true to enable this input configuration.

      enabled: true

      # Paths that should be crawled and fetched. Glob based paths.

      paths:

        #- /var/log/*.log

        - c:\programdata\elasticsearch\logs\*

     

    Output 설정 : 로그를 보낼 서버 설정으로 기본적으로 Elasticsearch 설정이 되어 있는데 logstash 로 연결할 예정이므로 주석처리 해 주고 logstash 부분은 주석을 없애 줍니다.

     

    아래 hosts 부분은 logstash 가 설치 되어있는 서버 IP 와 Port 번호 입니다.

    # ---------------------------- Elasticsearch Output ----------------------------

    #output.elasticsearch:

      # Array of hosts to connect to.

      #hosts: ["localhost:9200"]

      # Protocol - either `http` (default) or `https`.

      #protocol: "https"

      # Authentication credentials - either API key or username/password.

      #api_key: "id:api_key"

      #username: "elastic"

      #password: "changeme"

    # ------------------------------ Logstash Output -------------------------------

    output.logstash:

      # The Logstash hosts

      hosts: ["192.168.23.150:5044"]

     

    5. 서비스 시작

    파워셀에서 다음 명령어를 사용하여 filebeat를 시작하거나 windows 서비스에 등록하였다면 서비스에서 시작해도 됩니다.

    PS C:\Program Files\filebeat> Start-Service Filebeat

    PS C:\Program Files\filebeat> get-service filebeat

    Status   Name               DisplayName

    ------   ----               -----------

    Running  filebeat           filebeat

    PS C:\Program Files\filebeat>

     

    위와 같이 로그를 수집할 시스템들에 대해 filebeat를 설치 한 후 한 시스템으로 로그를 수집하여 중앙 집중 방식으로 로그를 분석 및 처리 할 수 있는 환경을 구축 할 수 있습니다.

    반응형