Skip to main content

ELK STACK 101 - Beats Collect, Parse, Ship

Beats là những data shipper mã nguồn mở mà ta sẽ cài đặt như các agent trên các server của ta để gửi các kiểu dữ liệu khác nhau tới Elasticsearch. Beats có thể gửi dữ liệu trực tiếp tới Elasticsearch hay tới Logstash từ đó ta có thể enrich hay archive dữ liệu.
Beats là một platform trong đó có các project nhỏ sinh ra thực hiện trên từng loại dữ liệu nhất định.
  • Packetbeat: a network packet analyzer
  • Topbeat: a server monitoring agent
  • Filebeat: ship log files from servers
  • Winlogbeat: ship windows event logs
  • Metricbeat: lighweight shipper collect metrics from OS, Services such as Apache, HAProxy, MongoDB, Nginx, ...
Mô hình Beats Platform
Ở bài này tôi sẽ chỉ cấu hình filebeat dựa trên mục đích của tôi muốn thu thập log từ các file log trên các server khác nhau.
FileBeat làm việc thế nào
Khi khởi động filebeat, nó sẽ khởi chạy một hay nhiều prospector, sẽ tìm kiếm các đường dẫn của tập tin tin mà ta đã khai báo. Với mỗi môt tập tin log mà prospector tìm thấy được, Filebeat sẽ khởi chạy một harvester. Mỗi một harvester đọc một tập tin log, và gửi các bản tin log này khi có dữ liệu mới tới spooler. Spooler là nơi tổng hợp các sự kiện và gửi dữ liệu đã tổng hợp được tới output mà ta đã cấu hình trên Filebeat.
Cấu trúc bên trong Filebeat
Cài đặt và cấu hình
Tôi sẽ thực hiện trên Ubuntu Server 14.04
Tải và thêm GPG key
curl https://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -  
Thêm repository chưa filebeat
echo "deb https://packages.elastic.co/beats/apt stable main" |  
a /etc/apt/sources.list.d/beats.list  
Cập nhật Repository và cài đặt filebeat
sudo apt-get update && sudo apt-get install -y filebeat  
Cấu hình filebeat khởi chạy cùng hệ thống
sudo update-rc.d filebeat defaults  
Thực hiện câu hình cho filebeat đọc các file log. Dùng trình soạn thảo để mở tập
tin cấu hình của filebeat ở đường dẫn “/etc/filebeat/filebeat.yml”
Định nghĩa các đường dẫn tới tập tin log.
Một cấu hình cơ bản của Filebeat là sử dụng một prospector cho một đường dẫn.
Prospectors trong ví dụ này sẽ tìm kiếm tât cả các tập tin trong đường dẫn
“/var/log” và các tập tin có phần mở rộng là “.log” - Cấu hình output cho filebeat.
Nếu ta muốn sử dụng Logstash làm nơi phân tách các thông điệp thì ở mục output trong tập tin cấu hình Filebeat ta sẽ khai báo địa chỉ IP và port của Logstash. Lưu ý port này sẽ trùng với port mà ta sẽ mở trên logstash.
Nếu ta muốn filebeat gửi tới elascticsearch luôn thì ta có thể cấu hình trong mục elasticsearch như sau:
Ở bài này tôi sẽ sử dụng logstash để thực hiện bóc tách thông điệp. Do vậy tôi sẽ cấu hình gửi tới logstash. Lúc này trên Logstash ta cần cấu hình input để filebeat có thể kết nối vào và gửi dữ liệu tới.
Trên máy chủ cài đặt logstash, mở tập tin cấu hình của logstash trong thư mục “/etc/logstash/conf.d”. Thêm vào phần input như sau:
Khởi động lại logstash trên máy chủ cài đặt logstash.
service logstash restart  
Khởi động lại filebeat trên máy remote
service filebeat restart  
Truy cập vào kibana lúc này ta sẽ thấy dữ liệu từ filebeat trả về như sau:

Comments

Popular posts from this blog

Zabbix, AWS and Auto Registration

One of the things I love the most with AWS is  auto-scaling . You choose an AMI, set some parameters and AWS will spin instances up and down whenever a threshold is breached. But with all these instances spinning up and down there are some unknowns. For example, what is the IP address of the new instance? Its host name? This can be critical when other components of your infrastructure are dependent on knowing these parameters. I had this problem when I started to use  Zabbix  as the monitoring system. At first it seemed like a complicated one, but Zabbix has a wonderful feature called  Auto Registration  which can be used exactly for this situation. I will try to show how to configure auto registration both on the client (EC2 instance running Ubuntu 14.04) and on the Zabbix server (Zabbix Server 2.4.2). Zabbix-agent Installation and Configuration Let’s start with installing zabbix-agent on the Ubuntu client: 1 2 $ sudo apt-get update $ sud...

Merge AVHDX Hyper-V Checkpoints

When you create a snapshot of a virtual machine in Microsoft Hyper-V, a new file is created with the  .avhdx  file extension. The name of the file begins with the name of its parent VHDX file, but it also has a GUID following that, uniquely representing that checkpoint (sometimes called snapshots). You can see an example of this in the Windows Explorer screenshot below. Creating lots of snapshots will result in many  .avhdx  files, which can quickly become unmanageable. Consequently, you might want to merge these files together. If you want to merge the  .avhdx  file with its parent  .vhdx  file, it’s quite easy to accomplish. PowerShell Method Windows 10 includes support for a  Merge-VHD  PowerShell command, which is incredibly easy to use. In fact, you don’t even need to be running PowerShell “as Administrator” in order to merge VHDX files that you have access to. All you need to do is call  Merge-VHD  with the...

SIPp cheatsheet

SIPp  is a free test tool and traffic generator for the SIP protocol. It uses XML format files to define test scenarios. General usage: sipp remote_host[:remote_port] [options] Some important command-line options: -sf filename Load test scenario from specified file. -inf filename Use CSV file to insert data substituted for [field0], [field1], etc into XML scenario. First line of file describes order of inserting field sets (SEQUENTIAL/RANDOM/USE). -sn name Use one of the embedded, predefined scenarios like "uac", "uas". -r rate Scenario execution rate, default value = 10 times per period, default period = 1000 ms. -rp period Scenario execution period [ms], combined with execution rate. Execution rate is combined of rate and period parameters, i.e. if period = 3500 and rate = 7 there will be 7 calls in 3.5 s. -t transport mode Set the transport mode: "u1" - UDP, one socket (default), "un" - UDP, one socket per call, other modes (...