ELK安装(Elasticsearch+Logstash+Kibana+Filebeat)

一、简介

1.1、软件简介

ELK其实是Elasticsearch,Logstash 和 Kibana三个产品的首字母缩写,这三款都是开源产品。

1.1.1、Elasticsearch简介

Elasticsearch 是一个分布式、高扩展、高实时的搜索与数据分析引擎。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用Elasticsearch的水平伸缩性,能使数据在生产环境变得更有价值。Elasticsearch 的实现原理主要分为以下几个步骤,首先用户将数据提交到Elasticsearch 数据库中,再通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据,当用户搜索数据时候,再根据权重将结果排名,打分,再将返回结果呈现给用户。

1.1.2、Logstash简介

Logstash是基于过滤器/管道模式的工具,用于收集,处理和生成日志或事件。它有助于集中和实时分析来自不同来源的日志和事件。

Logstash是用在JVM上运行的JRuby编程语言编写的,因此您可以在不同的平台上运行Logstash。它几乎从每种类型的源中收集不同类型的数据,例如日志,数据包,事件,事务,时间戳数据等。数据源可以是社交数据,电子商务,新闻文章,CRM,游戏数据,Web趋势,金融数据,物联网,移动设备等。

1.1.3、Kibana简介

Kibana是一个开源的分析与可视化平台,设计出来用于和Elasticsearch一起使用的。你可以用kibana搜索、查看、交互存放在Elasticsearch索引里的数据,使用各种不同的图表、表格、地图等kibana能够很轻易地展示高级数据分析与可视化。

Kibana让我们理解大量数据变得很容易。它简单、基于浏览器的接口使你能快速创建和分享实时展现Elasticsearch查询变化的动态仪表盘。安装Kibana非常快,你可以在几分钟之内安装和开始探索你的Elasticsearch索引数据,不需要写任何代码,没有其他基础软件依赖。

1.1.4、Filebeat简介

Filebeat是一个轻量级的托运器,用于转发和集中日志数据。Filebeat作为代理安装在您的服务器上,监视您指定的日志文件或位置,收集日志事件,并将其转发到Elasticsearch或Logstash进行索引

1.2、架构简介

大概就是Filebeat收集应用服务器的日志转给Logstash收集、解析之后将数据发送给Elasticsearch,然后Kibana将之展示出来。
至于为什么用了一个Filebeat了,就是因为其比较轻量,但收集日志又完全OK!所以将Logstash分离出来,Logstash安装插件的时候就比较简单了,不需要每台都安装,节省了资源提高了效率
在这里插入图片描述

二、环境准备

2.1、软件下载

去这个网站找啊!

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.14.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/logstash/logstash-8.14.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.14.3-linux-x86_64.tar.gz

2.2、java环境安装

下载安装jdk

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
yum -y install ./jdk-17_linux-x64_bin.rpm

修改环境变量

vim /etc/profile
export JAVA_HOME=/usr/java/jdk-17
export PATH=$JAVA_HOME/bin:$PATH

刷新环境变量,使之生效

source /etc/profile

查看Java环境

java -version

在这里插入图片描述

三、Elasticsearch

安装配置参考官方链接

3.1、安装

cd /home/local
tar -xvzf elasticsearch-8.14.3-linux-x86_64.tar.gz

3.2、修改配置文件

vim elasticsearch-8.14.3/config/elasticsearch.yml
cluster.name: elk-application
node.name: node-1
path.data: /home/local/elasticsearch-8.14.3/data
path.logs: /home/local/elasticsearch-8.14.3/logs
network.host: 10.10.30.34
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12

/home/local]# cat elasticsearch-8.14.3/config/elasticsearch.yml |grep -v ^# | grep -v ^$

在这里插入图片描述

3.3、修改jvm

vim elasticsearch-8.14.3/config/jvm.options
-Xms4g
-Xmx4g
-XX:+UseG1GC
-Djava.io.tmpdir=${ES_TMPDIR}
20-:--add-modules=jdk.incubator.vector
-XX:+HeapDumpOnOutOfMemoryError
-XX:+ExitOnOutOfMemoryError
-XX:HeapDumpPath=data
-XX:ErrorFile=logs/hs_err_pid%p.log
-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,level,pid,tags:filecount=32,filesize=64m
cat elasticsearch-8.14.3/config/jvm.options |grep -v ^# | grep -v ^$

