deb 서비스 설치

 

서비스로 사용하기 위해 deb 설치시 -e 옵션이 적용되어있어서 로그를 남기지 않음.
(-e 옵션 : stderr 만 출력 및 syslog/file 로깅은 하지 않음)
그래서 yml 에 로깅 설정해도 로깅이 남지 않으므로 /lib/systemd/system/filebeat.service 에서 -e 옵션을 제거해야 함.

rotate 할 파일 용량은 logging.files.rotateeverybytesedit 로 설정 가능하며 기본 10MB (10485760 bytes) 사용.

 

backoff 와 max_backoff 는 파일을 더 자주 체크하여 전송한다. 기본값은 각 1s, 10s 이다.

0s 으로 설정시 정상동작하지 않는다.

(https://www.elastic.co/guide/en/beats/filebeat/7.x/filebeat-input-log.html#_backoff_4)

 

# 설치
> curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.2-amd64.deb
> sudo dpkg -i filebeat-7.3.2-amd64.deb

# 설정수정
> sudo vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  backoff: 1s
  max_backoff: 1s
  paths:
    - /home/user1/tmp/*.log

filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false

setup.template.settings:
  index.number_of_shards: 1

output.logstash:
  hosts: ["localhost:5044"]

processors:
  - add_host_metadata: ~
  - add_cloud_metadata: ~

logging.level: debug
logging.to_stderr: false
logging.to_syslog: false
logging.to_files: true
logging.files:
  path: /var/log/filebeat
  name: filebeat
  keepfiles: 7
  permissions: 0644


# 서비스 설정 수정(-e 옵션 제거)
> sudo vi /lib/systemd/system/filebeat.service
Environment="BEAT_LOG_OPTS=-e" 를
Environment="BEAT_LOG_OPTS=" 로 변경


# autostart 등록
> sudo systemctl enable filebeat

# 서비스 시작
> sudo systemctl start filebeat

# 로그 확인
> tail -f /var/log/filebeat/filebeat

 

 

직접 설치

 

설치 파일 다운로드 및 압축해제
> wget https:/artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.2.0-linux-x86_64.tar.gz

# 설정
> filebeat.yml

# 서비스 등록
> vi filebeat.service


[Unit]
Description=filebeat
Documentation=https:/www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]
User=ubuntu
Group=ubuntu
Environment="BEAT_LOG_OPTS=-e"
Environment="BEAT_CONFIG_OPTS=-c /test/bin/filebeat/filebeat.yml"
Environment="BEAT_PATH_OPTS=-path.home /test/bin/filebeat -path.config /test/bin/filebeat -path.data /test/log/filebeat -path.logs /test/log/filebeat"
ExecStart=/test/bin/filebeat/filebeat $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS
Restart=always

[Install]
WantedBy=multi-user.target
Alias=filebeat.service