最新版ELK8.8.2安装部署

前言:
这是一个运维小白的工作记录,目前开发查看日志,有的使用阿里云的sls,有的使用我们部署的finderweb。突然有一天呢考虑到阿里云的sls有点贵,是不是可以自己部署elk来省下这些钱。所以搭建了一个单机的elk进行测试。但是后来使用中发现,目前对日志保存时间要求有点高,随便挑了四个服务出来统计了一下,日志保存30天都要2T。还要考虑机器的IO问题。所以使用ELK替换sls的工作又在此止步了。不知道有没有大佬指点一二。我觉得只看日志的话,finderweb挺好用的。
下面是ELK的单机安装部署的步骤,供大家参考。

一、ELK组件

Elasticsearch : 接收搜集的海量结构化日志数据,并提供给Kibana查询分析。
Logstash : 对日志进行过滤形成结构化数据,并转发到Elasticsearch中。
Kibana : 对Elasticsearch提供的数据进行分析展示。
filebeat : 用于收集日志

组件下载:
https://www.elastic.co/cn/downloads/elasticsearch
https://www.elastic.co/cn/downloads/kibana
https://www.elastic.co/cn/downloads/logstash
https://www.elastic.co/cn/downloads/beats/filebeat

本文档用的当时最新的版本8.8.2:
elasticsearch-8.8.2-linux-x86_64.tar.gz
logstash-8.8.2-linux-x86_64.tar.gz
filebeat-8.8.2-linux-x86_64.tar.gz
kibana-8.8.2-linux-x86_64.tar.gz

二、Elasticsearch安装

1、创建es用户
useradd es
passwd es

2、解压并修改所属用户
tar -zxvf elasticsearch-8.8.2-linux-x86_64.tar.gz -C /home/es
chown -R es:es /home/es/elasticsearch-8.8.2

3、初始化启动
在正式安装前可以启动一下,es会自动生成一些文件和配置,方便安装
首次启动 Elasticsearch 时,会自动进行以下安全配置:

  • 为传输层和 HTTP 层生成 TLS 证书和密钥。
  • TLS 配置设置被写入elasticsearch.yml
  • 为 elastic 用户生成密码。
  • 为 Kibana 生成一个注册令牌。

cd /home/es/elasticsearch-8.8.2
./bin/elasticsearch

8.x的版本启动后会有一下信息输出:

✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

# ES为我们生成的elastic账户的默认密码,重要,需要复制记下来
ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  BYqaCRcJsCKWi_iiNC3S

# CA证书的密钥信息,暂时先不管
ℹ️  HTTP CA certificate SHA-256 fingerprint:
  8afa029edf9178b5bbaf4d8cf94be8db99470515d96a2de8a79e7930c4d53404

# ES为Kibana生成的访问令牌,Kibana访问ES服务需要用到。(有效期为 30 分钟)
ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjguMiIsImFkciI6WyIxOTIuMTY4LjEuMjA2OjkyMDAiXSwiZmdyIjoiOGFmYTAyOWVkZjkxNzhiNWJiYWY0ZDhjZjk0YmU4ZGI5OTQ3MDUxNWQ5NmEyZGU4YTc5ZTc5MzBjNGQ1MzQwNCIsImtleSI6InBfckFJNGtCM01mVG5XWl91Q1FPOjhGTVJmX0tEUkdlYUtRMzg0WE1PQkEifQ==

# ES位其他节点加入集群生成的访问令牌,当前集群中需要加入新节点时,需要携带此令牌(有效期为 30 分钟)
ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.

4、修改默认密码
因为启动生成的默认密码不方便记忆,所以进行修改
在es服务启动的情况下,修改密码
cd /home/es/elasticsearch-8.8.2
修改elastic的密码,用于登录elastic
./bin/elasticsearch-reset-password -u elastic -i
修改elastic的密码,用于登录kibana
./bin/elasticsearch-reset-password -u kibana -i

5、验证服务
8.x默认开启了ssl,后面配置会关掉,这里使用https访问
https://ip:9200/
输入账号密码,登录成功即可

验证后,杀掉第一次启动的es进程,进行接下来的配置安装
image.png

6、修改es配置文件
cd /home/es/elasticsearch-8.8.2
vi ./config/elasticsearch.yml
修改后的配置如下:

#集群名字,目前是单节点
cluster.name: elk
#节点名
node.name: node-1
path.data: /home/es/elasticsearch-8.8.2/data
path.logs: /home/es/elasticsearch-8.8.2/logs
#不锁定jvm内存
bootstrap.memory_lock: false
#配置可进行数据交互的ip
network.host: 0.0.0.0
#允许http跨域访问,es_head插件必须开启
http.cors.enabled: true
http.cors.allow-origin: "*"

