ELK① 介绍

2018年8月29日 0 条评论 13.51k 次阅读 0 人点赞

一、概念介绍

ELK 是Elasticsearch、Logstash、Kibana的简称,这三者是核心套件,但并非全部。

Elasticsearch 是实时全文搜索和分析引擎,提供搜集、分析、存储数据三大功能;是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统。它构建于Apache Lucene搜索引擎库之上。

Logstash 是一个用来搜集、分析、过滤日志的工具。它支持几乎任何类型的日志,包括系统日志、错误日志和自定义应用程序日志。它可以从许多来源接收日志,这些来源包括 syslog、消息传递(例如 RabbitMQ)和JMX,它能够以多种方式输出数据,包括电子邮件、websockets和Elasticsearch。

Kibana 是一个基于Web的图形界面,用于搜索、分析和可视化存储在 Elasticsearch指标中的日志数据。它利用Elasticsearch的REST接口来检索数据,不仅允许用户创建他们自己的数据的定制仪表板视图,还允许他们以特殊的方式查询和过滤数据

官网地址:https://www.elastic.co/cn/
官网权威指南:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
安装指南:https://www.elastic.co/guide/en/elasticsearch/reference/5.x/rpm.html

①逻辑架构:

elk逻辑架构

Shipper 使用 logstash file input, redis output,对nginx的/wwwlog目录进行读取

Broker 使用 Redis

Indexer 使用 logstash redis input, elasticsearch output

Storage 使用 ElasticSearch

WebInterface 使用 Kibana

②部署架构:

image.png

简而言之就是:logstash 从原始日志文件中读取数据,存放至 redis,然后从redis 中取出后处理数据,然后传递给 elasticsearch,由 elasticsearch 匹配数据后于 kibana 展示(也就是 kibana 操作 elasticsearch 搜索 logstash 处理的 原始日志)

二、部署步骤:

①部署环境:

java-jdk:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

下载解压后添加bin文件夹到 $PATH 变量里面即可:

tar xzf jdk1.8.0_144.tar.gz
mv jdk1.8.0_144 /usr/local/java
echo 'PATH=$PATH:/usr/local/java/bin' >> /etc/profile

安装shasum

yum install perl-Digest-SHA -y

部分系统参数修改:

# grep -v '^$' /etc/security/limits.conf | grep -v '#'
* soft nproc 2048
* hard nproc 4096
* soft nofile 65535
* hard nofile 131072
# grep -v '^$' /etc/security/limits.d/90-nproc.conf | grep -v '#'
* soft nproc 4096

②源码包安装:

下载地址:https://www.elastic.co/downloads

  • Elasticsearch:

安装:

官方安装说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/zip-targz.html

环境依赖:JAVA8 或者以上

# useradd elk    #添加用户elk(elk不允许使用root启动)
# passwd elk    #设置elk密码
# cd /home/elk
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz.sha512
# shasum -a 512 -c elasticsearch-6.3.1.tar.gz.sha512 tar -xzf elasticsearch-6.3.1.tar.gz
# chown -R elk.elk
# echo "ES_HOME=$(readlink -f elasticsearch-6.3.1)" >> /etc/profile
# echo 'ES_PATH_CONF=$ES_HOME/config' >> /etc/profile
# su - elk
$ cd elasticsearch-6.3.1/
$ ./bin/elasticsearch -d -p pid

配置:

官方配置 说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
jvm配置 说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
安全配置 说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/secure-settings.html
日志配置 说明:https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html

启动方法:

cd /home/elk/elasticsearch-6.3.1
./bin/elasticsearch -d -p pid

查看启动日志:

tail -f logs/es-cluster.log

>>点击查看 便于操作的启动、停止、查看脚本

>>点击查看配置文件

核心配置:https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html


ES集群方式配置:

复制2套文件夹,删除data、logs下数据。共3个节点,一个客户端节点,2个数据节点。(参考上面部署架构)

下面配置全为本机:

Node-0的配置文件解析:

