Home>Article>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?
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
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.2-linux-x86_64.tar.gz
(2) Unzip and install Package:
tar -zxvf elasticsearch-7.15.2-linux-x86_64.tar.gz
(3) Run Elasticsearch:
cd elasticsearch-7.15.2/bin ./elasticsearch
(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" }
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.15.2.tar.gz
(2) Unzip the installation package:
tar -zxvf logstash-7.15.2.tar.gz
(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 } }
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
Note: The configuration information of logstash.conf needs to be modified according to the actual situation.
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.15.2-linux-x86_64.tar.gz
(2) Unzip the installation package:
tar -zxvf kibana-7.15.2-linux-x86_64.tar.gz
(3 ) Modify the config/kibana.yml file and set the address of Elasticsearch:
elasticsearch.hosts: ["http://localhost:9200"]
(4) Run Kibana:
cd kibana-7.15.2/bin ./kibana
(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.
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!