阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

ELK Stack 日志系统搭建

128次阅读
没有评论

共计 11938 个字符,预计需要花费 30 分钟才能阅读完成。

ELK Stack 是什么?

ELK Stack 是 Elasticsearch、Logstash、Kibana 三个开源软件的组合。在实时数据检索和分析场合,三者通常是配合共用,而且又都先后归于 Elastic.co 公司名下,故有此简称。

ELK Stack 在最近两年迅速崛起,成为机器数据分析,或者说实时日志处理领域,开源界的第一选择。和传统的日志处理方案相比,ELK Stack 具有如下几个优点:
• 处理方式灵活。Elasticsearch 是实时全文索引,不需要像 storm 那样预先编程才能使用;
• 配置简易上手。Elasticsearch 全部采用 JSON 接口,Logstash 是 Ruby DSL 设计,都是目前业界最通用的配置语法设计;
• 检索性能高效。虽然每次查询都是实时计算,但是优秀的设计和实现基本可以达到全天数据查询的秒级响应;
• 集群线性扩展。不管是 Elasticsearch 集群还是 Logstash 集群都是可以线性扩展的;
• 前端操作炫丽。Kibana 界面上,只需要点击鼠标,就可以完成搜索、聚合功能,生成炫丽的仪表板。
以上摘自 ELKstack 中文指南

Logstash 是能够用于收集, 处理和转发事件或日志信息的工具.
Logstash: Logstash 服务的组件,用于处理日志
Elasticsearch: 用于存储, 索引日志
Kibana 4: 搜索和可视化的日志的 Web 界面.

Elasticsearch 和 Logstash 需要运行 Java 环境, 并且版本最好是 1.7 以上.
首先必须安装 java7 及以上的版本

http://www.java.com/zh_CN/download/linux_manual.jsp
 [root@192_168_174_68 home]# wget ‘http://sdlc-esd.Oracle.com/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm&BHost=javadl.sun.com&File=jre-8u73-linux-x64.rpm&AuthParam=1457343423_73675d83c3aa00d667217e09e10d85c2&ext=.rpm’ -O jre-8u73-linux-x64.rpm
 –2016-03-07 17:18:01–  http://sdlc-esd.oracle.com/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm&BHost=javadl.sun.com&File=jre-8u73-linux-x64.rpm&AuthParam=1457343423_73675d83c3aa00d667217e09e10d85c2&ext=.rpm
 Resolving sdlc-esd.oracle.com… 96.7.54.179, 96.7.54.187
 Connecting to sdlc-esd.oracle.com|96.7.54.179|:80… connected.
 HTTP request sent, awaiting response… 200 OK
 Length: 49210622 (47M) [application/x-sdlc]
 Saving to:“jre-8u73-linux-x64.rpm”
100%[=================================================>] 49,210,622  1.58M/s  in 31s   
 2016-03-07 17:18:32 (1.51 MB/s) –“jre-8u73-linux-x64.rpm”saved [49210622/49210622]

安装 jdk 

[root@192_168_174_68 home]# yum install jre-8u73-linux-x64.rpm -y

[root@192_168_174_68 home]# java -version
 java version “1.8.0_73”
 Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
 Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

Elasticsearch 2.2.0 安装

YUM / DNF 安装
 下载并安装公钥:
 [root@192_168_174_68 ~]# rpm –import https://packages.elastic.co/GPG-KEY-elasticsearch
创建 /etc/yum.repos.d/elasticsearch.repo 文件, 复制下面的内容到文件中
[root@192_168_174_68 ~]# vim /etc/yum.repos.d/elasticsearch.repo
 [elasticsearch-2.x]
 name=Elasticsearch repository for 2.x packages
 baseurl=https://packages.elastic.co/elasticsearch/2.x/CentOS
 gpgcheck=1
 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
 enabled=1
安装 elasticsearch
 [root@192_168_174_68 ~]# yum install elasticsearch    #新版本的 Fedora 使用 dnf install elasticsearch
配置 elasticsearch 服务自动启动,SysV init 版本使用
chkconfig –add elasticsearch
 systemd 使用:
