NGINX is a widely-used high-performance web server. Developers need to monitor the stability of the server. To better monitor and optimize the performance and security of the NGINX server, you can use a Fleet agent to collect NGINX log data and use the Fleet server provided by Kibana to manage the collected data. You can use the Fleet server to transfer the collected data to Kibana for visualized analysis. This topic describes how to use the Fleet server to manage NGINX log data that is collected from two Elastic Compute Service (ECS) instances based on the same agent policy.
Terms
Term | Description |
Fleet | Fleet is a powerful solution provided by Elasticsearch to manage Fleet agents in a centralized manner. |
Fleet agent | A Fleet agent is a lightweight data collection agent that is used to collect data from a source. A Fleet agent can run on different types of operating systems and collect multiple types of data. |
Fleet server | The Fleet server is used to transfer data that is collected by a Fleet agent from a source to Elasticsearch. |
Prepare environments
Create an Alibaba Cloud Elasticsearch cluster. For more information, see Create an Alibaba Cloud Elasticsearch cluster. In this example, an Alibaba Cloud Elasticsearch V8.5 cluster is created.
NoteThe version of the Alibaba Cloud Elasticsearch cluster must be V7.10 or a later version other than V7.16.
Create two ECS instances. For more information, see Create an instance by using the wizard.
The ECS instances must reside in the same virtual private cloud (VPC) as the Elasticsearch cluster.
You must associate elastic IP addresses (EIPs) with the ECS instances. For more information, see Associate or disassociate an EIP.
NoteThe ECS instances are used as the source servers. A Fleet agent collects NGINX log data from the ECS instances.
Create an agent policy and add integrations
Step 1: Create an agent policy
Log on to the Kibana console of the Elasticsearch cluster. For more information, see Log on to the Kibana console.
Click the icon in the upper-left corner. In the left-side navigation pane, choose
.On the Fleet page, click the Agent policies tab.
Click Create agent policy. In the Create agent policy panel, configure the agent policy.
Enter the name nginx-log in the Name field.
Clear Collect system logs and metrics.
Click Advanced options. In the Agent monitoring section, clear Collect agent logs and Collect agent metrics.
NoteIn this example, only NGINX log data is collected. Therefore, Collect system logs and metrics, Collect agent logs, and Collect agent metrics do not need to be selected.
Click Create agent policy.
Step 2: Add a Fleet server integration
On the Agent policies tab of the Fleet page, find the nginx-log agent policy and click its name.
On the Integrations tab of the page that appears, click Add integration.
On the Browse integrations tab of the Integrations page, enter Fleet Server in the search box. Then, click the Fleet Server card that is displayed.
Install the Fleet server integration.
On the Fleet Server page, click the Settings tab.
Click Install Fleet Server assets. In the Install Fleet Server message, click Install Fleet Server.
NoteAfter the integration is installed, the version of the integration is displayed on the Settings tab of the Fleet Server page.
In the upper-right corner of the Fleet Server page, click Add Fleet Server.
In the Configure integration section of the Add Fleet Server integration page, enter a name for the integration in the Integration name field. On the Existing hosts tab of the Where to add this integration section of the same page, retain the default value
nginx-log
for the Agent policy parameter.In the lower-right corner of the Add Fleet Server integration page, click Save and continue. In the Fleet Server integration added message, click Add Elastic Agent later.
Step 3: Add an NGINX integration
On the Integrations tab of the nginx-log agent policy, click Add integration.
On the Browse integrations tab of the Integrations page, enter Nginx in the search box. Then, click the Nginx card that is displayed.
Install the NGINX integration.
On the Nginx page, click the Settings tab.
Click Install Nginx assets. In the Install Nginx message, click Install Nginx.
NoteAfter the integration is installed, the version of the integration is displayed on the Settings tab of the Nginx page.
In the upper-right corner of the Nginx page, click Add Nginx.
On the Add Nginx integration page, configure the integration.
In the Configure integration section, retain the default value nginx-1 in the Integration name field.
Click Change defaults next to Collect logs from Nginx instances. Enter a path in the Paths field based on your business requirements.
On the Existing hosts tab of the Where to add this integration section, select
nginx-log
from the Agent policy drop-down list.
In the lower-right corner of the Add Nginx integration page, click Save and continue. In the Nginx integration added message, click Add Elastic Agent later.
Add a Fleet agent
Step 1: Configure a host for the Fleet server
Click the icon in the upper-left corner. In the left-side navigation pane, choose
.On the Fleet page, click the Settings tab. On the Settings tab, configure parameters for Fleet.
In the Fleet server hosts section, click Edit hosts.
In the Fleet Server hosts panel, enter the URL of the source from which you want to collect data in the Specify host URL field. The URL must be in the
https://<Private IP address of the source>:<Port number>
format, such ashttps://172.16.*.***:8220
. Then, click Save and apply settings. In the Save and deploy changes message, click Save and deploy.NoteIn this example, a URL that contains the primary private IP address of one of the ECS instances is entered. For more information about the configurations, see Fleet Server hosts.
In the Outputs section of the Fleet page, click the icon in the Actions column.
In the Edit output panel, enter the URL of the Elasticsearch cluster in the Hosts field. The URL must be in the
http://<Internal endpoint of the Elasticsearch cluster>:<Port number>
format, such ashttp://es-cn-uqm3auln80001****.elasticsearch.aliyuncs.com:9200
.Click Save and apply settings. In the Save and deploy changes message, click Save and deploy.
Step 2: Add a Fleet agent
On the Fleet page, click the Agent policies tab.
Find the nginx-log agent policy, click the icon in the Actions column, and then select Add agent.
On the Enroll in Fleet tab of the Add agent panel, click Add Fleet Server. In the Add a Fleet Server panel, click Advanced. In the Select a policy for Fleet Server section, retain the default value
nginx-log
.In the Choose a deployment mode for security section, retain the default value Quick start.
In the Add your Fleet Server host section, click Add host.
In the Generate a service token section, click Generate service token.
In the Install Fleet Server to a centralized host section, copy the code that is automatically generated and run the code in one of the ECS instances.
If
Successfully
is displayed after you run the code, the Fleet agent is installed on the ECS instance and is started.Repeat the preceding substeps to add a Fleet agent for the other ECS instance.
View the collected data
You can use one of the following methods to view the collected NGINX log data:
Method 1: View the collected NGINX log data on the View Dashboards page
Click the icon in the upper-left corner. In the left-side navigation pane, choose
.On the Fleet page, click the Data streams tab. On the Data streams tab, you can view the collected NGINX log data in the dataset list.
Find the desired dataset, click the icon in the Actions column, and then select View Dashboards. On the page that appears, you can select the item whose information you want to view. For example, you can select
[Metrics Nginx] Overview
and view information about it.
Method 2: View the collected NGINX log data in the destination index on the Discover page
Click the icon in the upper-left corner. In the left-side navigation pane, choose
.In the upper-left corner of the Discover page, select a data view. For example, you can select
metrics-*
.
Method 3: Query the collected NGINX log data by running a command on the Console tab
Click the icon in the upper-left corner. In the left-side navigation pane, choose
.On the Console tab, run the following commands to query the collected NGINX log data:
GET logs-nginx.access-*/_search GET logs-nginx.error-*/_search