本地启动ES报错解决

1,506 阅读8分钟

Exception in thread "main" java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release

最近在本地安装ES,启动服务的时候报错

warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release
warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release
Exception in thread "main" java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
	at java.base/java.lang.System.setSecurityManager(System.java:429)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82)        

看起来是jdk自带的类,于是查看elasticsearch安装路径,试图找到绑定jdk的相关配置文件

ll
total 48
-rw-r--r--  1 xiao  admin   1.3K May 25  2022 INSTALL_RECEIPT.json
-rw-r--r--  1 xiao  admin   645B Jan  7  2021 LICENSE.txt
-rw-r--r--  1 xiao  admin   228B Jan  7  2021 NOTICE.txt
-rw-r--r--  1 xiao  admin   7.1K Jan  7  2021 README.asciidoc
drwxr-xr-x  6 xiao  admin   192B May 25  2022 bin
-rw-r--r--  1 xiao  admin   771B May 25  2022 homebrew.mxcl.elasticsearch.plist
drwxr-xr-x  7 xiao  admin   224B May 25  2022 libexec

很遗憾,没有任何配置相关的目录,查看INSTALL_RECEIPT.json

{
  "homebrew_version": "2.7.5-10-g8869208",
  "used_options": [

  ],
  "unused_options": [

  ],
  "built_as_bottle": true,
  "poured_from_bottle": true,
  "installed_as_dependency": false,
  "installed_on_request": true,
  "changed_files": [
    "bin/elasticsearch",
    "bin/elasticsearch-keystore",
    "bin/elasticsearch-plugin",
    "bin/elasticsearch-shard",
    "libexec/bin/elasticsearch-env",
    ".bottle/etc/elasticsearch/elasticsearch.yml",
    ".bottle/etc/elasticsearch/jvm.options",
    "INSTALL_RECEIPT.json",
    "homebrew.mxcl.elasticsearch.plist"
  ],
  "time": 1653489603,
  "source_modified_time": 1609962377,
  "compiler": "clang",
  "aliases": [
    "elasticsearch@7"
  ],
  "runtime_dependencies": [
    {
      "full_name": "openjdk",
      "version": "16.0.2",
      "declared_directly": true
    }
  ]
  ...
  

看到了运行时依赖为openjdk 16, 于是查看openkjdk 中System.java line 429

@Deprecated(since="17", forRemoval=true)
  @CallerSensitive
  public static void setSecurityManager(@SuppressWarnings("removal") SecurityManager sm) {
      if (allowSecurityManager()) {
          var callerClass = Reflection.getCallerClass();
          if (CallersHolder.callers.putIfAbsent(callerClass, true) == null) {
              URL url = codeSource(callerClass);
              final String source;
              if (url == null) {
                  source = callerClass.getName();
              } else {
                  source = callerClass.getName() + " (" + url + ")";
              }
              initialErrStream.printf("""
                      WARNING: A terminally deprecated method in java.lang.System has been called
                      WARNING: System::setSecurityManager has been called by %s
                      WARNING: Please consider reporting this to the maintainers of %s
                      WARNING: System::setSecurityManager will be removed in a future release
                      """, source, callerClass.getName());
          }
          implSetSecurityManager(sm);
      } else {
          // security manager not allowed
          if (sm != null) {
              throw new UnsupportedOperationException(
                  "The Security Manager is deprecated and will be removed in a future release");
          }
      }
  }
  

于是想办法将elasticsearch指向jdk8,查看bin目录下的elasticsearch服务启动脚本

#!/bin/bash
JAVA_HOME="/usr/local/opt/openjdk" exec "/usr/local/Cellar/elasticsearch/7.10.2/libexec/bin/elasticsearch"  "$@"

这里显示的指定了jdk路径,于是复制elasticsearch脚本为elasticsearch_jdk8,并修改如下

!/bin/bash
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home" exec "/usr/local/Cellar/elasticsearch/7.10.2/libexec/bin/elasticsearch"  "$@"

运行elasticsearch_jdk8,elasticsearch服务启动成功。

future versions of Elasticsearch will require Java 11; your Java version from [/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre] does not meet this requirement
warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release
future versions of Elasticsearch will require Java 11; your Java version from [/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre] does not meet this requirement
warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release
[2023-10-10T10:54:54,141][INFO ][o.e.n.Node               ] [3c22fbe33b52] version[7.10.2-SNAPSHOT], pid[87205], build[oss/tar/unknown/2021-01-16T01:34:41.142971Z], OS[Mac OS X/10.16/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_231/25.231-b11]
[2023-10-10T10:54:54,154][INFO ][o.e.n.Node               ] [3c22fbe33b52] JVM home [/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre]
[2023-10-10T10:54:54,155][INFO ][o.e.n.Node               ] [3c22fbe33b52] JVM arguments [-Xshare:auto, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=SPI,JRE, -Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Djava.io.tmpdir=/var/folders/x0/7x8bmzdn5jzdgl__0cfv_sv80000gn/T/elasticsearch-6778907160944274409, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:/usr/local/var/log/elasticsearch/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -XX:MaxDirectMemorySize=536870912, -Des.path.home=/usr/local/Cellar/elasticsearch/7.10.2/libexec, -Des.path.conf=/usr/local/etc/elasticsearch, -Des.distribution.flavor=oss, -Des.distribution.type=tar, -Des.bundled_jdk=false]
[2023-10-10T10:54:54,156][WARN ][o.e.n.Node               ] [3c22fbe33b52] version [7.10.2-SNAPSHOT] is a pre-release version of Elasticsearch and is not suitable for production
[2023-10-10T10:54:55,105][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [aggs-matrix-stats]
[2023-10-10T10:54:55,105][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [analysis-common]
[2023-10-10T10:54:55,106][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [geo]
[2023-10-10T10:54:55,106][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [ingest-common]
[2023-10-10T10:54:55,106][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [ingest-geoip]
[2023-10-10T10:54:55,106][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [ingest-user-agent]
[2023-10-10T10:54:55,107][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [kibana]
[2023-10-10T10:54:55,107][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [lang-expression]
[2023-10-10T10:54:55,107][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [lang-mustache]
[2023-10-10T10:54:55,108][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [lang-painless]
[2023-10-10T10:54:55,108][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [mapper-extras]
[2023-10-10T10:54:55,108][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [parent-join]
[2023-10-10T10:54:55,108][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [percolator]
[2023-10-10T10:54:55,109][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [rank-eval]
[2023-10-10T10:54:55,109][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [reindex]
[2023-10-10T10:54:55,109][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [repository-url]
[2023-10-10T10:54:55,109][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [test-delayed-aggs]
[2023-10-10T10:54:55,110][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] loaded module [transport-netty4]
[2023-10-10T10:54:55,110][INFO ][o.e.p.PluginsService     ] [3c22fbe33b52] no plugins loaded
[2023-10-10T10:54:55,155][INFO ][o.e.e.NodeEnvironment    ] [3c22fbe33b52] using [1] data paths, mounts [[/ (/dev/disk1s1s1)]], net usable_space [14gb], net total_space [233.4gb], types [apfs]
[2023-10-10T10:54:55,155][INFO ][o.e.e.NodeEnvironment    ] [3c22fbe33b52] heap size [989.8mb], compressed ordinary object pointers [true]
[2023-10-10T10:54:55,288][INFO ][o.e.n.Node               ] [3c22fbe33b52] node name [3c22fbe33b52], node ID [w6z4VWpHT_yU__U0ktihHQ], cluster name [elasticsearch_brew], roles [master, remote_cluster_client, data, ingest]
[2023-10-10T10:54:58,291][INFO ][o.e.t.NettyAllocator     ] [3c22fbe33b52] creating NettyAllocator with the following configs: [name=unpooled, suggested_max_allocation_size=1mb, factors={es.unsafe.use_unpooled_allocator=null, g1gc_enabled=false, g1gc_region_size=0b, heap_size=989.8mb}]
[2023-10-10T10:54:58,368][INFO ][o.e.d.DiscoveryModule    ] [3c22fbe33b52] using discovery type [zen] and seed hosts providers [settings]
[2023-10-10T10:54:58,611][WARN ][o.e.g.DanglingIndicesState] [3c22fbe33b52] gateway.auto_import_dangling_indices is disabled, dangling indices will not be automatically detected or imported and must be managed manually
[2023-10-10T10:54:58,767][INFO ][o.e.n.Node               ] [3c22fbe33b52] initialized
[2023-10-10T10:54:58,767][INFO ][o.e.n.Node               ] [3c22fbe33b52] starting ...
[2023-10-10T10:54:58,914][INFO ][o.e.t.TransportService   ] [3c22fbe33b52] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2023-10-10T10:54:59,081][WARN ][o.e.b.BootstrapChecks    ] [3c22fbe33b52] the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2023-10-10T10:54:59,083][INFO ][o.e.c.c.Coordinator      ] [3c22fbe33b52] cluster UUID [lRlLTrQDROu6kvtubEwWjg]
[2023-10-10T10:54:59,092][INFO ][o.e.c.c.ClusterBootstrapService] [3c22fbe33b52] no discovery configuration found, will perform best-effort cluster bootstrapping after [3s] unless existing master is discovered
[2023-10-10T10:54:59,197][INFO ][o.e.c.s.MasterService    ] [3c22fbe33b52] elected-as-master ([1] nodes joined)[{3c22fbe33b52}{w6z4VWpHT_yU__U0ktihHQ}{OAD5TqFnT7iXJH1W2NAuhA}{127.0.0.1}{127.0.0.1:9300}{dimr} elect leader, _BECOME_MASTER_TASK_, _FINISH_ELECTION_], term: 2, version: 3, delta: master node changed {previous [], current [{3c22fbe33b52}{w6z4VWpHT_yU__U0ktihHQ}{OAD5TqFnT7iXJH1W2NAuhA}{127.0.0.1}{127.0.0.1:9300}{dimr}]}
[2023-10-10T10:54:59,235][INFO ][o.e.c.s.ClusterApplierService] [3c22fbe33b52] master node changed {previous [], current [{3c22fbe33b52}{w6z4VWpHT_yU__U0ktihHQ}{OAD5TqFnT7iXJH1W2NAuhA}{127.0.0.1}{127.0.0.1:9300}{dimr}]}, term: 2, version: 3, reason: Publication{term=2, version=3}
[2023-10-10T10:54:59,265][INFO ][o.e.h.AbstractHttpServerTransport] [3c22fbe33b52] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2023-10-10T10:54:59,266][INFO ][o.e.n.Node               ] [3c22fbe33b52] started
[2023-10-10T10:54:59,267][INFO ][o.e.g.GatewayService     ] [3c22fbe33b52] recovered [0] indices into cluster_state
[2023-10-10T10:55:29,277][WARN ][o.e.c.r.a.DiskThresholdMonitor] [3c22fbe33b52] high disk watermark [90%] exceeded on [w6z4VWpHT_yU__U0ktihHQ][3c22fbe33b52][/usr/local/var/lib/elasticsearch/nodes/0] free: 14gb[6%], shards will be relocated away from this node; currently relocating away shards totalling [0] bytes; the node is expected to continue to exceed the high disk watermark when these relocations are complete

浏览器输入http://localhost:9200 测试连通性,返回

{
  "name" : "3c22fbe33b52",
  "cluster_name" : "elasticsearch_brew",
  "cluster_uuid" : "lRlLTrQDROu6kvtubEwWjg",
  "version" : {
    "number" : "7.10.2-SNAPSHOT",
    "build_flavor" : "oss",
    "build_type" : "tar",
    "build_hash" : "unknown",
    "build_date" : "2021-01-16T01:34:41.142971Z",
    "build_snapshot" : true,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

问题解决。