10、升级ES-7.8.0的log4j版本

背景

由于低版本的 log4j 存在严重漏洞,不同组件自带的 log4j 则要升级到指定版本(2.17.1),最近升级 ES-7.8.0 的 log4j 版本,特此记录一下。

操作步骤

1、升级 jar 包准备,去 apache 官网下载对应版本。

2、先终止服务器上的 ES 服务,kill -9 进程号。

3、使用 find 命令,查找 ES 安装目录下存在的 log4 j的 jar 包,如下:

[xxw@123456 es]$ find ./elasticsearch-7.8.0/ -name 'log4j*.jar'
./elasticsearch-7.8.0/modules/x-pack-identity-provider/log4j-slf4j-impl-2.11.1.jar
./elasticsearch-7.8.0/modules/x-pack-security/log4j-slf4j-impl-2.11.1.jar
./elasticsearch-7.8.0/modules/x-pack-core/log4j-1.2-api-2.11.1.jar
./elasticsearch-7.8.0/lib/log4j-core-2.11.1.jar
./elasticsearch-7.8.0/lib/log4j-api-2.11.1.jar

4、移动这些jar包到临时的备份目录(出现意外时可回滚这些文件)。

5、将新jar包对应替换,这里将 2.11.1 替换成 2.17.1 版本,如下:

cp log4j-slf4j-impl-2.17.1.jar ./elasticsearch-7.8.0/modules/x-pack-identity-provider/
cp log4j-slf4j-impl-2.17.1.jar ./elasticsearch-7.8.0/modules/x-pack-security/
cp log4j-1.2-api-2.17.1.jar ./elasticsearch-7.8.0/modules/x-pack-core/
cp log4j-core-2.17.1.jar ./elasticsearch-7.8.0/lib/
cp log4j-api-2.17.1.jar ./elasticsearch-7.8.0/lib/

6、替换之后,使用 find 命令确认是否替换完成,如下:

[xxw@123456 es]$ find ./elasticsearch-7.8.0/ -name 'log4j*.jar'
./elasticsearch-7.8.0/modules/x-pack-identity-provider/log4j-slf4j-impl-2.17.1.jar
./elasticsearch-7.8.0/modules/x-pack-security/log4j-slf4j-impl-2.17.1.jar
./elasticsearch-7.8.0/modules/x-pack-core/log4j-1.2-api-2.17.1.jar
./elasticsearch-7.8.0/lib/log4j-core-2.17.1.jar
./elasticsearch-7.8.0/lib/log4j-api-2.17.1.jar

7、最后,重启 ES 服务,并进行验证 ES 服务是否正常运行。

ES启动方式有以下两种:

  • 窗口启动:./elasticsearch-7.8.0/bin/elasticsearch
  • 后台启动:./elasticsearch-7.8.0/bin/elasticsearch -d

查看进程验证:jps 或 ps -ef|grep elasticsearch

发送请求验证:curl http://宿主机IP:配置端口号/

[xxx@123456 es]$ curl http://10.129.40.16:9200/
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iHwx-eIsTxinhm4sY-S7_A",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

遇到的问题

1. 使用 find 命令报错,如下:

[xxw@123456 es]$ find ./elasticsearch-7.8.0/ -name "log4j*.jar"
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

解决办法:查找多文件时需要使用单引号,而不是双引号。

2. 官网找不到需要的 2.17.1 版本的 jar 包?

去这里,Index of /dist/logging/log4j

猜你喜欢

转载自blog.csdn.net/qq_29119581/article/details/130313497
今日推荐