[转帖]elasticsearch 8.0 linux安装部署

济南小老虎 / 2024-01-09 / 原文

1. 下载安装包

https://www.elastic.co/cn/downloads/elasticsearch

选择下载linux版本,elasticsearch-8.0.0-linux-x86_64.tar.gz

2. 系统参数修改

limits.conf和sysctl.conf

  1. vim /etc/security/limits.conf
  2. elastic soft nofile 65536
  3. elastic hard nofile 65536
  4. elastic soft nproc 65536
  5. elastic hard nproc 65536
  6. vim /etc/sysctl.conf
  7. # 添加如下配置
  8. vm.max_map_count=262144
  9. # 执行生效
  10. sysctl -p

3. 新建用户

添加用户并设置密码。

  1. useradd elastic
  2. passwd elastic

如果解压文件是在切换用户以前进行,则可以在创建用户以后,设置目录权限为新建用户。

chown -R elastic:elastic elasticsearch-8.0.0

切换用户名:

su - elastic

4. 解压文件

tar -zxvf elasticsearch-8.0.0-linux-x86_64.tar.gz

5. 配置文件elasticsearch.yml

  1. cluster.name: my-application
  2. node.name: node-1
  3. path.data: /opt/elk/elasticsearch-8.0.0/data
  4. path.logs: /opt/elk/elasticsearch-8.0.0/logs
  5. #开启xpack
  6. xpack.security.enabled: false
  7. xpack.security.transport.ssl.enabled: false
  8. #开启集群中https传输
  9. #xpack.security.transport.ssl.enabled: true
  10. #xpack.security.transport.ssl.verification_mode: certificate
  11. #xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
  12. #xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
  13. #开启api接口https传输,配置HTTP层TLS/SSL加密传输
  14. #xpack.security.http.ssl.enabled: true
  15. #xpack.security.http.ssl.keystore.path: certs/elastic-certificates.p12
  16. #xpack.security.http.ssl.truststore.path: certs/elastic-certificates.p12
  17. #xpack.security.http.ssl.enabled: true
  18. #xpack.security.http.ssl.keystore.path: "certs/http.p12"
  19. #允许跨域
  20. http.cors.enabled: true
  21. http.cors.allow-origin: "*"
  22. http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length

本地测试访问,先不启用https了。

6. 运行服务,浏览器访问

http://localhost:9200/

 可以看到类似下面的信息,表示安装成功

  1. {
  2. "name" : "node-1",
  3. "cluster_name" : "my-application",
  4. "cluster_uuid" : "D7re4bfxTpC",
  5. "version" : {
  6. "number" : "8.0.0",
  7. "build_flavor" : "default",
  8. "build_type" : "tar",
  9. "build_hash" : "1b6a7ece17463df5ff54",
  10. "build_date" : "2022-02-03T16:47:57.507843096Z",
  11. "build_snapshot" : false,
  12. "lucene_version" : "9.0.0",
  13. "minimum_wire_compatibility_version" : "7.17.0",
  14. "minimum_index_compatibility_version" : "7.0.0"
  15. },
  16. "tagline" : "You Know, for Search"
  17. }

7. 常见错误,不能以root运行

启动后出现如下提示,表示elasticsearch不能以root运行。

  1. [2022-03-08T14:52:15,181][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [bogon] uncaught exception in thread [main]
  2. org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root