ELK(elasticsearch+logstash+kibana)开源日志分析平台搭建

本文涉及的产品
Elasticsearch Serverless通用抵扣包,测试体验金 200元
日志服务 SLS,月写入数据量 50GB 1个月
简介:

环境介绍


System:   CentOS7.2 x86_64

hostname: elk-server.huangming.org

IP Address: 10.0.6.42、10.17.83.42


本篇的ELK环境为单机部署方式,即将ELK所有的软件包都安装在一台服务器上,配置如下:

CPU:   4c

Mem:   8G

Disk:  50


一、Elasticsearch安装


1、安装jdk 1.8及以上的版本(安装过程略)

1
2
3
4
[root@elk-server elk] # java -version
java version  "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)


2、下载Elasticsearch最新版本(目前5.5版本)

1
2
3
4
使用curl命令下载 tar
# curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
也可以使用wget命令下载
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz


3、解压至指定目录(安装目录)/usr/local/下,并将其重命名为elasticsearch (完整的目录应该为/usr/local/elasticsearch)

1
2
3
# tar -zxf elasticsearch-5.5.2.tar.gz -C /usr/local/
# cd /usr/local/
# mv elasticsearch-5.5.2 elasticsearch


2、创建一个用于运行elasticsearch的普通用户,随后修改elasticsearch家目录的所属权限为该用户;创建elasticsearch数据存储目录/data/elasticsearch

1
2
3
4
5
# groupadd elasticsearch
# useradd -g elasticsearch elasticsearch -m
# chown -R elasticsearch. /usr/local/elasticsearch
# mkdir /data/elasticsearch
# chown -R elasticsearch. /data/elasticsearch


2、修改elasticsearch.yml配置文件

1
2
3
4
5
6
# vim config/elasticsearch.yml
cluster.name: my-application         #ELK集群名称
path.data:  /data/elasticsearch       #elasticsearch 数据存储目录
path.logs:  /usr/local/elasticsearch/logs    #elasticsearch 日志存储路径
network.host: 10.17.83.42            #elasticsearch 监听地址,默认为localhost
http.port: 9200                      #elasticsearch 监听端口,默认问9200


6、修改相关的内核参数


打开/etc/security/limits.conf文件,添加以下参数

1
2
3
4
*        soft    nproc           2048
*        hard    nproc           16384
*        soft    nofile          65536
*        hard    nofile          65536


修改vm.max_map_count=262144

1
# echo "/etc/sysctl.conf" >> /etc/sysctl.conf


7、运行elasticsearch (注意:要切换到普通用户运行)


# su - elasticsearch

$ ./bin/elasticsearch


