ELK日志分析系统——-Elasticsearch 安装

ELK日志分析系统——-Elasticsearch 安装

一、系统简介

1.1.为什么会有分析系统

日志分析是运维工程师解决系统故障,发现问题的主要手段。日志主要包括系统日志、应用程序日志和安全日志。
系统运维和开发人员可以通过日志了解服务器软硬件信息、检查配置过程中的错误及错误发生的原因。经常分析日志可以了解服务器的负荷,性能安全性,从而及时采取措施纠正错误。
通常,日志被分散的储存在不同的设备上。如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志,即繁琐又效率低下。为此,我们可以使用集中化的日志管理

日志服务器为了提高安全性,集中存放日志导致了对日志分析的困难,开源实时日志分析ELK平台能够完美的解决我们上述的问题

1.2.ELK日志分析系统组成

Elasticsearch

Logstash

Kibana

1.3.处理步骤

1)将日志进行集中化管理

  1. 将日志格式化(Logstash)并输出到 Elasticsearch

3)对格式化后的数据进行索引和存储(Elasticsearch )

4)前端数据的展示(Kibana)

二、 Elasticsearch

1.概述

提供了一个分布式多用户能力的全文搜索引擎

2.核心概念

*接近实时

*集群:一个集群就是由一个或多个节点组织在一起,它们共同持有你整个的数据,并一起提供索引和搜索功能

*节点:节点就是一台单一的服务器,是集群的一部分,存储数据并参与集群的索引和搜索功能

*索引 :对应数据库

​ 索引(库) —>类型(表)---->文档(记录)

*分片和副本

分片的两个最主要原因:

水平分割扩展,增大存储量

分布式并行跨分片操作,提高性能和吞吐量

副本也有两个最主要原因:

高可用性,以应对分片或者节点故障。出于这个原因,分片副本要在不同的节点上。
增大吞吐量,搜索可以并行在所有副本上执行

三、Elasticsearch安装实验

1.关闭防火墙和核心防护

2.上传相关软件包到opt目录下

3.两台虚拟机node1 IP:20.0.0.12 和node2 ip:20.0.0.14

步骤:两台都是一样配置

[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# su
[root@node1 ~]# vim /etc/hosts
20.0.0.12  node1
20.0.0.14  node2

[root@node1 ~]# cd /opt
[root@node1 opt]# ls
elasticsearch-5.5.0.rpm  elasticsearch-head.tar.gz  node-v8.2.1.tar.gz  rh
[root@node1 opt]# rpm -ivh elasticsearch-5.5.0.rpm
[root@node1 opt]# systemctl daemon-reload
[root@node1 opt]# systemctl enable elasticsearch.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@node1 opt]# cp -p /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak 
[root@node1 opt]# 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"]
[root@node1 opt]# mkdir -p /data/elk_data
[root@node1 opt]# chown elasticsearch.elasticsearch /data/elk_data
[root@node1 opt]# systemctl start elasticsearch.service 
[root@node1 opt]# netstat -antp | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      59185/java

真机登录 http://20.0.0.14:9200/_cluster/state?pretty查看如下

  "cluster_name" : "my-elk-cluster",
  "version" : 2,
  "state_uuid" : "oqr45jA1QOS6Ywro-NuZWA",
  "master_node" : "sxbb7sI6QaiewXIkj_fcwQ",
  "blocks" : { },
  "nodes" : {
    "sxbb7sI6QaiewXIkj_fcwQ" : {
      "name" : "node1",
      "ephemeral_id" : "UEZXRB7gQ6WFaxKNfVm1_w",
      "transport_address" : "20.0.0.14:9300",
      "attributes" : { }
    }
  },
  "metadata" : {
    "cluster_uuid" : "nNST1bVnSx2F1y9gLpNkzQ",
    "templates" : { },
    "indices" : { },
    "index-graveyard" : {
      "tombstones" : [ ]
    }
  },
  "routing_table" : {
    "indices" : { }
  },
  "routing_nodes" : {
    "unassigned" : [ ],
    "nodes" : {
      "sxbb7sI6QaiewXIkj_fcwQ" : [ ]
    }
  }
}

编译安装node组件依赖包

上传node-v8.2.1.tar.gz到 opt
 yum -y install gcc gcc-c++ make
[root@node2 ~]# cd /opt
[root@node2 opt]# tar xzvf  node-v8.2.1.tar.gz
[root@node2 opt]# cd node-v8.2.1/
[root@node2 node-v8.2.1]# ./configure 
[root@node2 node-v8.2.1]#make-j3
[root@node2 node-v8.2.1]#make install

安装phantomjs 的前端框架

root@node2 node-v8.2.1]# cd /opt
[root@node2 opt]# tar xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2 
[root@node2 opt]# cd phantomjs-2.1.1-linux-x86_64/bin
[root@node2 bin]# cp phantomjs /usr/local/bin

安装elasticsearch-head // 数据可视化

[root@node2 bin]# cd /opt
[root@node2 opt]# tar xzvf elasticsearch-head.tar.gz
[root@node2 opt]# cd elasticsearch-head/
[root@node2 elasticsearch-head]# npm install
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/karma/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression

up to date in 3.959s
[root@node2 elasticsearch-head]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@node1 elasticsearch-head]# systemctl restart elasticsearch.service
[root@node2 elasticsearch-head]# npm run start &
[1] 100288
[root@node2 elasticsearch-head]# 

> elasticsearch-head@0.0.0 start /opt/elasticsearch-head
> grunt server

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
[root@node2 elasticsearch-head]# netstat -lnupt | grep 9100
tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN      100298/grunt        
[root@node2 elasticsearch-head]# netstat -lnupt | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      100170/java 

node1和node2 按上面步骤配置完成后

在真机浏览器登录20.0.0.12:9100后出现界面中Elasticsearch 后面 栏目中输入20.0.0.12:9200 连接发现集群健康值:greep (0 of 0)

出现结果如图

[root@node2 ~]# curl -XPUT 'localhost:9200/index-demo/test/1?pretty&pretty' -H 'content-Type: application/json' -d '{"user":"zhangsan","mesg":"hello world"}'

出现结果如图:
在这里插入图片描述
可以看到这样就表示Elasticsearch安装成功了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值