elasticsearch cluster 开启用户名+密码

分手后的思念是犯贱 2022-09-09 13:45 371阅读 0赞

当前目录:/home/es/elasticsearch-7.13.4
在这里插入图片描述

docker-compose.yml

  1. ---
  2. version: '2.2'
  3. services:
  4. elasticsearch:
  5. restart: always
  6. image: elasticsearch:7.13.4
  7. container_name: es-node1
  8. network_mode: host
  9. volumes:
  10. - /data/es/data:/usr/share/elasticsearch/data
  11. - /home/es/elasticsearch-7.13.4/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  12. - /home/es/elasticsearch-7.13.4/config/jvm.options:/usr/share/elasticsearch/config/jvm.options
  13. - /home/es/elasticsearch-7.13.4/config/es.pem:/usr/share/elasticsearch/config/es.pem
  14. - /home/es/elasticsearch-7.13.4/config/es-key.pem:/usr/share/elasticsearch/config/es-key.pem
  15. environment:
  16. bootstrap.memory_lock: "true"
  17. ulimits:
  18. memlock:
  19. soft: -1
  20. hard: -1

elasticsearch.yml

  1. cluster.name: jiankunking-log
  2. node.name: 10.163.16.188
  3. http.port: 9200
  4. transport.tcp.port: 8100
  5. discovery.seed_hosts: ["10.163.16.188","10.163.16.190","10.163.16.191"]
  6. cluster.initial_master_nodes: ["10.163.16.188","10.163.16.190","10.163.16.191"]
  7. network.bind_host: 10.163.16.188
  8. network.publish_host: 10.163.16.188
  9. path:
  10. data:
  11. - /usr/share/elasticsearch/data
  12. xpack.monitoring.collection.enabled: true
  13. xpack.security.enabled: true
  14. xpack.security.http.ssl.enabled: false
  15. xpack.security.http.ssl.key: /usr/share/elasticsearch/config/es-key.pem
  16. xpack.security.http.ssl.certificate: /usr/share/elasticsearch/config/es.pem
  17. xpack.security.http.ssl.certificate_authorities: ["/usr/share/elasticsearch/config/es.pem"]
  18. xpack.security.transport.ssl.enabled: true
  19. # 这里也可以指定为证书
  20. xpack.security.transport.ssl.verification_mode: none
  21. xpack.security.transport.ssl.key: /usr/share/elasticsearch/config/es-key.pem
  22. xpack.security.transport.ssl.certificate: /usr/share/elasticsearch/config/es.pem
  23. xpack.security.transport.ssl.certificate_authorities: ["/usr/share/elasticsearch/config/es.pem"]

jvm.options

  1. ################################################################
  2. ##
  3. ## JVM configuration
  4. ##
  5. ################################################################
  6. ##
  7. ## WARNING: DO NOT EDIT THIS FILE. If you want to override the
  8. ## JVM options in this file, or set any additional options, you
  9. ## should create one or more files in the jvm.options.d
  10. ## directory containing your adjustments.
  11. ##
  12. ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
  13. ## for more information.
  14. ##
  15. ################################################################
  16. ################################################################
  17. ## IMPORTANT: JVM heap size
  18. ################################################################
  19. ##
  20. ## The heap size is automatically configured by Elasticsearch
  21. ## based on the available memory in your system and the roles
  22. ## each node is configured to fulfill. If specifying heap is
  23. ## required, it should be done through a file in jvm.options.d,
  24. ## and the min and max should be set to the same value. For
  25. ## example, to set the heap to 4 GB, create a new file in the
  26. ## jvm.options.d directory containing these lines:
  27. -Xms31g
  28. -Xmx31g
  29. ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
  30. ## for more information
  31. ##
  32. ################################################################
  33. ################################################################
  34. ## Expert settings
  35. ################################################################
  36. ##
  37. ## All settings below here are considered expert settings. Do
  38. ## not adjust them unless you understand what you are doing. Do
  39. ## not edit them in this file; instead, create a new file in the
  40. ## jvm.options.d directory containing your adjustments.
  41. ##
  42. ################################################################
  43. ## GC configuration
  44. 8-13:-XX:+UseConcMarkSweepGC
  45. 8-13:-XX:CMSInitiatingOccupancyFraction=75
  46. 8-13:-XX:+UseCMSInitiatingOccupancyOnly
  47. ## G1GC Configuration
  48. # NOTE: G1 GC is only supported on JDK version 10 or later
  49. # to use G1GC, uncomment the next two lines and update the version on the
  50. # following three lines to your version of the JDK
  51. # 10-13:-XX:-UseConcMarkSweepGC
  52. # 10-13:-XX:-UseCMSInitiatingOccupancyOnly
  53. 14-:-XX:+UseG1GC
  54. ## JVM temporary directory
  55. -Djava.io.tmpdir=${ES_TMPDIR}
  56. ## heap dumps
  57. # generate a heap dump when an allocation from the Java heap fails; heap dumps
  58. # are created in the working directory of the JVM unless an alternative path is
  59. # specified
  60. -XX:+HeapDumpOnOutOfMemoryError
  61. # specify an alternative path for heap dumps; ensure the directory exists and
  62. # has sufficient space
  63. -XX:HeapDumpPath=data
  64. # specify an alternative path for JVM fatal error logs
  65. -XX:ErrorFile=logs/hs_err_pid%p.log
  66. ## JDK 8 GC logging
  67. 8:-XX:+PrintGCDetails
  68. 8:-XX:+PrintGCDateStamps
  69. 8:-XX:+PrintTenuringDistribution
  70. 8:-XX:+PrintGCApplicationStoppedTime
  71. 8:-Xloggc:logs/gc.log
  72. 8:-XX:+UseGCLogFileRotation
  73. 8:-XX:NumberOfGCLogFiles=32
  74. 8:-XX:GCLogFileSize=64m
  75. # JDK 9+ GC logging
  76. 9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

证书

es-key.pem 自签名的私钥
es.pem 自签名的证书

证书有效时间,尽量长一些
如果该集群后面要加入remote cluster的话,证书的签名CA要一样。

重启

关掉集群 分片 自动分配设置

  1. PUT /_cluster/settings
  2. {
  3. "transient": {
  4. "cluster.routing.allocation.enable": "none"
  5. }
  6. }

修改配置重启所有节点

  1. docker-compose stop
  2. docker-compose up -d --build

等最后一个节点起来后,进入容器执行

  1. ./bin/elasticsearch-setup-passwords interactive

设置对应账号名的密码即可。

重新开启集群 分片 自动分配

  1. PUT /_cluster/settings
  2. {
  3. "persistent": {
  4. "cluster.routing.allocation.enable": "all"
  5. }
  6. }

发表评论

表情:
评论列表 (有 0 条评论,371人围观)

还没有评论,来说两句吧...

相关阅读