Ask Làm thế nào để sử dụng EFK?

thanhnhaletuong

New member
## Làm thế nào để sử dụng EFK?

EFK là viết tắt của Elaticsearch, Fluentd và Kibana.Đây là một ngăn xếp ghi nhật ký phổ biến có thể được sử dụng để thu thập, lưu trữ và phân tích nhật ký từ các ứng dụng của bạn.Trong bài viết này, chúng tôi sẽ chỉ cho bạn cách sử dụng EFK để thu thập nhật ký từ cụm Kubernetes.

### Điều kiện tiên quyết

Để làm theo với hướng dẫn này, bạn sẽ cần những điều sau đây:

* Một cụm kubernetes
* [Biểu đồ Helm Helm] (https://github.com/elastic/helm-parts/tree/master/elaticsearch)
* [Biểu đồ Helm Fluentd] (https://github.com/fluent/fluentd-helm/tree/master/charts/fluentd)
* [Biểu đồ Helm Helm] (https://github.com/elastic/helm-parts/tree/master/kibana)

### Cài đặt EFK

Để cài đặt EFK trên cụm Kubernetes của bạn, bạn có thể sử dụng các lệnh Helm sau:

`` `
Helm Cài đặt Elasticsearch co giãn/elasticsearch
Helm Cài đặt Fluentd Fluent/Fluentd
Helm Cài đặt Kibana đàn hồi/Kibana
`` `

Các lệnh này sẽ cài đặt các phiên bản mới nhất của Elaticsearch, Fluentd và Kibana trên cụm của bạn.

### Cấu hình EFK

Khi EFK được cài đặt, bạn sẽ cần định cấu hình nó để thu thập nhật ký từ các ứng dụng của bạn.Để làm điều này, bạn sẽ cần tạo một tệp cấu hình trôi chảy.Dưới đây là một ví dụ về tệp cấu hình thông thạo mà bạn có thể sử dụng:

`` `
<Nguồn>
Loại đuôi
đường dẫn /var/log/containers/*.log
Thực hiện theo sự thật
Tail_lines 10
</Nguồn>

<Bộ lọc **>
Nhập Kubernetes
Kubernetes_host localhost: 8080
Ứng dụng Kubernetes_Match_Labels = My-App
</Filter>

<khớp **>
Nhập bản sao
<Cửa hàng>
Loại elaticsearch
Elaticsearch_host Elaticsearch-Master: 9200
elaticsearch_index my-app-logs
</Store>
<Cửa hàng>
Nhập stdout
</Store>
</Match>
`` `

Tệp cấu hình này sẽ thu thập nhật ký từ tất cả các container trong không gian tên `My-app` và gửi chúng đến Elaticsearch.

### Kiểm tra EFK

Khi bạn đã cấu hình EFK, bạn có thể kiểm tra nó bằng cách tạo một tệp nhật ký trong một trong các ứng dụng của bạn.Ví dụ: bạn có thể chạy lệnh sau để tạo tệp nhật ký trong không gian tên `my-app`:

`` `
Echo "Hello World" >> /var/log/containers/my-app-pod-1.log
`` `

Khi bạn đã tạo tệp nhật ký, bạn có thể kiểm tra Elaticsearch để xem liệu thông báo nhật ký có nhận được không.Bạn có thể làm điều này bằng cách chạy lệnh sau:

`` `
Curl LocalHost: 9200/My-App-Logs/_Search? Pretty = true
`` `

Lệnh này sẽ trả về một danh sách tất cả các thông báo nhật ký đã được thu thập cho chỉ mục `my-apps-logs`.Bạn sẽ thấy thông báo nhật ký mà bạn đã tạo trước đó trong danh sách.

### Sử dụng EFK

Bây giờ bạn đã cài đặt và cấu hình EFK, bạn có thể sử dụng nó để thu thập, lưu trữ và phân tích nhật ký từ các ứng dụng của bạn.Bạn có thể sử dụng bảng điều khiển web Elaticsearch và Kibana để xem và tìm kiếm nhật ký của bạn.Bạn cũng có thể sử dụng API Elaticsearch để truy cập vào nhật ký của bạn.

### Tài nguyên

* [Tài liệu elaticsearch] (https://www.elastic.co/guide/en/elasticsearch/reference/civerse/index.html)
* [Tài liệu Fluentd] (https://www.fluentd.org/docs/)
* [Tài liệu Kibana] (https://www.elastic.co/guide/en/kibana/civerse/index.html)

## hashtags

* #elk
* #Logging
* #Kubernetes
* #giám sát
* #ObServability
=======================================
## How to Use EFK?

EFK stands for Elasticsearch, Fluentd, and Kibana. It is a popular logging stack that can be used to collect, store, and analyze logs from your applications. In this article, we will show you how to use EFK to collect logs from a Kubernetes cluster.

### Prerequisites

To follow along with this tutorial, you will need the following:

* A Kubernetes cluster
* The [Elasticsearch Helm chart](https://github.com/elastic/helm-charts/tree/master/elasticsearch)
* The [Fluentd Helm chart](https://github.com/fluent/fluentd-helm/tree/master/charts/fluentd)
* The [Kibana Helm chart](https://github.com/elastic/helm-charts/tree/master/kibana)

### Installing EFK

To install EFK on your Kubernetes cluster, you can use the following Helm commands:

```
helm install elasticsearch elastic/elasticsearch
helm install fluentd fluent/fluentd
helm install kibana elastic/kibana
```

These commands will install the latest versions of Elasticsearch, Fluentd, and Kibana on your cluster.

### Configuring EFK

Once EFK is installed, you will need to configure it to collect logs from your applications. To do this, you will need to create a Fluentd configuration file. Here is an example of a Fluentd configuration file that you can use:

```
<source>
type tail
path /var/log/containers/*.log
follow true
tail_lines 10
</source>

<filter **>
type kubernetes
kubernetes_host localhost:8080
kubernetes_match_labels app=my-app
</filter>

<match **>
type copy
<store>
type elasticsearch
elasticsearch_host elasticsearch-master:9200
elasticsearch_index my-app-logs
</store>
<store>
type stdout
</store>
</match>
```

This configuration file will collect logs from all of the containers in the `my-app` namespace and send them to Elasticsearch.

### Testing EFK

Once you have configured EFK, you can test it by creating a log file in one of your applications. For example, you could run the following command to create a log file in the `my-app` namespace:

```
echo "Hello world" >> /var/log/containers/my-app-pod-1.log
```

Once you have created the log file, you can check Elasticsearch to see if the log message was received. You can do this by running the following command:

```
curl localhost:9200/my-app-logs/_search?pretty=true
```

This command will return a list of all of the log messages that have been collected for the `my-app-logs` index. You should see the log message that you created earlier in the list.

### Using EFK

Now that you have EFK installed and configured, you can use it to collect, store, and analyze logs from your applications. You can use the Elasticsearch and Kibana web consoles to view and search your logs. You can also use the Elasticsearch API to programmatically access your logs.

### Resources

* [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)
* [Fluentd documentation](https://www.fluentd.org/docs/)
* [Kibana documentation](https://www.elastic.co/guide/en/kibana/current/index.html)

## Hashtags

* #elk
* #Logging
* #Kubernetes
* #monitoring
* #ObServability
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock