Filebeat 치트시트
설치
| 플랫폼 | 명령어 |
|---|
| Ubuntu/Debian | `wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch \ |
| RHEL/CentOS | sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo yum install filebeat |
| macOS | brew tap elastic/tap
brew install elastic/tap/filebeat-full |
| Windows | Download from https://artifacts.elastic.co/downloads/beats/filebeat/ Extract and run: .\install-service-filebeat.ps1 |
| Docker | docker pull docker.elastic.co/beats/filebeat:8.11.0 |
| Kubernetes (Helm) | helm repo add elastic https://helm.elastic.co
helm install filebeat elastic/filebeat |
| 명령어 | 설명 |
|---|
sudo systemctl start filebeat | Filebeat 서비스 시작 |
sudo systemctl stop filebeat | Filebeat 서비스 중지 |
sudo systemctl restart filebeat | Filebeat 서비스 재시작 |
sudo systemctl status filebeat | Filebeat 서비스 상태 확인 |
sudo systemctl enable filebeat | 부팅 시 Filebeat 활성화 |
sudo filebeat -e | Filebeat를 포그라운드에서 콘솔 출력과 함께 실행 |
sudo filebeat -e -c /path/to/filebeat.yml | 특정 구성 파일로 실행 |
sudo filebeat test config | 구성 파일 구문 유효성 검사 |
sudo filebeat test output | 구성된 출력에 대한 연결성 테스트 |
sudo journalctl -u filebeat -f | Filebeat 서비스 로그를 실시간으로 보기 |
sudo filebeat modules list | 사용 가능한 모듈 모두 나열하기 |
sudo filebeat modules enable apache | 특정 모듈 활성화 (Apache 예시) |
sudo filebeat modules disable apache | 특정 모듈 비활성화 |
sudo filebeat setup | 인덱스 템플릿, 대시보드, 파이프라인 로드 |
sudo filebeat version | Filebeat 버전 정보 표시 |
| 명령어 | 설명 |
|---|
sudo filebeat modules list | 사용 가능한 모든 모듈과 해당 상태 표시 |
sudo filebeat modules enable nginx mysql | 한 번에 여러 모듈 활성화하기 |
sudo filebeat modules disable system | 모듈 비활성화 |
| `sudo filebeat modules list \ | grep Enabled -A 10` |
sudo filebeat export config --modules apache | 특정 모듈 구성 내보내기 |
ls /etc/filebeat/modules.d/ | 목록 모듈 구성 파일 |
sudo vi /etc/filebeat/modules.d/nginx.yml | 모듈 구성 파일 편집 |
| 명령어 | 설명 |
|---|
sudo filebeat setup --index-management | Elasticsearch에서 색인 템플릿만 설정하기 |
sudo filebeat setup --dashboards | Kibana 대시보드만 설정하기 |
sudo filebeat setup --pipelines | 수집 파이프라인만 설정 |
sudo filebeat setup -E output.elasticsearch.hosts=['es:9200'] | 특정 Elasticsearch 호스트로 설정 |
sudo filebeat setup -E output.elasticsearch.username=elastic -E output.elasticsearch.password=pass | 인증 자격 증명으로 설정 |
sudo filebeat export template | stdout로 인덱스 템플릿 내보내기 |
sudo filebeat export ilm-policy | ILM(인덱스 수명 주기 관리) 정책 내보내기 |
| 명령어 | 설명 |
|---|
sudo filebeat -e -d "*" | 모든 구성 요소에 대해 디버그 로깅으로 실행 |
sudo filebeat -e -d "publish,harvester" | 특정 구성 요소만 디버그하기 |
sudo filebeat -e --strict.perms=false | 엄격한 권한 확인 비활성화 |
sudo filebeat -e -E http.enabled=true -E http.host=localhost -E http.port=5066 | HTTP 모니터링 엔드포인트 활성화 |
curl http://localhost:5066/stats | 통계를 위한 쿼리 모니터링 엔드포인트 |
curl http://localhost:5066/state | 상세한 상태 정보 가져오기 |
sudo filebeat -e -E output.console.enabled=true -E output.elasticsearch.enabled=false | Elasticsearch 대신 콘솔에 이벤트 출력 |
sudo filebeat -e -E filebeat.config.inputs.workers=4 | 특정 수의 작업자로 실행 |
sudo filebeat -e -E output.elasticsearch.bulk_max_size=100 | 대량 색인 크기 조정 |
sudo filebeat -e -E queue.mem.events=8192 | 큐 메모리 이벤트 제한 설정 |
sudo filebeat -e -E output.elasticsearch.compression_level=3 | Elasticsearch 출력에 대한 압축 활성화 |
sudo filebeat test config -e -d "processors" | 디버그 출력으로 프로세서 구성 테스트하기 |
sudo filebeat migrate-registry | 이전 Filebeat 버전에서 레지스트리 마이그레이션 |
sudo filebeat export config | 전체 구성을 stdout으로 내보내기 |
curl http://localhost:5066/autodiscover | 자동 검색 상태 확인 |
| 명령어 | 설명 |
|---|
sudo filebeat keystore create | 비밀 키 저장소 생성하기 |
sudo filebeat keystore add ES_PASSWORD | 키스토어에 비밀 추가 (값 입력 프롬프트) |
sudo filebeat keystore list | 키스토어의 모든 키 나열하기 |
sudo filebeat keystore remove ES_PASSWORD | 키스토어에서 키 제거하기 |
주 구성 파일
위치: /etc/filebeat/filebeat.yml(Linux) 또는 C:\Program Files\filebeat\filebeat.yml(Windows)
기본 입력 구성
# Filestream input (recommended for log files)
filebeat.inputs:
- type: filestream
id: my-app-logs
enabled: true
paths:
- /var/log/myapp/*.log
fields:
app: myapp
environment: production
fields_under_root: true
로그 입력 구성
# Log input (legacy, but still supported)
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
exclude_lines: ['^DEBUG']
include_lines: ['^ERR', '^WARN']
multiline.pattern: '^[[:space:]]'
multiline.negate: false
multiline.match: after
컨테이너 입력 구성
# Docker container logs
filebeat.inputs:
- type: container
enabled: true
paths:
- /var/lib/docker/containers/*/*.log
processors:
- add_docker_metadata: ~
Elasticsearch 출력
output.elasticsearch:
hosts: ["elasticsearch:9200"]
username: "elastic"
password: "${ES_PASSWORD}" # From keystore
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
pipeline: "filebeat-%{[agent.version]}-apache-access-default"
Logstash 출력
output.logstash:
hosts: ["logstash:5044"]
loadbalance: true
ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
ssl.certificate: "/etc/pki/client/cert.pem"
ssl.key: "/etc/pki/client/cert.key"
Kafka 출력
output.kafka:
hosts: ["kafka1:9092", "kafka2:9092"]
topic: "filebeat"
partition.round_robin:
reachable_only: false
compression: gzip
max_message_bytes: 1000000
프로세서 구성
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
- drop_fields:
fields: ["agent.ephemeral_id", "agent.id"]
- decode_json_fields:
fields: ["message"]
target: "json"
overwrite_keys: true
Docker용 자동 검색
filebeat.autodiscover:
providers:
- type: docker
hints.enabled: true
templates:
- condition:
contains:
docker.container.image: nginx
config:
- type: container
paths:
- /var/lib/docker/containers/${data.docker.container.id}/*.log
processors:
- add_docker_metadata: ~
Kubernetes용 자동 검색
filebeat.autodiscover:
providers:
- type: kubernetes
node: ${NODE_NAME}
hints.enabled: true
hints.default_config:
type: container
paths:
- /var/log/containers/*${data.kubernetes.container.id}.log
모듈 구성 예시
# /etc/filebeat/modules.d/nginx.yml
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log*"]
일반적인 사용 사례
사용 사례 1: 애플리케이션 로그 수집
Would you like me to continue with the remaining translations or provide more context for the empty sections?```bash
sudo vi /etc/filebeat/filebeat.yml
```yaml
filebeat.inputs:
- type: filestream
id: myapp-logs
enabled: true
paths:
- /var/log/myapp/*.log
fields:
app: myapp
env: production
# Test configuration and restart
sudo filebeat test config
sudo systemctl restart filebeat
```### Use Case 2: Nginx 로그 수집
```bash
# Enable Nginx module
sudo filebeat modules enable nginx
# Configure module
sudo vi /etc/filebeat/modules.d/nginx.yml
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log*"]
# Setup dashboards and restart
sudo filebeat setup --dashboards
sudo systemctl restart filebeat
```### Use Case 3: Docker 컨테이너 로그 수집
```bash
# Run Filebeat in Docker to collect container logs
docker run -d \
--name=filebeat \
--user=root \
--volume="$(pwd)/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro" \
--volume="/var/lib/docker/containers:/var/lib/docker/containers:ro" \
--volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
docker.elastic.co/beats/filebeat:8.11.0
```### Use Case 4: Kubernetes DaemonSet 배포
```bash
# Deploy Filebeat as DaemonSet using Helm
helm repo add elastic https://helm.elastic.co
helm repo update
# Create values file
cat > filebeat-values.yaml <<EOF
daemonset:
enabled: true
filebeatConfig:
filebeat.yml: |
filebeat.autodiscover:
providers:
- type: kubernetes
node: \${NODE_NAME}
hints.enabled: true
output.elasticsearch:
hosts: ["elasticsearch:9200"]
EOF
# Install Filebeat
helm install filebeat elastic/filebeat \
--namespace logging --create-namespace \
-f filebeat-values.yaml
```### Use Case 5: 멀티라인 로그 파싱 (스택 트레이스)
```bash
# Configure multiline pattern for Java stack traces
sudo vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: java-app
enabled: true
paths:
- /var/log/java-app/*.log
parsers:
- multiline:
type: pattern
pattern: '^[[:space:]]+(at|\.{3})\b|^Caused by:'
negate: false
match: after
# Test and restart
sudo filebeat test config
sudo systemctl restart filebeat
```### Use Case 6: 여러 출력 대상으로 로그 전송
```bash
# Configure Logstash output for processing and Elasticsearch for backup
sudo vi /etc/filebeat/filebeat.yml
output.logstash:
hosts: ["logstash:5044"]
loadbalance: true
# Note: Only one output can be active at a time in Filebeat
# For multiple outputs, use Logstash as intermediary
```### Use Case 7: 로그 필터링 및 보강
```bash
# Add processors to enrich and filter logs
sudo vi /etc/filebeat/filebeat.yml
processors:
- drop_event:
when:
regexp:
message: "^DEBUG"
- add_fields:
target: ''
fields:
datacenter: us-east-1
team: platform
- decode_json_fields:
fields: ["message"]
target: "json"
overwrite_keys: true
- drop_fields:
fields: ["agent.ephemeral_id", "ecs.version"]
```## 모범 사례
- **Filestream 입력 사용**: 파일 회전에 대해 더 나은 성능과 안정성을 위해 레거시 입력 유형보다 선호
- **모듈 활성화**: 가능한 경우 사용자 정의 구성 대신 사전 구축된 모듈(nginx, apache, mysql 등)을 사용하여 더 빠른 설정 및 더 나은 파싱
- **백프레셔 처리 구현**: 데이터 손실 없이 로드 스파이크를 처리하도록 구성
- **자격 증명 보안**: 구성 파일의 평문 대신 Filebeat 키 저장소에 민감한 정보(비밀번호, API 키) 저장
- **리소스 사용량 모니터링**: Filebeat 성능 및 하베스터 상태를 모니터링하기 위해 HTTP 엔드포인트 활성화
- **인덱스 수명 주기 관리(ILM) 사용**: 인덱스 보존 및 스토리지 비용 절감을 자동으로 관리하도록 ILM 정책 구성
- **로그에 태그 지정 및 보강**: 로그를 더 검색 가능하고 컨텍스트화하기 위해 프로세서를 사용하여 사용자 정의 필드 및 메타데이터 추가
- **프로덕션 전 테스트**: 구성 변경을 배포하기 전에 항상 테스트
- **멀티라인 로그 처리**: 로그 조각화를 방지하기 위해 스택 트레이스 및 멀티라인 애플리케이션 로그에 대한 멀티라인 패턴 구성
- **자동 검색 구현**: 동적 환경(Docker, Kubernetes)에서 새 컨테이너를 자동으로 감지 및 구성하기 위해 자동 검색 사용
- **정기적인 업데이트**: Elasticsearch 버전과 호환성 및 보안 패치를 위해 Filebeat를 최신 버전으로 유지
- **적절한 권한 설정**: Filebeat가 로그 파일에 대한 읽기 액세스 권한을 가지지만 최소 권한 원칙을 따르도록 보장
`filestream`## 문제 해결
`log`## 빠른 참조: 일반적인 파일 위치
`queue.mem.events`## 성능 튜닝 매개변수
`output.elasticsearch.bulk_max_size`| 10초 | 새 파일 확인 주기 | 5초-30초 |`http.enabled: true`) to monitor Filebeat performance and harvester status
- **Use Index Lifecycle Management (ILM)**: Configure ILM policies to automatically manage index retention and reduce storage costs
- **Tag and Enrich Logs**: Add custom fields and metadata using processors to make logs more searchable and contextual
- **Test Before Production**: Always use `filebeat test config` and `filebeat test output` before deploying configuration changes
- **Handle Multiline Logs**: Configure multiline patterns for stack traces and multi-line application logs to prevent log fragmentation
- **Implement Autodiscover**: Use autodiscover for dynamic environments (Docker, Kubernetes) to automatically detect and configure new containers
- **Regular Updates**: Keep Filebeat updated to match your Elasticsearch version for compatibility and security patches
- **Set Appropriate Permissions**: Ensure Filebeat has read access to log files but follows the principle of least privilege
## Troubleshooting
| 문제 | 솔루션 |
|-------|----------|
| **Filebeat not starting** | Check configuration syntax: `sudo filebeat test config`<br>Check service status: `sudo systemctl status filebeat`<br>Review logs: `sudo journalctl -u filebeat -n 50` |
| **No data in Elasticsearch** | Test output connectivity: `sudo filebeat test output`<br>Check Elasticsearch is running: `curl http://elasticsearch:9200`<br>Verify index exists: `curl http://elasticsearch:9200/_cat/indices?v` |
| **Permission denied errors** | Ensure Filebeat has read access: `sudo chmod 644 /var/log/myapp/*.log`<br>Check file ownership: `ls -la /var/log/myapp/`<br>Run with proper user: `sudo chown root:root /etc/filebeat/filebeat.yml` |
| **Duplicate events** | Check registry file: `/var/lib/filebeat/registry/filebeat/data.json`<br>Ensure unique input IDs in configuration<br>Avoid multiple Filebeat instances reading same files |
| **High memory usage** | Reduce queue size: `queue.mem.events: 2048`<br>Decrease harvester limit: `filebeat.config.inputs.max_harvesters: 100`<br>Enable compression: `output.elasticsearch.compression_level: 3` |
| **Logs not being tailed** | Check file paths are correct: `ls -la /var/log/myapp/*.log`<br>Verify input is enabled in configuration<br>Check close_inactive setting isn't too aggressive |
| **Connection timeout to Elasticsearch** | Increase timeout: `output.elasticsearch.timeout: 90`<br>Check network connectivity: `telnet elasticsearch 9200`<br>Verify credentials: `curl -u elastic:password http://elasticsearch:9200` |
| **Module not working** | Verify module is enabled: `sudo filebeat modules list`<br>Check log paths in module config: `cat /etc/filebeat/modules.d/nginx.yml`<br>Ensure ingest pipelines loaded: `sudo filebeat setup --pipelines` |
| **Multiline logs not parsing** | Test pattern with sample logs<br>Check `multiline.negate` and `multiline.match` settings<br>Review harvester debug logs: `sudo filebeat -e -d "harvester"` |
| **SSL/TLS connection errors** | Verify certificate paths and permissions<br>Check certificate validity: `openssl x509 -in cert.pem -text -noout`<br>Disable SSL verification for testing: `output.elasticsearch.ssl.verification_mode: none` |
| **Registry file corruption** | Stop Filebeat: `sudo systemctl stop filebeat`<br>Backup registry: `sudo cp -r /var/lib/filebeat/registry /tmp/registry.bak`<br>Remove registry: `sudo rm -rf /var/lib/filebeat/registry`<br>Restart (will reprocess logs): `sudo systemctl start filebeat` |
| **Autodiscover not detecting containers** | Check Docker socket permissions: `ls -la /var/run/docker.sock`<br>Verify autodiscover config syntax<br>Enable debug: `sudo filebeat -e -d "autodiscover"` |
## Quick Reference: Common File Locations
| 항목 | 위치 (Linux) | 위치 (Windows) |
|------|------------------|-------------------|
| **Main config** | `/etc/filebeat/filebeat.yml` | `C:\Program Files\filebeat\filebeat.yml` |
| **Module configs** | `/etc/filebeat/modules.d/` | `C:\Program Files\filebeat\modules.d\` |
| **Registry** | `/var/lib/filebeat/registry/` | `C:\ProgramData\filebeat\registry\` |
| **Logs** | `/var/log/filebeat/` | `C:\ProgramData\filebeat\logs\` |
| **Binary** | `/usr/share/filebeat/bin/filebeat` | `C:\Program Files\filebeat\filebeat.exe` |
| **Data directory** | `/var/lib/filebeat/` | `C:\ProgramData\filebeat\` |
## Performance Tuning Parameters
| 매개변수 | 기본값 | 설명 | 권장 범위 |
|-----------|---------|-------------|-------------------|
| `queue.mem.events` | 4096 | 이벤트 큐가 보유할 수 있는 이벤트의 수 | 2048-8192 |
| `queue.mem.flush.min_events` | 2048 | 최소 플러시 이전 이벤트 | 1024-4096 |
| `output.elasticsearch.bulk_max_size` | 50 | 대량 요청당 최대 이벤트 수 | 50-1600 |
| `output.elasticsearch.worker` | 1 | 출력 작업자 수 | 1-4 |
| `filebeat.config.inputs.max_harvesters` | 0 (무제한) | 최대 동시 파일 리더 | 100-500 |
| `close_inactive` | 5m | 비활성 후 파일 닫기 | 1m-10m || `scan_frequency` | 10s | How often to check for new files | 5s-30s |