在这里插入图片描述

3.4、修改环境参数

修改连接数和文件数
临时生效ulimit -n 65535
永久生效

vim /etc/security/limits.conf
elastic  -  nofile  65535
elastic  -  noproc  65535

修改虚拟内存
临时生效:sysctl -w vm.max_map_count=262144
永久生效

vim /etc/sysctl.conf
vm.max_map_count=262144

3.5、启动

Elasticsearch不能使用root用户启动

3.5.1、命令启动
useradd elastic
passwd elastic
chown -R elastic:elastic /home/local/elasticsearch-8.14.3
su - elastic
/home/local/elasticsearch-8.14.3/bin/elasticsearch -d
3.5.2、服务启动
vim /lib/systemd/system/elasticsearch.service
[Unit]
Description=elasticsearch
Wants=network-online.target
After=network-online.target

[Service]
User=elastic
ExecStart=/home/local/elasticsearch-8.14.3/bin/elasticsearch -d
PrivateTmp=true
# 指定此进程可以打开的最大文件数
LimitNOFILE=65535
# 指定此进程可以打开的最大进程数
LimitNPROC=65535
# 最大虚拟内存
LimitAS=infinity
# 最大文件大小
LimitFSIZE=infinity
# 超时设置 0-永不超时
TimeoutStopSec=0
# SIGTERM是停止java进程的信号
KillSignal=SIGTERM
# 信号只发送给给JVM
KillMode=process
# java进程不会被杀掉
SendSIGKILL=no
# 正常退出状态
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
#加载服务
systemctl daemon-reload
#开机自启
systemctl enable elasticsearch
#启动服务
systemctl start  elasticsearch
#关闭服务
systemctl stop  elasticsearch
#重启服务
systemctl restart  elasticsearch
#查看状态
systemctl status elasticsearch
#查看日志
journalctl  -f -u elasticsearch

3.6、验证

3.6.1、访问页面
curl -I http://10.10.30.34:9200/

在这里插入图片描述

3.6.2、查看进程
ps -ef | grep elasticsearch

在这里插入图片描述

3.6.3、服务状态
systemctl status elasticsearch

在这里插入图片描述

四、Logstash

4.1、安装

tar -xzvf logstash-8.14.3-linux-x86_64.tar.gz

4.2、配置

vim logstash-8.14.3/config/logstash-sample.conf
input {
  beats {
    port => 5044
  }
}
output {
 if "mes3-log" in [tags] {
  elasticsearch {
    hosts => ["http://10.10.30.34:9200"]
    index => "[mes3-log]-%{+YYYY.MM.dd}"
  }
 }
}
cat logstash-8.14.3/config/logstash-sample.conf | grep -v ^# | grep -v ^$

在这里插入图片描述

4.3、启动

4.3.1、命令启动
chown -R elastic:elastic /home/local/logstash-8.14.3
su - elastic
nohup /home/local/logstash-8.14.3/bin/logstash -f /home/local/logstash-8.14.3/config/logstash-sample.conf &
4.3.2、服务启动
vim /lib/systemd/system/logstash.service
[Unit]
Description=logstash
Wants=network-online.target
After=network-online.target

[Service]
User=elastic
ExecStart=/home/local/logstash-8.14.3/bin/logstash -f /home/local/logstash-8.14.3/config/logstash-sample.conf
# 设置为掉线自动重启,进程强制杀掉后会自动重新启动
Restart=always

[Install]
WantedBy=multi-user.target
#加载服务
systemctl daemon-reload
#开机自启
systemctl enable logstash
#启动服务
systemctl start  logstash
#关闭服务
systemctl stop  logstash
#重启服务
systemctl restart  logstash
#查看状态
systemctl status logstash
#查看日志
journalctl  -f -u logstash

4.4、验证

进程查看

ps -ef | grep logstash

在这里插入图片描述
服务状态

