Home Operation and Maintenance Linux Operation and Maintenance How to use ELK Stack for log analysis in Linux environment?

How to use ELK Stack for log analysis in Linux environment?

Jul 29, 2023 pm 04:53 PM
linux Log analysis elk stack

How to use ELK Stack for log analysis in Linux environment?

1. Introduction to ELK Stack
ELK Stack is a log analysis platform composed of three open source software Elasticsearch, Logstash and Kibana. Elasticsearch is a distributed real-time search and analysis engine, Logstash is a tool for collecting, processing and forwarding logs, and Kibana is an interface for visualizing and analyzing logs.

2. Install ELK Stack

  1. Install Elasticsearch
    (1) Download the latest version of Elasticsearch:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.2-linux-x86_64.tar.gz
Copy after login

(2) Unzip and install Package:

tar -zxvf elasticsearch-7.15.2-linux-x86_64.tar.gz
Copy after login

(3) Run Elasticsearch:

cd elasticsearch-7.15.2/bin
./elasticsearch
Copy after login

(4) Verify that Elasticsearch is running normally, visit http://localhost:9200 in the browser, if the following information is returned, it means installation Success:

{
  "name" : "xxxx",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "xxxx",
  "version" : {
    "number" : "7.15.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "xxxx",
    "build_date" : "xxxx",
    "build_snapshot" : false,
    "lucene_version" : "xxxx",
    "minimum_wire_compatibility_version" : "xxxx",
    "minimum_index_compatibility_version" : "xxxx"
  },
  "tagline" : "You Know, for Search"
}
Copy after login
  1. Install Logstash
    (1) Download the latest version of Logstash:
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.15.2.tar.gz
Copy after login

(2) Unzip the installation package:

tar -zxvf logstash-7.15.2.tar.gz
Copy after login

(3) Create a Logstash configuration file, such as logstash.conf:

input {
  file {
    path => "/var/log/nginx/access.log"
    start_position => "beginning"
  }
}

filter {
  grok {
    match => { "message" => "%{COMBINEDAPACHELOG}" }
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "nginx-access-log"
  }
  stdout { codec => rubydebug }
}
Copy after login

The above configuration file specifies the input log path, uses Grok mode to match the log format, sends the processed log to Elasticsearch, and passes The stdout plugin outputs debugging information to the terminal.

(4) Run Logstash:

cd logstash-7.15.2/bin
./logstash -f logstash.conf
Copy after login

Note: The configuration information of logstash.conf needs to be modified according to the actual situation.

  1. Install Kibana
    (1) Download the latest version of Kibana:
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.15.2-linux-x86_64.tar.gz
Copy after login

(2) Unzip the installation package:

tar -zxvf kibana-7.15.2-linux-x86_64.tar.gz
Copy after login

(3 ) Modify the config/kibana.yml file and set the address of Elasticsearch:

elasticsearch.hosts: ["http://localhost:9200"]
Copy after login

(4) Run Kibana:

cd kibana-7.15.2/bin
./kibana
Copy after login

(5) Visit http://localhost:5601 in the browser, If you can see the Kibana interface, the installation is successful.

3. Use ELK Stack for log analysis
After the ELK Stack is installed, you can start log analysis.

  1. Collect logs
    In the Logstash configuration file, you can configure logs from multiple sources, such as files, networks, etc. Modify the Logstash configuration file, specify the correct log source, and format it accordingly.
  2. Processing and forwarding logs
    Logstash is a powerful log processing tool that can process and forward logs through built-in plug-ins. In the filter section of the configuration file, you can use a series of plug-ins to parse, filter and format logs.
  3. Storing and Indexing Logs
    In the output section of the Logstash configuration file, you can configure the storage and indexing methods of logs. Elasticsearch is a distributed search engine that can quickly store and retrieve large amounts of data. You can store the processed logs in the corresponding index by configuring the hosts and index parameters of Elasticsearch.
  4. Visualizing and analyzing logs
    Kibana is the visualization tool of ELK Stack. It provides rich charts and dashboards to display and analyze log data. In Kibana, various charts and reports can be customized to meet different needs by creating index patterns, visualizations, and dashboards.

4. Summary
ELK Stack is a powerful and flexible log analysis platform that can help us collect, process, store, visualize and analyze log data. It only takes a few simple steps to install and configure ELK Stack in a Linux environment, and then you can perform log analysis according to actual needs. In this way, we can better understand and utilize log data to optimize system performance, identify potential problems, and improve user experience.

The above is the detailed content of How to use ELK Stack for log analysis in Linux environment?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

See all articles