介绍: ELK是es,logstash和kibana三者的组合,他们是同一家公司开发的,在企业中经常用于进行日志采集
为啥搭建ELK呢?
ELK Stacks是一个技术栈的组合,分别是Elasticsearch、Logstash、Kibana
数据输入到logstash
中,然后logstash
进行处理后分发给es,然后es进行处理,然后kibana进行数据的可视化。
logstash里面有3个关卡,Input,Filter和Output
es博主没有深入研究,据说es内容非常多,这里我先介绍一下基本概念和基础环境搭建
类比对应关系
ES | MySQL |
---|---|
Index | DB |
Type | Table |
Document | Row |
Field | Column |
首先把SElinux
关闭,然后清空iptables
,我们自己编写一条iptables
链,允许我们局域网上的主机可以进行通信,然后还要使用ntp
进行时间同步,因为我们查看日志很多时候都是根据时间查的,所以配置这几台es服务器时间同步。
基础环境安装
yum -y install gcc
yum -y install gcc-c++
安装docker的依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
安装docker
yum -y install docker-ce
启动docker
systemctl start docker
查看docker系统版本
[root@lvs roles]# docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:27:04 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:25:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
配置docker镜像加速,这里每个人的都是不一样的,直接使用菜鸟教程那个:菜鸟教程镜像加速教学
[root@lvs roles]# sudo mkdir -p /etc/docker
[root@lvs roles]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://0lmclr63.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://0lmclr63.mirror.aliyuncs.com"]
}
重新启动docker并拉取es镜像
[root@lvs roles]# sudo systemctl daemon-reload
[root@lvs roles]# sudo systemctl restart docker
[root@lvs roles]# docker pull elasticsearch:7.2.0
7.2.0: Pulling from library/elasticsearch
8ba884070f61: Pull complete
2211b14f8b24: Pull complete
617ccdb47f3d: Pull complete
915ee6b2c338: Pull complete
b414b7f29a7d: Pull complete
547bfdd35d62: Pull complete
8353a2ed248c: Pull complete
Digest: sha256:84b5bc2fd15b0f1f5bf78c8c6ee34b6ae5a46ab81be1c2cfa678eea0c6457a46
Status: Downloaded newer image for elasticsearch:7.2.0
docker.io/library/elasticsearch:7.2.0
[root@lvs roles]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.2.0 0efa6a3de177 10 months ago 861MB
查找Elasticsearch启动文件,把Jvm内存的1G改成512m,
[root@lvs roles]# find /var/lib/docker -name jvm.options
/var/lib/docker/overlay2/f71eb89609a63a340a587968d11bdfc01f4deb1461811d2cc9445c69b4ecc3f7/diff/usr/share/elasticsearch/config/jvm.options
[root@lvs roles]# vim /var/lib/docker/overlay2/f71eb89609a63a340a587968d11bdfc01f4deb1461811d2cc9445c69b4ecc3f7/diff/usr/share/elasticsearch/config/jvm.options
[root@lvs roles]# docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.2.0
a3bddb30f86ae0d1986cae3d58c272ae703bfa7402a2797304a2477252ee7e8b
[root@lvs roles]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3bddb30f86a elasticsearch:7.2.0 "/usr/local/bin/dock…" 10 seconds ago Up 9 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
[root@lvs roles]# curl 172.17.0.2:9200
{
"name" : "a3bddb30f86a",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "h-RTgPL8SJGEQBVeAuJ7Rw",
"version" : {
"number" : "7.2.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "508c38a",
"build_date" : "2019-06-20T15:54:18.811730Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
查看集群节点(这里还没有配置集群,介绍一下)
[root@lvs roles]# curl -XGET 'http://172.17.0.2:9200/_cat/nodes?pretty'
172.17.0.2 35 46 0 0.03 0.05 0.04 mdi * a3bddb30f86a
查看集群健康状态
[root@lvs roles]# curl -i -XGET http://172.17.0.2:9200/_cluster/health?pretty
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 467
{
"cluster_name" : "docker-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"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
}
显示green,说明非常健康