systemctl status logstash

在这里插入图片描述

五、Kibana

5.1、安装

tar xvzf kibana-8.14.3-linux-x86_64.tar.gz

5.2、配置

vim kibana-8.14.3/config/kibana.yml
server.port: 5601
server.host: "10.10.30.34"
server.name: "myshell"
elasticsearch.hosts: ["http://10.10.30.34:9200"]

cat kibana-8.14.3/config/kibana.yml | grep -v ^# | grep -v ^$

在这里插入图片描述

5.3、启动

5.3.1、命令启动
chown -R  elastic:elastic kibana-8.14.3
su - elastic
nohup /home/local/kibana-8.14.3/bin/kibana &
5.3.2、服务启动
vim /lib/systemd/system/kibana.service
[Unit]
Description=kibana
Wants=network-online.target
After=network-online.target

[Service]
User=elastic
ExecStart=/home/local/kibana-8.14.3/bin/kibana
# 设置为掉线自动重启,进程强制杀掉后会自动重新启动
Restart=always

[Install]
WantedBy=multi-user.target
#加载服务
systemctl daemon-reload
#开机自启
systemctl enable kibana
#启动服务
systemctl start  kibana
#关闭服务
systemctl stop  kibana
#重启服务
systemctl restart  kibana
#查看状态
systemctl status kibana
#查看日志
journalctl  -f -u kibana

5.4、验证

5.4.1、网页验证
curl -I http://10.10.30.34:5601

在这里插入图片描述

5.4.2、进程查看
ps -ef | grep kibana

在这里插入图片描述
5.4.3、服务状态

systemctl status kibana

在这里插入图片描述

六、Filebeat

6.1、安装

tar xvzf filebeat-8.14.3-linux-x86_64.tar.gz

6.2、配置

vim /home/local/filebeat-8.14.3-linux-x86_64/filebeat.yml
filebeat.inputs:
- type: filestream
  id: filestream-2-3
  enabled: true
  paths:
    - /var/lib/docker/containers/67eafd4ef65765ea5c6cec77dccbb357764a984de9cc1c21c7131688d3cc3bf3/*.log
    - /var/log/*.log
  tags: ["mes3-log"]
  exclude_lines: ['^$']
  multiline:
    type: pattern
    pattern: '^[0-9]{4}-[0-9]{4}-[0-9]{2}'
    negate: true
    match: after
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
setup.template.settings:
  index.number_of_shards: 1
setup.kibana:
output.logstash:
  hosts: ["10.10.30.34:5044"]
processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~
seccomp:
  default_action: allow 
  syscalls:
  - action: allow
    names:
    - rseq

cat  /home/local/filebeat-8.14.3-linux-x86_64/filebeat.yml | grep -v ^# | grep -v ^$ | grep -v '#'

在这里插入图片描述

6.3、启动

直接使用命令启动

nohup /home/local/filebeat-8.14.3-linux-x86_64/filebeat -e -c /home/local/filebeat-8.14.3-linux-x86_64/filebeat.yml &

整成服务

vim /lib/systemd/system/filebeat.service
[Unit]
Description=filebeat
Wants=network-online.target
After=network-online.target

[Service]
User=root
ExecStart=/home/local/filebeat-8.14.3-linux-x86_64/filebeat -e -c /home/local/filebeat-8.14.3-linux-x86_64/filebeat.yml
# 设置为掉线自动重启,进程强制杀掉后会自动重新启动
Restart=always

[Install]
WantedBy=multi-user.target
#加载服务
systemctl daemon-reload
#开机自启
systemctl enable filebeat
#启动服务
systemctl start  filebeat
#关闭服务
systemctl stop  filebeat
#重启服务
systemctl restart  filebeat
#查看状态
systemctl status filebeat
#查看日志
journalctl  -f -u filebeat

6.4、验证

查看进程

ps -ef | grep filebeat

在这里插入图片描述
查看服务状态

systemctl status filebeat

在这里插入图片描述

七、Kibana网页配

7.1、Index Management

在这里插入图片描述

7.2、Data Views

在这里插入图片描述

7.3、Discover

在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值