cluster.name: es-cluster
node.name: node-0
node.master: false
node.data: false
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
 
network.host: 127.0.0.1
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300", "127.0.0.1:9301","127.0.0.1:9302"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 2
action.destructive_requires_name: true

关于discovery.zen.minimum_master_nodes配置的说明,原文如下:

To prevent data loss, it is vital to configure the discovery.zen.minimum_master_nodes setting so that each master-eligible node knows the minimum number of master-eligible nodes that must be visible in order to form a cluster.

为了防止数据丢失,必须配置一个 discovery.zen.minimum_master_nodes 设置,为了构成一个群集中让有资格成为master的节点所知道。

Without this setting, a cluster that suffers a network failure is at risk of having the cluster split into two independent clusters?—?a split brain?—?which will lead to data loss. A more detailed explanation is provided in Avoiding split brain with minimum_master_nodes.

如果没有这个设置,1个群集会因为网络失败的风险导致群集会被分割成2个独立的群集——脑裂——将会导致数据丢失。更多解释可以点击查看:Avoiding split brain with

To avoid a split brain, this setting should be set to a quorum of master-eligible nodes:

为了避免脑裂,这个设置项应该设置成一个合法的数值,参考公式如下:(可能类似于交换或者路由中的dr选举)

(master_eligible_nodes / 2) + 1

In other words, if there are three master-eligible nodes, then minimum master nodes should be set to (3 / 2) + 1 or 2:

discovery.zen.minimum_master_nodes: 2

>>点击查看所有配置

验证:

curl -X GET "http://localhost:9200/"
{
  "name" : "Cp8oag6",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
  "version" : {
    "number" : "6.3.1",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "f27399d",
    "build_date" : "2016-03-30T09:51:41.449Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "1.2.3",
    "minimum_index_compatibility_version" : "1.2.3"
  },
  "tagline" : "You Know, for Search"}
#查看健康状态
curl -X GET http://localhost:9200/_cat/health?v
#查看线程池
curl -X GET http://localhost:9200/_nodes/stats/thread_pool?pretty
#查看索引
curl -X GET http://localhost:9200/_cat/indices
* 对于elasticsearch中的所有配置,均可以设置为127.0.0.1,以方便调用,在iptables中可以设置外部拦截端口
* 如果不启用xpack,对于新版本中(此文采用6.3.1),已经集成了xpack,可以使用配置项 xpack.security.enabled: false 关闭 官方说明

  • Logstash:

启动方式:

cd /home/elk/logstash-6.3.1
nohup ./bin/logstash > /dev/null 2>&1 &

查看启动日志:

tail -f logs/logstash-plain.log

>>点击查看 nginx日志设置

>>点击查看 logstash.yml

>>点击查看 startup.options

>>点击查看 pipelines.yml

此处添加 nginx 2个日志文件到 redis 的配置,以及 从 redis 取出到 elasticsearch 的配置,涉及比较复杂的就是 对 日志 内容的处理:

>>点击查看 nginx到redis配置

>>点击查看 redis到elasticsearch配置

对于GeoIP数据库可以使用 yum install -y geoipupdate 安装后配置 /etc/GeoIP.conf 中的:

UserId 0
LicenseKey 000000000000

免费序列号后,运行 geoipupdate 更新geo数据库文件,位置如上配置。

对于redis到elasticsearch中的filter规则,可使用grok工具调试到elasticsearch的正则表达式:http://grok.elasticsearch.cn/do/match

>>点击查看完整启动日志logstash-plain.log


  • Kibana:

启动方式:

cd /home/elk/kibana-6.3.1-linux-x86_64
./bin/kibana &

查看启动日志:

tail -f logs/logstash-plain.log

>>点击查看 配置文件kibana.yml

Beats:

暂未安装使用

三、调试使用

篇幅太大,转到另外一篇://www.sevenfal.com/2018/07/26/1567.html


手头机器扛不住docker,暂不使用docker

>>点击查看docker安装

Sevenfal

这个人太懒什么东西都没留下

文章评论(0)