Debian/ Ubuntu

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

Xác định một loại agent mà mình muốn cài và làm theo hưỡng dẫn của agent đó dưới đây:

  • Nếu sử dụng script chuẩn bị sẵn trong thư mục tải về, chạy lệnh

  • Nếu cài thủ công, chạy lệnh

sudo chmod +x filebeat.sh
sudo ./filebeat.sh <path-to-file-log>
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.7.1-amd64.deb
sudo dpkg -i filebeat-8.7.1-amd64.deb

  • Nếu sử dụng script chuẩn bị sẵn trong thư mục tải về, chạy lệnh

  • Nếu cài thủ công, chạy lệnh

sudo chmod +x logstash.sh
sudo ./logstash.sh <path-to-file-log>
Cài java (>8): sudo apt-get install openjdk-8-jre-headless -y
Cài Logstash: curl -LO  https://artifacts.elastic.co/downloads/logstash/logstash-8.6.2-amd64.deb 
			  sudo dpkg -i logstash-8.6.2-amd64.deb

Tiếp theo bạn cần cấu hình agent log. 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 /etc/filebeat/filebeat.yml. Cấu hình dưới đây sẽ lấy tất cả log trong file /var/log/app.log đẩy về vMonitor Platform:

  • Trong đó:

    • Tại input đường dẫn tới file log

    • Tại output , các biến cần điền bạn lấy từ bước tải certicate ở trên:

      • $BOOTSTRAP_SERVERS, $TOPIC lấy trong file info.md

      • $PATH_FILE_VNG_TRUST_PEM,$PATH_FILE_USER_CER_PEM,$PATH_FILE_USER_KEY_PEM là đường dẫn tới file VNG.trust.pem user.cer.pem user.key.pem

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:
    - $PATH_FILE_VNG_TRUST_PEM
  ssl.certificate: "$PATH_FILE_USER_CER_PEM"
  ssl.key: "$PATH_FILE_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

  • File /etc/logstash/conf.d/logstash.conf. Cấu hình dưới đây sẽ lấy tất cả log trong file /var/log/app.log đẩy về vMonitor Platform:

  • Trong đó: tại input , nếu như muốn lấy thêm log tại các file khác, cấu hình thêm như sau

  • Tại output , các biến cần điền bạn lấy từ bước tải certicate ở trên:

    • $BOOTSTRAP_SERVERS, $TOPIC, $TRUTSTORE_PASS, $USER_PASS lấy trong file info.md

    • $PATH_FILE_VNG_TRUST, $PATH_FILE_USER_KEY là đường dẫn tới file VNG.trust, user.key

input {
    file {
        start_position => "beginning"
        path => [ "/var/log/app.log" ]
    }
}

output {
      kafka {
        codec => json
        bootstrap_servers => "$BOOTSTRAP_SERVERS"
        topic_id => "$TOPIC"
        security_protocol => "SSL"
        ssl_truststore_location => "$PATH_FILE_VNG_TRUST"
        ssl_truststore_password => "$TRUTSTORE_PASS"
        ssl_keystore_location => "$PATH_FILE_USER_KEY"
        ssl_keystore_password => "$USER_PASS"
        ssl_key_password => "$USER_PASS"
        ssl_endpoint_identification_algorithm => ""
      }
}
input {
    file {
        start_position => "beginning"
        path => [ "/var/log/app.log" , "/var/log/backend.log", "/var/log/cmd/*.log"]
    }
}

Quản trị

Nếu cài thủ công, mặc định agent log sau khi cài sẽ không tự động bật, bạn kiểm tra việc khởi động (start) và enable (tự khởi động cùng máy) cho chúng.

  • Start

  • Enable

  • Stop

  • Reload

  • Restart

  • Observe

  • Uninstall

systemctl start filebeat
systemctl enable filebeat
systemctl stop filebeat
systemctl reload filebeat
systemctl restart filebeat
systemctl status filebeat
journalctl -f --unit filebeat
tail -f /var/log/filebeat
apt remove --purge filebeat

  • Start

  • Enable

  • Stop

  • Reload

  • Restart

  • Observe

  • Uninstall

systemctl start logstash
systemctl enable logstash
systemctl stop logstash
systemctl reload logstash
systemctl restart logstash
systemctl status logstash
journalctl -f --unit logstash
tail -f /var/log/logstash
apt remove --purge logstash

Last updated