Cài đặt Log Agent trên Docker
Trước khi thực hiện cài đặt agent trên các hệ điều hành mà chúng tôi hỗ trợ bên dưới, bạn cần phải tải xuống certificate theo hướng dẫn tại Khởi tạo Certificate. Thông tin hướng dẫn thiết lập agent nằm trong file readme, các script hướng dẫn cũng nằm trong tệp tin certificate được tải về. Sử dụng thông tin này với các hướng dẫn bên dưới để hoàn thành việc thiết lập Agent for Log.
Cài đặt
Tải image
docker pull docker.elastic.co/beats/filebeat:8.7.0
Tải certificate lấy thông tin xác thực user
Nếu sử dụng script chuẩn bị sẵn trong thư mục tải về, chạy lệnh:
Trong ví dụ thiết lập dưới dây chúng tôi sẽ mount
/var/log/app.log
vào agent cài bằng docker để đẩy log về hệ thống
docker compose up -d -f docker-compose.yml
Các file cấu hình dưới đều đã được chúng tôi chuẩn bị sẵn tại script khi tải certificate về, mô tả dưới đây giúp người đọc hình dung được nếu tạo manual sẽ thế nào.
Cấu hình
File
docker-compose.yml
version: "3"
services:
filebeat-agent-vmonitor:
image: docker.elastic.co/beats/filebeat:8.7.0
container_name: filebeat-agent-vmonitor
restart: always
env_file:
- container.env
volumes:
- $PWD/filebeat.yml:/usr/share/filebeat/filebeat.yml
- $PWD/VNG.trust.pem:/usr/share/filebeat/VNG.trust:rw
- $PWD/user.cer.pem:/usr/share/filebeat/user.cer.pem:rw
- $PWD/user.key.pem:/usr/share/filebeat/user.key.pem:rw
- /var/log/app.log:/var/log/app.log:ro
- /var/log/filebeat/:/var/log/filebeat/
logging:
driver: "json-file"
options:
max-size: "50m"
deploy:
resources:
limits:
cpus: '1'
memory: 2G
File
filebeat.yml
. Cấu hình dưới đây sẽ lấy tất cả log được ghi vào file/var/log/app.log
về vMonitor Platform:
filebeat.inputs:
- type: log
paths:
- /var/log/app.log
output.kafka:
hosts: ${BOOTSTRAP_SERVERS}
topic: ${TOPIC}
partition.round_robin:
reachable_only: false
required_acks: 1
compression: gzip
max_message_bytes: 1000000
ssl.certificate_authorities:
- /usr/share/filebeat/VNG.trust
ssl.certificate: /usr/share/filebeat/user.cer.pem
ssl.key: /usr/share/filebeat/user.key.pem
ssl.verification_mode: "none"
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
Note : các biến $
BOOTSTRAP_SERVERS, $TOPIC
ở trên đã nằm sẵn trongcontainer.env
file tại thư mục certificate tải về.
version: "3"
services:
filebeat-agent-vmonitor:
image: docker.elastic.co/beats/filebeat:8.7.0
container_name: filebeat-agent-vmonitor
restart: always
env_file:
- container.env
volumes:
- $PWD/filebeat.yml:/usr/share/filebeat/filebeat.yml
- $PWD/VNG.trust.pem:/usr/share/filebeat/VNG.trust:rw
- $PWD/user.cer.pem:/usr/share/filebeat/user.cer.pem:rw
- $PWD/user.key.pem:/usr/share/filebeat/user.key.pem:rw
- /var/log/app.log:/var/log/app.log:ro
- /var/log/filebeat/:/var/log/filebeat/
logging:
driver: "json-file"
options:
max-size: "50m"
deploy:
resources:
limits:
cpus: '1'
memory: 2G
filebeat.inputs:
- type: log
paths:
- /var/log/app.log
output.kafka:
hosts: ${BOOTSTRAP_SERVERS}
topic: ${TOPIC}
partition.round_robin:
reachable_only: false
required_acks: 1
compression: gzip
max_message_bytes: 1000000
ssl.certificate_authorities:
- /usr/share/filebeat/VNG.trust
ssl.certificate: /usr/share/filebeat/user.cer.pem
ssl.key: /usr/share/filebeat/user.key.pem
ssl.verification_mode: "none"
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
Quản trị
Stop
docker stop filebeat
Reload
docker kill --signal=HUP filebeat
Restart
docker restart filebeat
Observe
docker logs --tail 100 -f filebeat
Uninstall
docker rm filebeat
docker stop filebeat
docker kill --signal=HUP filebeat
docker restart filebeat
docker logs --tail 100 -f filebeat
docker rm filebeat
Trước khi thực hiện cài đặt tác nhân trên các hệ điều hành mà chúng tôi hỗ trợ bên dưới, bạn cần Khởi tạo Certificate. Thông báo hướng dẫn tác nhân thiết lập nằm trong tệp readme, hướng dẫn tập lệnh cũng nằm trong tệp tin chứng chỉ được tải về. Sử dụng thông tin này với các hướng dẫn bên dưới để hoàn thành việc thiết lập Agent for Log.
Last updated