#es_head连接时读取用户名密码
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

# 开启安全认证 , 本机测试可以使用关闭了安全验证,生产建议开启 
# 由于ES 8.x的安全模块启用后集群的搭建和kibana需要证书验证才可以,因此此处不建议开启
#	下面也会书写开启安全验证后配置
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
	#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
#主节点
cluster.initial_master_nodes: ["node-1"]
http.host: 0.0.0.0

7、启动
./bin/elasticsearch -d

8、验证
访问http://ip:9200
开启了ssl访问:https://ip:9200
image.png

三、Kibana安装

Kibana依赖es,安装Kibana请确保es服务没问题

1、解压
tar -zxvf kibana-8.8.2-linux-x86_64.tar.gz -C /home/es
cd /home/es/kibana-8.8.2

由于我们未启用security ,kibana启动非常简单, 简单配置如下:


server.port: 5601
server.host: 你的IP
# 连接es,账号密码在安装es的时候配置过了
elasticsearch.hosts: ["http://你的IP:9200"]
elasticsearch.username: "kibana"
elasticsearch.password: "wlk_123"

# 设置成中文
i18n.locale: "zh-CN"

若启用了安全模式
修改yml,不需要配置链接的es

server.port: 5601
server.host: 你的IP

nohup ./bin/kibana &

启动后访问IP:5601
会看到如下页面
将启动es时生产的token填写进去
因为token有时间限制。可通过命令重新生产
./elasticsearch-create-enrollment-token -s kibana
image.png

然后使用es的账号密码登录即可
2、启动
nohup ./bin/kibana &

3、http://你的IP:5601即可登陆

四、Logstash安装

1、解压
tar -zxvf logstash-8.8.2-linux-x86_64.tar.gz -C /home/es

2、修改配置
cd /home/es/logstash-8.8.2
vi ./config/logstash-sample.conf

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["http://192.168.1.236:9200"]
    index => "elklog-%{+YYYY.MM.dd}"
    user => "elastic"
    password => "wlk_123"
  }
}

若es开启了ssl,则使用如下配置

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
      hosts => ["https://127.0.0.1:9200"]
      index => "kernel-hypt1-%{+YYYY.MM.dd}"
    	#需要添加证书
      cacert => "/home/es/elasticsearch-8.8.2/config/certs/http_ca.crt"
      user => "elastic"
      password => "密码"
  }
}

3、启动
cd /home/es/logstash-8.8.2
nohup ./bin/logstash -f ./config/logstash-sample.conf &

可以自动检测配置文件的变动和自动重新加载配置文件默认3秒 --config.reload.automatic
nohup ./bin/logstash -f ./config/logstash-sample.conf --config.reload.automatic 10 &

五、filebeat安装

安装在需要被收集日志的服务器

1、解压
tar -zxvf filebeat-8.8.2-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/filebeat-8.8.2

2、修改配置
vim filebeat.yml

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

# filestream is an input for collecting log messages from files.
- type: filestream

  # Unique ID among all inputs, an ID is required.
  id: my-filestream-id

  # Change to true to enable this input configuration.
  enabled: ture

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /home/buybal/tomcat/wlkv1/logs/catalina.out
    #- c:\programdata\elasticsearch\logs\*
	fields:
    filetype: elklog



# ------------------------------ Logstash Output -------------------------------
output.logstash:
  # The Logstash hosts
  hosts: ["192.168.1.236:5044"]

  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

filebeat.inputs 可以配置多个,通过filetype来区分不同的日志
同样logstash可以通过filetype来区分不同的日志,在es内创建不同的索引
输出到Logstash 配置连接方式即可

3、启动
cd /usr/local/filebeat-8.8.2
nohup ./filebeat -e -c ./filebeat.yml &

4、修改配置文件,自动加载配置
开启自动加载配置文件后,修改配置文件就不需要在重启啦
修改配置文件
vim filebeat.yml
添加如下配置


filebeat.config.inputs:
  path: /usr/local/filebeat/config/*.yml

  reload.enabled: true

  reload.period: 10s

创建日志收集配置
vim /usr/local/filebeat/config/input.yml

- type: log

  id: tyzf

  enabled: true

  paths:
    - /home/buybal/tomcat/tongyizhifu-8085/logs/*.out

  fields:
    filetype: tyzf
  fields_under_root: true


- type: log

  id: reload

  enabled: true

  paths:
    - /home/*.out

  fields:
    filetype: reload
  fields_under_root: true
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值