ELK 日志分析系统 ----------- 部署ElasticSearch群集

ELK日志分析系统简介

  • 服务器中产生的日志是庞大的,通常我们想要从日志中查找自己想要的信息时时通过 grep、awk等来实现,但在那些庞大规模的web、机构面前,就不够看了。像那些大型电商网站,动则上百亿PV的日志产生,如何快速归档、快速定位、查询成为问题。
  • 这时候我们就可以用到ELK日志分析系统,ELK提供了一整套解决方案。它是由ElasticSearch(群集) 、logstash(日志搜集)、Kibana(展现相关的分析的日志信息、数据信息、索引信息在web页面上)这些开源软件,相互作用配合,对日志进行集中化管理的一种架构系统。

ELK的工作原理

  • 前端产生了各种web日志被Logstash代理端搜集到,(Lofstash会指定这些Web服务的路径定时去检索日志里面的内容,然后进行搜集),然后将这些日志转化成es所能识别的格式,传输给es,接着es会将这些日志进行存储,并做相应的索引以便快速定位,当需要让它展示相关的日志信息时,Kibana会将es传输给它的数据在web页面上以柱状图、饼状图、分析图以及相关的复制索引信息展现给管理者或用户.

Elasticsearch 群集介绍

  • Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等
部署ElasticSearch群集
部署规划

1、2台CentOS7.4 版本的Linux操作系统
2、node1:20.0.0.101
node2:20.0.0.102
3、所需软包请到官网下载

安装ES群集
  • 分别在两台节点上执行下列操作
1、 安装环境设置
systemctl stop firewalld
setenforce 0
hostnamectl set-hostname node1

vi /etc/hosts
20.0.0.101 node1
20.0.0.102 node2

java -version

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)


2、将elasticsearch-5.5.0.rpm软件包上传到家目录中并安装

3、重载系统参数,并设置为开机自启
systemctl daemon-reload
systemctl enable elasticsearch.service

4、修改lasticsearch主配置文件
cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak                  ###将文件做个备份

vi /etc/elasticsearch/elasticsearch.yml

17行 :cluster.name: my-elk-cluster
23行 :node.name: node1
33行 :path.data: /data/elk_data
37行 :path.logs: /var/log/elasticsearch/
43行 :bootstrap.memory_lock: false
55行 :network.host: 0.0.0.0
59行 :http.port: 9200
68行 :discovery.zen.ping.unicast.hosts: ["node1", "node2"]


5、创建数据存放目录,并授权
mkdir -p /data/elk_data

[root@node2 ~]# id elasticsearch理es的
uid=990(elasticsearch) gid=985(elasticsearch)=985(elasticsearch)

chown elasticsearch:elasticsearch /data/elk_data据
[root@node2 ~]# ll /data/
drwxr-xr-x. 2 elasticsearch elasticsearch 6 1028 14:49 elk_data


6、开启服务并确认服务是否开启
systemctl start elasticsearch.service

[root@node2 ~]# netstat -anpt | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      54162/java

7、真机网页输入:  http://20.0.0.101:9200   和  http://20.0.0.102:9200    分别查看节点信息
101{
  "name" : "node1",
  "cluster_name" : "my-elk-cluster",
  "cluster_uuid" : "J3Jom7kbS4GqpTw1KSGUQg",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}


102{
  "name" : "node2",
  "cluster_name" : "my-elk-cluster",
  "cluster_uuid" : "J3Jom7kbS4GqpTw1KSGUQg",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}


网页输入:    http://20.0.0.101:9200/_cluster/health?pretty    查看健康状态
101102{
  "cluster_name" : "my-elk-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}



在网页输入: http://20.0.0.102:9200/_cluster/state?pretty    检查群集状态信息

{
  "cluster_name" : "my-elk-cluster",
  "version" : 3,
  "state_uuid" : "IM53qDZaTneZVZW7Ujo6bg",
  "master_node" : "GnH2gHnqSVC4GlpcZLUrSw",
  "blocks" : { },
  "nodes" : {
    "CgH_iSNLSXiex70Q4vRErw" : {
      "name" : "node2",
      "ephemeral_id" : "1pfVovCVQhWuzrDgsuMxrg",
      "transport_address" : "20.0.0.102:9300",
      "attributes" : { }
    },
    "GnH2gHnqSVC4GlpcZLUrSw" : {
      "name" : "node1",
      "ephemeral_id" : "_GYOm0SwRsWzmH-eQ3EQtw",
      "transport_address" : "20.0.0.101:9300",
      "attributes" : { }
    }
  },
  "metadata" : {
    "cluster_uuid" : "J3Jom7kbS4GqpTw1KSGUQg",
    "templates" : { },
    "indices" : { },
    "index-graveyard" : {
      "tombstones" : [ ]
    }
  },
  "routing_table" : {
    "indices" : { }
  },
  "routing_nodes" : {
    "unassigned" : [ ],
    "nodes" : {
      "CgH_iSNLSXiex70Q4vRErw" : [ ],
      "GnH2gHnqSVC4GlpcZLUrSw" : [ ]
    }
  }
}


8、 编译安装 node 组件依赖包
上传node-v8.2.1.tar.gz软件包到家目录中并解压
tar zxvf node-v8.2.1.tar.gz
cd node-v8.2.1/
./configure
make
make install


9、安装 phantomjs 前端框架
上传phantomjs-2.1.1-linux-x86_64.tar.bz2软件包到家目录中并解压
tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
cd phantomjs-2.1.1-linux-x86_64/bin
cp phantomjs /usr/local/bin 


10、安装 elasticsearch-head 数据可视化工具
上传elasticsearch-head.tar.gz安装包到家目录
tar zxvf elasticsearch-head.tar.gz
cd elasticsearch-head/
npm install


11、修改主配置文件
vi /etc/elasticsearch/elasticsearch.yml 
http.cors.enabled: true 
http.cors.allow-origin: "*"

systemctl restart elasticsearch


12、启动 elasticsearch-head 工具
cd elasticsearch-head/
npm run start &

确认端口是否启动:
netstat -lnupt | grep 9100
tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN      101486/grunt

netstat -lnupt | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      101335/java   



13、 真机测试
输入网址:    http://20.0.0.101:9100     ;   进入之后修改 连接localhost 为本机IP地址,就可以进行节点连接,健康值为绿色
★node1
●node2


虚拟机节点中输入:
  curl -XPUT 'localhost:9200/index-demo/test/1?pretty&pretty' -H 'content-Type: application/json' -d '{"user":"zhangsan","mesg":"hello world"}'
  (刷新下真机网页页面,点击索引选项,即可看到存储值)

到此结束,感谢浏览

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值