centos7 installs ELK for log collection (elasticsearch,logstash,kibana)

Needless to say, you've heard about elk more or less. Recently, I've set up a collection of logs for your reference:

1. Install elasticsearch,logstash,kibana

It is strongly recommended to install the official installation to es:
Today is 2019.4.9. The latest version is 6.7.1. All three are packed with version 6.7.1 (the versions should be the same, otherwise there will be various complications)
elasticsearch: https://www.elastic.co/downlo...
logstash: https://www.elastic.co/cn/dow...
kibana:https://www.elastic.co/cn/dow...

One of the installation tutorials for es I wrote in this article: https://segmentfault.com/a/11... , the following describes the installation of logstash and kibana

1.logstash:
After downloading

##Enter the directory where the package is located and unzip
tar -xf logstash-6.7.1.tar.gz
##Switch to the bin directory
cd /logstash-6.7.1/bin
##Edit or create a startup profile to start with
vim input_flter_output.conf

input {
   file{
       path=> "/crawler/jenkins/*.log"    ##Directory where logs are generated
       type=> "cml"          ##Type of index
       start_position=> "beginning"     ##Enter the original log information at the beginning
  }
  stdin{}
}
filter{
 
}
output{
       elasticsearch{
       action=> "index"
       hosts=> "www.iamcrawler.cn:9500"      ##Output to elasticsearch
       index=> "log-%{+yyyy.MM.dd}"     ##Generate a log-time index
       }
}
   #Save Last Exit
   ##Write another startup bat in the bin directory
   vim run.bat
   sh logstash -f input_flter_output.conf  &
    #Save Last Exit
   //Then run.bat
   [root@iamcrawler bin]# sh run.bat
   ##The following situations normally occur:
    [root@iamcrawler bin]# Sending Logstash logs to /crawler/logstash/logstash-6.7.1/logs which is now configured via log4j2.properties
    [2019-04-09T13:11:40,120][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
    [2019-04-09T13:11:40,138][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.7.1"}
    [2019-04-09T13:11:50,041][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
    [2019-04-09T13:11:50,697][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://www.iamcrawler.cn:9500/]}}
    [2019-04-09T13:11:51,065][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://www.iamcrawler.cn:9500/"}
    [2019-04-09T13:11:51,191][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
    [2019-04-09T13:11:51,196][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
    [2019-04-09T13:11:51,232][INFO ][logstash.outputs.elasticsearch] Using default mapping template
    [2019-04-09T13:11:51,253][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//www.iamcrawler.cn:9500"]}
    [2019-04-09T13:11:51,287][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
    [2019-04-09T13:11:51,399][INFO ][logstash.outputs.elasticsearch] Installing elasticsearch template to _template/logstash
    [2019-04-09T13:11:51,783][INFO ][logstash.inputs.file     ] No sincedb_path set, generating one based on the "path" setting {:sincedb_path=>"/crawler/logstash/logstash-6.7.1/data/plugins/inputs/file/.sincedb_6677650ec826fa62a735f6625357dead", :path=>["/crawler/jenkins/*.log"]}
    [2019-04-09T13:11:51,896][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x729fdee9 run>"}
    [2019-04-09T13:11:52,010][INFO ][filewatch.observingtail  ] START, creating Discoverer, Watch with file and sincedb collections
    [2019-04-09T13:11:52,033][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
    [2019-04-09T13:11:52,723][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
   

2. Installation of kibana
kibana is easy to install. After downloading, go to the config directory of the installation directory, such as:
cd /crawler/kibana/kibana-6.7.1-linux-x86_64/config

vim kibana.yml
##Add the following command
server.host: 0.0.0.0
elasticsearch.url: "http://localhost:9500 "#Here is the http address of es
##Enter the kibana directory, execute the following command, and run kibana in the background
./bin/kibana &

2. kibana can be used in many online tutorials, which are not described too much here

Tags: Linux ElasticSearch vim jenkins less

Posted on Fri, 29 Nov 2019 20:08:09 -0800 by keevitaja