sudo /bin/systemctl daemon-reload
 sudo /bin/systemctl enable elasticsearch.service
修改 elasticsearch 配置
[root@192_168_174_68 ~]# mkdir /opt/elasticsearch.path.data
 [root@192_168_174_68 elasticsearch]# vim /etc/elasticsearch/elasticsearch.yml
 path.data: /opt/elasticsearch.path.data
 network.host: 0.0.0.0

启动服务:
 [root@192_168_174_68 opt]# service elasticsearch start   
 Starting elasticsearch:                                    [OK]
 [root@192_168_174_68 opt]# ps aux |grep elastic
 498      8171 24.3  3.2 6815980 263784 ?      Sl  17:24  0:10 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/share/elasticsearch -cp /usr/share/elasticsearch/lib/elasticsearch-2.2.0.jar:/usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -p /var/run/elasticsearch/elasticsearch.pid -d -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.conf=/etc/elasticsearch
 root      8283  0.0  0.0 103252  844 pts/1    S+  17:25  0:00 grep elastic
 [root@192_168_174_68 opt]# netstat -lntp |grep 8171
 tcp        0      0 ::ffff:127.0.0.1:9200      :::*                        LISTEN      8171/java         
 tcp        0      0 ::1:9200                    :::*                        LISTEN      8171/java         
 tcp        0      0 ::ffff:127.0.0.1:9300      :::*                        LISTEN      8171/java         
 tcp        0      0 ::1:9300                    :::*                        LISTEN      8171/java         
 [root@192_168_174_68 opt]#
服务已经启动.

ELK Stack 日志系统搭建

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-08/134166p2.htm

kibana4.4.1 安装:
在下载主界面, 有这么一行字, 所以要注意与安装的 elasticsearch 相匹配.
Note: Kibana 4.4.1 requires Elasticsearch 2.2.

下载安装包.
 [root@192_168_174_68 ~]# wget https://download.elastic.co/kibana/kibana/kibana-4.4.1-linux-x64.tar.gz
 [root@192_168_174_68 ~]# tar zxvf kibana-4.4.1-linux-x64.tar.gz -C /opt/
 [root@192_168_174_68 ~]# cd /opt/kibana-4.4.1-linux-x64/
修改配置文件
[root@192_168_174_68 kibana-4.4.1-linux-x64]# vim config/kibana.yml
 server.port: 5601
 server.host: “0.0.0.0”
