Elasticsearch7.4.2 单实例安装

环境:操作系统 centos 6.10 内核2.6

下载地址https://www.elastic.co/cn/downloads/elasticsearch

elasticsearch下载页面

一、安装步骤

这里本人选择的Linux版本的 elasticsearch-7.4.2-linux-x86_64.tar.gz

  • 解压: tar -zxf elasticsearch-7.4.2-linux-x86_64.tar.gz
  • 重命名文件夹: mv elasticsearch-7.4.2 elasticsearch
  • 进入解压目录并查看目录结构:cd elasticsearch && ll
  • 进入config目录并查看目录信息:cd config && ll
  • 修改jvm配置信息: vim jvm.options
  • 修改elastic配置文件: vim elasticsearch.yml
  • 修改数据和日志存放路径:(请根据实际情况进行设置)

path.data: /usr/local/program/elasticsearch/data # 数据目录位置
path.logs: /usr/local/program/elasticsearch/logs # 日志目录位置

  • 设置node名称: node.name: node-1
  • 设置访问地址(这里设置为允许任何ip访问,可以根据实际情况设置为指定ip访问): network.host: 0.0.0.0
  • 设置访问端口: http.port: 9200

二、运行elasticsearch (请确定jdk 1.8以上)

第一次运行./bin/elasticsearch

future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_192-amd64/jre] does not meet this requirement
[2019-11-18T10:53:37,510][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.4.2.jar:7.4.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.4.2.jar:7.4.2]
… 6 more

原因elasticsearch 不能使用 root 用户启动

解决方案:

  • 创建用户组:groupadd elasticsearch
  • 创建用户: useradd es -p elasticsearch
  • 分配权限: chown -R es:elasticsearch /usr/local/program/elasticsearch

第二次运行

  • 切换用户: su es
  • 启动命令: ./bin/elasticsearch

future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_192-amd64/jre] does not meet this requirement
[2019-11-18T11:16:06,182][WARN ][o.e.b.JNANatives ] [node-1] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:342) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:617) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:260) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:113) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:110) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) [elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) [elasticsearch-7.4.2.jar:7.4.2]

原因: 因为Centos6不支持SecComp(centos6,其linux内核版本为2.6。而Elasticsearch的插件要求至少3.5以上版本)而ES默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动 。

解决方案:修改配置文件 vim elasticsearch.yml

  • bootstrap.memory_lock: false
  • bootstrap.system_call_filter: false

第三次运行

  • 切换用户: su es
  • 启动命令: ./bin/elasticsearch

[2019-11-18T12:29:17,957][INFO ][o.e.b.BootstrapChecks ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: 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
[2019-11-18T12:29:17,965][INFO ][o.e.n.Node ] [node-1] stopping …
[2019-11-18T12:29:17,984][INFO ][o.e.n.Node ] [node-1] stopped
[2019-11-18T12:29:17,984][INFO ][o.e.n.Node ] [node-1] closing …
[2019-11-18T12:29:17,997][INFO ][o.e.n.Node ] [node-1] closed
[2019-11-18T12:29:17,999][INFO ][o.e.x.m.p.NativeController] [node-1] Native controller process has stopped – no new native processes can be started

错误原因: 启动检查未通过

  1. 用户的最大线程数太低
  2. 进程虚拟内存太低
  3. 配置项 cluster.initial_master_nodes 没有配置

解决方案:

  1. 修改vim /etc/security/limits.d/90-nproc.conf 将默认值改为4096或更大
  2. 修改vim /etc/sysctl.conf,追加以下内容:vm.max_map_count=655360保存后,执行:sysctl -p
  3. 修改配置文件 vim elasticsearch.yml 取消注释保留一个节点 cluster.initial_master_nodes: [“node-1”]

第四次运行

  • 切换用户: su es
  • 启动命令: ./bin/elasticsearch

终于启动成功!输入测试命令:curl http://127.0.0.1:9200 返回以下信息

发表评论

电子邮件地址不会被公开。 必填项已用*标注