1-ELK安装及使用教程(搭建日志分析系统)

1、Logstash使用

Logstash是一个完全开源的工具,他可以对你的日志进行收集、分析,并将其存储供以后使用。

1.1 Logstash安装(JDK 1.8环境下)

下载Logstash 2.3.4,并解压。

1.2 Logstash配置

配置logstash.conf

input {
    file {
        type => "log-file"
        path => "/root/test/log/log.log"
    }
 }
output {
    stdout { 
            codec => rubydebug  
    }
}

其中input为Logstash的输入源,当前配置是监控root/test/log/log.log文件,并将该日志类型置为log-file
其中output为Logstash的输出源,当前配置为直接输出到终端。

1.3 Logstash启动

./bin/logstash -f logstash.conf

1.4 Logstash使用

  • 首先启动Logstash服务
  • 启动打印日志的程序,并将日志输出到root/test/log/log.log
  • 观察Logstash终端的输出,可以看到Logstash抓取到了监控路径下的日志,并进行处理和输出。
{
       "message" => "[INFO][uid:1491031249][name:Gloria Harrison][ip:36.59.236.198][date:2017-04-01T15:20:49.703+0800]",
      "@version" => "1",
    "@timestamp" => "2017-04-01T07:20:50.644Z",
          "path" => "/root/test/log/log.log",
          "host" => "0.0.0.0",
          "type" => "log-file"
}
{
       "message" => "[INFO][uid:14910312497][name:Ralph Martinez][ip:36.58.103.37][date:2017-04-01T15:20:49.704+0800]",
      "@version" => "1",
    "@timestamp" => "2017-04-01T07:20:50.645Z",
          "path" => "/root/test/log/log.log",
          "host" => "0.0.0.0",
          "type" => "log-file"
}

2、Elasticsearch使用

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

2.1 Elasticsearch安装(JDK 1.8环境下)

下载elasticsearch 2.3.4,并解压。

2.2 Elasticsearch配置

配置config/elasticsearch.yml

# host设置
network.host: 172.17.203.210

2.3 Elasticsearch常用插件安装

  • head :是集群管理工具、数据可视化、增删改查工具。
# 安装命令
./bin/plugin install mobz/elasticsearch-head

访问路径:http://localhost:9200/_plugin/head/
- kopf:是一个ElasticSearch的管理工具,它也提供了对ES集群操作的API。

# 安装命令
./bin/plugin install lmenezes/elasticsearch-kopf

访问路径:http://localhost:9200/_plugin/kopf/
- hq:对于ElasticSearch实例和集群进行监视和管理Web应用程序。

# 安装命令
./bin/plugin install royrusso/elasticsearch-HQ

访问路径:http://localhost:9200/_plugin/hq/

2.4 Elasticsearch启动

./bin/elasticsearch -d -p pid

2.5 Elasticsearch使用

  • HQ插件

3、Kibana使用

Kibana 也是一个开源和免费的工具,他可以帮助您汇总、分析和搜索重要数据日志并提供友好的web界面。他可以为 Logstash 和 ElasticSearch 提供的日志分析的 Web 界面。

logstash index将日志收集在一起交给全文搜索服务ElasticSearch,可以用ElasticSearch进行自定义搜索,通过Kibana 来结合自定义搜索进行页面展示。

3.1 Kibana安装(JDK 1.8环境)

下载kibana 4.5.2,并解压。

3.2 Kibana配置

# Kibana is served by a back end server. This controls which port to use. Web界面的端口号

port: 5601

# The host to bind the server to. Web访问的host

host: "127.0.0.1"

# The Elasticsearch instance to use for all your queries. ES的访问路径

elasticsearch_url: elasticsearch.url: "http://127.0.0.1:9200"

3.3 Kibana启动

nohup ./bin/kibana &

3.4 Kibana使用

3.4.1 访问Kibana地址

127.0.0.1:5601

3.4.2 创建index pattern

  • Index contains time-based events:ES索引带有时间列
  • Use event times to create index names
    如果这2个都不选的情况下,可以直接添加ES的索引名字。

Kibana展示


版权声明:本文为f59130原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>