elasticsearch.url: “http://192.168.174.68:9200”
启动服务
[root@192_168_174_68 kibana-4.4.1-linux-x64]# nohup ./bin/kibana -l /var/log/kibana4.4.1.log  &
 [1] 8867
 nohup: ignoring input and appending output to `nohup.out’

ELK Stack 日志系统搭建

logstash 安装

ELK Stack 日志系统搭建

YUM 源安装方式
 下载安装公钥
rpm –import https://packages.elastic.co/GPG-KEY-elasticsearch
创建 /etc/yum.repo.d/logstash.repo 文件
[root@192_168_174_68 ~]# vim /etc/yum.repos.d/logstash.repo

 [logstash-2.2]
 name=Logstash repository for 2.2.x packages
 baseurl=http://packages.elastic.co/logstash/2.2/CentOS
 gpgcheck=1
 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
 enabled=1

 [root@192_168_174_68 ~]# yum install logstash -y

ELK Stack 日志系统搭建

测试:
 [root@192_168_174_68 logstash]# JAVA_HOME=/usr/java/jre1.8.0_73 && /opt/logstash/bin/logstash  -e ‘input {stdin {} } output {stdout {} }’   
 Settings: Default pipeline workers: 8
 Logstash startup completed
 talen
 2016-03-07T09:51:08.290Z 192_168_174_68 talen
测试 OK
下面使用 log4j 模块收集日志
 从 Log4j SocketAppender 通过 TCP 读取事件. 只支持 log4j 1.x 版本. 根据配置 mode 的不同, 可以接受客户端连接也可以连接到服务端. 根据 mode 不同, 必需在对端配置 SocketAppender 或 SocketHubAppender.
编辑业务的 log4j 配置, 添加如下信息
log4j.rootLogger=logstash
 log4j.appender.logstash=org.apache.log4j.net.SocketAppender
 log4j.appender.logstash.port=56789
 log4j.appender.logstash.remoteHost=192.168.174.68
修改 logstash 配置信息
[root@192_168_174_68 ~]# cat /etc/logstash/conf.d/3rd.conf
 input {
        log4j {
                mode => “server”
                host  => “0.0.0.0”
                port => 56789
                type => “log4j”
        }
 }
 #The geoip plugin configuration requires data that is already defined as separate fields. Make sure that the geoip section is after the grok section of the configuration file.
 output {
    elasticsearch {
        hosts =>  “192.168.174.68:9200”
    }
 }
在浏览器中输入 http://192.168.174.68:5601, 可以看到收集上来的日志

ELK Stack 日志系统搭建
ELK Stack 日志系统搭建
ELK Stack 日志系统搭建

问题一:

 [root@192_168_174_68 ~]# service elasticsearch start
 Starting elasticsearch: Exception in thread “main” java.lang.IllegalStateException: Unable to access ‘path.data’ (/opt/elasticsearch.path.data/elasticsearch)
 Likely root cause: java.nio.file.AccessDeniedException: /opt/elasticsearch.path.data/elasticsearch
        at sun.nio.fs.UnixException.translateToIOException(Unknown Source)
        at sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.UnixFileSystemProvider.createDirectory(Unknown Source)
        at java.nio.file.Files.createDirectory(Unknown Source)
        at java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
        at java.nio.file.Files.createDirectories(Unknown Source)
        at org.elasticsearch.bootstrap.Security.ensureDirectoryExists(Security.java:337)
        at org.elasticsearch.bootstrap.Security.addPath(Security.java:314)
        at org.elasticsearch.bootstrap.Security.addFilePermissions(Security.java:259)
        at org.elasticsearch.bootstrap.Security.createPermissions(Security.java:212)
        at org.elasticsearch.bootstrap.Security.configure(Security.java:118)
        at org.elasticsearch.bootstrap.Bootstrap.setupSecurity(Bootstrap.java:196)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:167)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
 Refer to the log for complete error details.
                                                            [FAILED]
解决:
[root@192_168_174_68 opt]# chmod 777 /opt/elasticsearch.path.data/

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-08/134166.htm

ELK Stack 是什么?

ELK Stack 是 Elasticsearch、Logstash、Kibana 三个开源软件的组合。在实时数据检索和分析场合,三者通常是配合共用,而且又都先后归于 Elastic.co 公司名下,故有此简称。

ELK Stack 在最近两年迅速崛起,成为机器数据分析,或者说实时日志处理领域,开源界的第一选择。和传统的日志处理方案相比,ELK Stack 具有如下几个优点:
• 处理方式灵活。Elasticsearch 是实时全文索引,不需要像 storm 那样预先编程才能使用;
• 配置简易上手。Elasticsearch 全部采用 JSON 接口,Logstash 是 Ruby DSL 设计,都是目前业界最通用的配置语法设计;
• 检索性能高效。虽然每次查询都是实时计算,但是优秀的设计和实现基本可以达到全天数据查询的秒级响应;
• 集群线性扩展。不管是 Elasticsearch 集群还是 Logstash 集群都是可以线性扩展的;
• 前端操作炫丽。Kibana 界面上,只需要点击鼠标,就可以完成搜索、聚合功能,生成炫丽的仪表板。
以上摘自 ELKstack 中文指南

Logstash 是能够用于收集, 处理和转发事件或日志信息的工具.
Logstash: Logstash 服务的组件,用于处理日志
Elasticsearch: 用于存储, 索引日志
Kibana 4: 搜索和可视化的日志的 Web 界面.

Elasticsearch 和 Logstash 需要运行 Java 环境, 并且版本最好是 1.7 以上.
首先必须安装 java7 及以上的版本

http://www.java.com/zh_CN/download/linux_manual.jsp
 [root@192_168_174_68 home]# wget ‘http://sdlc-esd.Oracle.com/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm&BHost=javadl.sun.com&File=jre-8u73-linux-x64.rpm&AuthParam=1457343423_73675d83c3aa00d667217e09e10d85c2&ext=.rpm’ -O jre-8u73-linux-x64.rpm
 –2016-03-07 17:18:01–  http://sdlc-esd.oracle.com/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u73-b02/jre-8u73-linux-x64.rpm&BHost=javadl.sun.com&File=jre-8u73-linux-x64.rpm&AuthParam=1457343423_73675d83c3aa00d667217e09e10d85c2&ext=.rpm
 Resolving sdlc-esd.oracle.com… 96.7.54.179, 96.7.54.187
 Connecting to sdlc-esd.oracle.com|96.7.54.179|:80… connected.
 HTTP request sent, awaiting response… 200 OK
 Length: 49210622 (47M) [application/x-sdlc]
 Saving to:“jre-8u73-linux-x64.rpm”
100%[=================================================>] 49,210,622  1.58M/s  in 31s   
 2016-03-07 17:18:32 (1.51 MB/s) –“jre-8u73-linux-x64.rpm”saved [49210622/49210622]

安装 jdk 

[root@192_168_174_68 home]# yum install jre-8u73-linux-x64.rpm -y

[root@192_168_174_68 home]# java -version
 java version “1.8.0_73”
 Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
 Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

Elasticsearch 2.2.0 安装

YUM / DNF 安装
 下载并安装公钥:
 [root@192_168_174_68 ~]# rpm –import https://packages.elastic.co/GPG-KEY-elasticsearch
创建 /etc/yum.repos.d/elasticsearch.repo 文件, 复制下面的内容到文件中
[root@192_168_174_68 ~]# vim /etc/yum.repos.d/elasticsearch.repo
 [elasticsearch-2.x]
 name=Elasticsearch repository for 2.x packages
 baseurl=https://packages.elastic.co/elasticsearch/2.x/CentOS
 gpgcheck=1
 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
 enabled=1
安装 elasticsearch
 [root@192_168_174_68 ~]# yum install elasticsearch    #新版本的 Fedora 使用 dnf install elasticsearch
配置 elasticsearch 服务自动启动,SysV init 版本使用
chkconfig –add elasticsearch
 systemd 使用:
sudo /bin/systemctl daemon-reload
 sudo /bin/systemctl enable elasticsearch.service
修改 elasticsearch 配置
[root@192_168_174_68 ~]# mkdir /opt/elasticsearch.path.data
 [root@192_168_174_68 elasticsearch]# vim /etc/elasticsearch/elasticsearch.yml
 path.data: /opt/elasticsearch.path.data
 network.host: 0.0.0.0

启动服务:
 [root@192_168_174_68 opt]# service elasticsearch start   
 Starting elasticsearch:                                    [OK]
 [root@192_168_174_68 opt]# ps aux |grep elastic
 498      8171 24.3  3.2 6815980 263784 ?      Sl  17:24  0:10 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/share/elasticsearch -cp /usr/share/elasticsearch/lib/elasticsearch-2.2.0.jar:/usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -p /var/run/elasticsearch/elasticsearch.pid -d -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.conf=/etc/elasticsearch
 root      8283  0.0  0.0 103252  844 pts/1    S+  17:25  0:00 grep elastic
 [root@192_168_174_68 opt]# netstat -lntp |grep 8171
 tcp        0      0 ::ffff:127.0.0.1:9200      :::*                        LISTEN      8171/java         
 tcp        0      0 ::1:9200                    :::*                        LISTEN      8171/java         
 tcp        0      0 ::ffff:127.0.0.1:9300      :::*                        LISTEN      8171/java         
 tcp        0      0 ::1:9300                    :::*                        LISTEN      8171/java         
 [root@192_168_174_68 opt]#
服务已经启动.

ELK Stack 日志系统搭建

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-08/134166p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计11938字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中