运行elasticsearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[elasticsearch@elk-server ~]$  cd  /usr/local/elasticsearch/
[elasticsearch@elk-server elasticsearch]$ . /bin/elasticsearch
[2017-08-28T14:51:31,069][INFO ][o.e.n.Node               ] [] initializing ...
[2017-08-28T14:51:31,186][INFO ][o.e.e.NodeEnvironment    ] [6eN59Pf] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [89.4gb], net total_space [91.4gb], spins? [unknown], types [rootfs]
[2017-08-28T14:51:31,187][INFO ][o.e.e.NodeEnvironment    ] [6eN59Pf] heap size [1.9gb], compressed ordinary object pointers [ true ]
[2017-08-28T14:51:31,188][INFO ][o.e.n.Node               ] node name [6eN59Pf] derived from node ID [6eN59PfuS7iVRfoEppsngg];  set  [node.name] to override
[2017-08-28T14:51:31,189][INFO ][o.e.n.Node               ] version[5.5.2], pid[2759], build[b2f0c09 /2017-08-14T12 :33:14.154Z], OS[Linux /3 .10.0-327.el7.x86_64 /amd64 ], JVM[Oracle Corporation /Java  HotSpot(TM) 64-Bit Server VM /1 .8.0_65 /25 .65-b01]
[2017-08-28T14:51:31,189][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless= true , -Dfile.encoding=UTF-8, -Djna.nosys= true , -Djdk.io.permissionsUseCanonicalPath= true , -Dio.netty.noUnsafe= true , -Dio.netty.noKeySetOptimization= true , -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled= false , -Dlog4j2.disable.jmx= true , -Dlog4j.skipJansi= true , -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home= /usr/local/elasticsearch ]
[2017-08-28T14:51:32,174][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [aggs-matrix-stats]
[2017-08-28T14:51:32,174][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [ingest-common]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [lang-expression]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [lang-groovy]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [lang-mustache]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [lang-painless]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [parent- join ]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [percolator]
[2017-08-28T14:51:32,175][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [reindex]
[2017-08-28T14:51:32,176][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [transport-netty3]
[2017-08-28T14:51:32,176][INFO ][o.e.p.PluginsService     ] [6eN59Pf] loaded module [transport-netty4]
[2017-08-28T14:51:32,176][INFO ][o.e.p.PluginsService     ] [6eN59Pf] no plugins loaded
[2017-08-28T14:51:33,991][INFO ][o.e.d.DiscoveryModule    ] [6eN59Pf] using discovery  type  [zen]
[2017-08-28T14:51:34,576][INFO ][o.e.n.Node               ] initialized
[2017-08-28T14:51:34,577][INFO ][o.e.n.Node               ] [6eN59Pf] starting ...
[2017-08-28T14:51:34,814][INFO ][o.e.t.TransportService   ] [6eN59Pf] publish_address {10.17.83.42:9300}, bound_addresses {10.17.83.42:9300}
[2017-08-28T14:51:34,826][INFO ][o.e.b.BootstrapChecks    ] [6eN59Pf] bound or publishing to a non-loopback or non-link- local  address, enforcing bootstrap checks
[2017-08-28T14:51:37,883][INFO ][o.e.c.s.ClusterService   ] [6eN59Pf] new_master {6eN59Pf}{6eN59PfuS7iVRfoEppsngg}{hs82h4vkTwKCEvKybCodbw}{10.17.83.42}{10.17.83.42:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-08-28T14:51:37,900][INFO ][o.e.h.n.Netty4HttpServerTransport] [6eN59Pf] publish_address {10.17.83.42:9200}, bound_addresses {10.17.83.42:9200}
[2017-08-28T14:51:37,900][INFO ][o.e.n.Node               ] [6eN59Pf] started
[2017-08-28T14:51:37,925][INFO ][o.e.g.GatewayService     ] [6eN59Pf] recovered [0] indices into cluster_state
[2017-08-28T14:51:43,485][INFO ][o.e.c.m.MetaDataCreateIndexService] [6eN59Pf] [.kibana] creating index, cause [api], templates [], shards [1]/[1], mappings [_default_, index-pattern, server, visualization, search, timelion-sheet, config, dashboard, url]



一般情况我们要求elasticsearch在后台运行,使用命令如下:

1
$ . /bin/elasticsearch  -d


8、检查elasticsearch状态,如下则表示正常运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@elk-server elasticsearch] # curl http://10.17.83.42:9200
{
   "name"  "6eN59Pf" ,
   "cluster_name"  "my-application" ,
   "cluster_uuid"  "cKopwE1iTciIQAiFI6d8Gw" ,
   "version"  : {
     "number"  "5.5.2" ,
     "build_hash"  "b2f0c09" ,
     "build_date"  "2017-08-14T12:33:14.154Z" ,
     "build_snapshot"  false ,
     "lucene_version"  "6.6.0"
   },
   "tagline"  "You Know, for Search"
}



二、Logstash安装


1、下载logstash软件包

1
# wget https://artifacts.elastic.co/downloads/logstash/logstash-5.5.2.tar.gz


2、解压至指定安装目录

1
2
3
4
# tar -zxf logstash-5.5.2.tar.gz -C /usr/local/
# cd /usr/local/
  
# mv logstash-5.5.2 logstash


3、运行logstash

# cd logstash/

# ./bin/logstash -e 'input { stdin { } } output { stdout {} }'


输入hello world!  ,验证是否正常输出

1
2
3
4
5
6
7
8
9
10
11
12
[root@elk-server logstash] # ./bin/logstash -e 'input { stdin { } } output { stdout {} }'
ERROR StatusLogger No log4j2 configuration  file  found. Using default configuration: logging only errors to the console.
Sending Logstash's logs to  /usr/local/logstash/logs  which  is now configured via log4j2.properties
[2017-08-28T15:11:33,267][INFO ][logstash.setting.writabledirectory] Creating directory {:setting=> "path.queue" , :path=> "/usr/local/logstash/data/queue" }
[2017-08-28T15:11:33,273][INFO ][logstash.setting.writabledirectory] Creating directory {:setting=> "path.dead_letter_queue" , :path=> "/usr/local/logstash/data/dead_letter_queue" }
[2017-08-28T15:11:33,300][INFO ][logstash.agent           ] No persistent UUID  file  found. Generating new UUID {:uuid=> "2fb479ab-0ca5-4979-89b1-4246df9a7472" , :path=> "/usr/local/logstash/data/uuid" }
[2017-08-28T15:11:33,438][INFO ][logstash.pipeline        ] Starting pipeline { "id" => "main" "pipeline.workers" =>8,  "pipeline.batch.size" =>125,  "pipeline.batch.delay" =>5,  "pipeline.max_inflight" =>1000}
[2017-08-28T15:11:33,455][INFO ][logstash.pipeline        ] Pipeline main started
The stdin plugin is now waiting  for  input:
[2017-08-28T15:11:33,497][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
hello world!   
2017-08-28T07:11:42.724Z elk-server.huangming.org hello world!



三、Kibana安装


1、下载kibana

1
# wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.2-linux-x86_64.tar.gz


2、解压至安装目录

1
2
3
# tar -zxf kibana-5.5.2-linux-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# mv kibana-5.5.2-linux-x86_64 kibana


3、修改配置

1
2
3
4
5
6
7
# cd kibana/
  
# vim config/kibana.yml
  
server.port: 5601             # 监听端口
server.host:  "10.17.83.42"    # 指定后端服务器
elasticsearch.url:  "http://10.17.83.42:9200"   # 指定elasticsearch实例地址



4、运行kibana


# ./bin/kibana &

1
2
3
4
5
6
7
8
9
10
[root@elk-server kibana] # ./bin/kibana &
[1] 3219
[root@elk-server kibana] #   log   [07:26:02.496] [info][status][plugin:kibana@5.5.2] Status changed from uninitialized to green - Ready
   log   [07:26:02.604] [info][status][plugin:elasticsearch@5.5.2] Status changed from uninitialized to yellow - Waiting  for  Elasticsearch
   log   [07:26:02.637] [info][status][plugin:console@5.5.2] Status changed from uninitialized to green - Ready
   log   [07:26:02.682] [info][status][plugin:metrics@5.5.2] Status changed from uninitialized to green - Ready
   log   [07:26:02.930] [info][status][plugin:elasticsearch@5.5.2] Status changed from yellow to green - Kibana index ready
   log   [07:26:02.932] [info][status][plugin:timelion@5.5.2] Status changed from uninitialized to green - Ready
   log   [07:26:02.937] [info][listening] Server running at http: //10 .17.83.42:5601
   log   [07:26:02.939] [info][status][ui settings] Status changed from uninitialized to green - Ready



5、验证kibana


在客户端浏览器打开http://10.17.83.42:5601

wKioL1mj3eGhpWozAAB5-KFyFn4377.png


在该页面提示我们需要创建一个index

 

首先创建一个kinana默认的index(名称为.kibana),如果输入的index名不存在,则无法创建

wKiom1mj3hmxgB_IAABf9OAqQII729.png


查看运行状态及已安装的插件

wKioL1mj3vXCO9DzAACd_1n55NM020.png


至此ELK已经搭建完成了,下面来创建一个收集message系统日志的实例



本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1960254

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
3月前
|
人工智能 自然语言处理 运维
让搜索引擎“更懂你”:AI × Elasticsearch MCP Server 开源实战
本文介绍基于Model Context Protocol (MCP)标准的Elasticsearch MCP Server,它为AI助手(如Claude、Cursor等)提供与Elasticsearch数据源交互的能力。文章涵盖MCP概念、Elasticsearch MCP Server的功能特性及实际应用场景,例如数据探索、开发辅助。通过自然语言处理,用户无需掌握复杂查询语法即可操作Elasticsearch,显著降低使用门槛并提升效率。项目开源地址:<https://github.com/awesimon/elasticsearch-mcp>,欢迎体验与反馈。
864 1
|
4月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
6月前
|
存储 运维 监控
金融场景 PB 级大规模日志平台:中信银行信用卡中心从 Elasticsearch 到 Apache Doris 的先进实践
中信银行信用卡中心每日新增日志数据 140 亿条(80TB),全量归档日志量超 40PB,早期基于 Elasticsearch 构建的日志云平台,面临存储成本高、实时写入性能差、文本检索慢以及日志分析能力不足等问题。因此使用 Apache Doris 替换 Elasticsearch,实现资源投入降低 50%、查询速度提升 2~4 倍,同时显著提高了运维效率。
金融场景 PB 级大规模日志平台:中信银行信用卡中心从 Elasticsearch 到 Apache Doris 的先进实践
|
8月前
|
存储 JSON Java
ELK 圣经:Elasticsearch、Logstash、Kibana 从入门到精通
ELK是一套强大的日志管理和分析工具,广泛应用于日志监控、故障排查、业务分析等场景。本文档将详细介绍ELK的各个组件及其配置方法,帮助读者从零开始掌握ELK的使用。
|
8月前
|
存储 监控 安全
|
8月前
|
存储 数据采集 监控
开源日志分析Elasticsearch
【10月更文挑战第22天】
134 5
|
2月前
|
JSON 安全 数据可视化
Elasticsearch(es)在Windows系统上的安装与部署(含Kibana)
Kibana 是 Elastic Stack(原 ELK Stack)中的核心数据可视化工具,主要与 Elasticsearch 配合使用,提供强大的数据探索、分析和展示功能。elasticsearch安装在windows上一般是zip文件,解压到对应目录。文件,elasticsearch8.x以上版本是自动开启安全认证的。kibana安装在windows上一般是zip文件,解压到对应目录。elasticsearch的默认端口是9200,访问。默认用户是elastic,密码需要重置。
613 0
|
3月前
|
安全 Java Linux
Linux安装Elasticsearch详细教程
Linux安装Elasticsearch详细教程
321 1
|
8月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
283 5
|
9月前
|
存储 JSON Java
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
这篇文章是关于Elasticsearch的学习指南,包括了解Elasticsearch、版本对应、安装运行Elasticsearch和Kibana、安装head插件和elasticsearch-ik分词器的步骤。
751 0
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。