通过Docker部署Elasticsearch集群

忘是亡心i 2023-03-13 09:16 98阅读 0赞

以7.6.2为例

Elasticsearch

挂载

在宿主机上创建Elasticsearch的数据存储、config配置目录
eg:

  1. 数据存储:
  2. mkdir /data/es/data-b
  3. 配置文件
  4. mkdir /home/es/elasticsearch-7.6.2/config

新建用户 adduser es
数据存储需要赋予权限:sudo chown -R 1000:1000 /data/es/data-b

Elasticsearch配置

在/home/es/elasticsearch-7.6.2/config文件夹下新建elasticsearch.yml、 jvm.options

具体内容可以参考:
elasticsearch.yml

  1. cluster.name: business-log
  2. node.name: es-b-188
  3. http.port: 9201
  4. transport.tcp.port: 9301
  5. discovery.seed_hosts: ["10.133.0.188","10.133.0.190","10.133.0.191"]
  6. cluster.initial_master_nodes: ["10.133.0.188","10.133.0.190","10.133.0.191"]
  7. network.bind_host: 10.133.0.188
  8. network.publish_host: 10.133.0.188

jvm.options

  1. ## JVM configuration
  2. ################################################################
  3. ## IMPORTANT: JVM heap size
  4. ################################################################
  5. ##
  6. ## You should always set the min and max JVM heap
  7. ## size to the same value. For example, to set
  8. ## the heap to 4 GB, set:
  9. ##
  10. ## -Xms4g
  11. ## -Xmx4g
  12. ##
  13. ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
  14. ## for more information
  15. ##
  16. ################################################################
  17. # Xms represents the initial size of total heap space
  18. # Xmx represents the maximum size of total heap space
  19. -Xms26g
  20. -Xmx26g
  21. ################################################################
  22. ## Expert settings
  23. ################################################################
  24. ##
  25. ## All settings below this section are considered
  26. ## expert settings. Don't tamper with them unless
  27. ## you understand what you are doing
  28. ##
  29. ################################################################
  30. ## GC configuration
  31. #-XX:+UseConcMarkSweepGC
  32. #-XX:CMSInitiatingOccupancyFraction=75
  33. #-XX:+UseCMSInitiatingOccupancyOnly
  34. ## G1GC Configuration
  35. # NOTE: G1GC is only supported on JDK version 10 or later.
  36. # To use G1GC uncomment the lines below.
  37. #-XX:-UseConcMarkSweepGC
  38. #-XX:-UseCMSInitiatingOccupancyOnly
  39. -XX:+UseG1GC
  40. -XX:InitiatingHeapOccupancyPercent=75
  41. ## DNS cache policy
  42. # cache ttl in seconds for positive DNS lookups noting that this overrides the
  43. # JDK security property networkaddress.cache.ttl; set to -1 to cache forever
  44. -Des.networkaddress.cache.ttl=60
  45. # cache ttl in seconds for negative DNS lookups noting that this overrides the
  46. # JDK security property networkaddress.cache.negative ttl; set to -1 to cache
  47. # forever
  48. -Des.networkaddress.cache.negative.ttl=10
  49. ## optimizations
  50. # pre-touch memory pages used by the JVM during initialization
  51. -XX:+AlwaysPreTouch
  52. ## basic
  53. # explicitly set the stack size
  54. -Xss1m
  55. # set to headless, just in case
  56. -Djava.awt.headless=true
  57. # ensure UTF-8 encoding by default (e.g. filenames)
  58. -Dfile.encoding=UTF-8
  59. # use our provided JNA always versus the system one
  60. -Djna.nosys=true
  61. # turn off a JDK optimization that throws away stack traces for common
  62. # exceptions because stack traces are important for debugging
  63. -XX:-OmitStackTraceInFastThrow
  64. # flags to configure Netty
  65. -Dio.netty.noUnsafe=true
  66. -Dio.netty.noKeySetOptimization=true
  67. -Dio.netty.recycler.maxCapacityPerThread=0
  68. # log4j 2
  69. -Dlog4j.shutdownHookEnabled=false
  70. -Dlog4j2.disable.jmx=true
  71. -Djava.io.tmpdir=${ES_TMPDIR}
  72. ## heap dumps
  73. # generate a heap dump when an allocation from the Java heap fails
  74. # heap dumps are created in the working directory of the JVM
  75. -XX:+HeapDumpOnOutOfMemoryError
  76. # specify an alternative path for heap dumps; ensure the directory exists and
  77. # has sufficient space
  78. -XX:HeapDumpPath=data
  79. # specify an alternative path for JVM fatal error logs
  80. -XX:ErrorFile=logs/hs_err_pid%p.log
  81. ## JDK 8 GC logging
  82. 8:-XX:+PrintGCDetails
  83. 8:-XX:+PrintGCDateStamps
  84. 8:-XX:+PrintTenuringDistribution
  85. 8:-XX:+PrintGCApplicationStoppedTime
  86. 8:-Xloggc:logs/gc.log
  87. 8:-XX:+UseGCLogFileRotation
  88. 8:-XX:NumberOfGCLogFiles=32
  89. 8:-XX:GCLogFileSize=64m
  90. # JDK 9+ GC logging
  91. 9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
  92. # due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
  93. # time/date parsing will break in an incompatible way for some date patterns and locals
  94. 9-:-Djava.locale.providers=COMPAT

启动

创建docker-compose.yml文件,内容如下:

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

启动:

  1. docker-compose up -d

备注

elasticsearch.yml、jvm.options、docker-compose.yml等每个节点都需要配置,其中elasticsearch.yml、docker-compose.yml具体节点信息需要替换。

Kibana

挂载

在宿主机上创建kibana config配置目录
eg:

  1. 配置文件
  2. mkdir /home/es/kibana-7.6.2

Kibana配置

在/home/es/kibana-7.6.2目录下创建kibana.yml,具体内容如下:

  1. # Kibana is served by a back end server. This setting specifies the port to use.
  2. server.port: 5602
  3. # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
  4. # The default is 'localhost', which usually means remote machines will not be able to connect.
  5. # To allow connections from remote users, set this parameter to a non-loopback address.
  6. server.host: 0.0.0.0
  7. # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
  8. # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
  9. # from requests it receives, and to prevent a deprecation warning at startup.
  10. # This setting cannot end in a slash.
  11. #server.basePath: ""
  12. # Specifies whether Kibana should rewrite requests that are prefixed with
  13. # `server.basePath` or require that they are rewritten by your reverse proxy.
  14. # This setting was effectively always `false` before Kibana 6.3 and will
  15. # default to `true` starting in Kibana 7.0.
  16. #server.rewriteBasePath: false
  17. # The maximum payload size in bytes for incoming server requests.
  18. #server.maxPayloadBytes: 1048576
  19. # The Kibana server's name. This is used for display purposes.
  20. #server.name: "your-hostname"
  21. # The URLs of the Elasticsearch instances to use for all your queries.
  22. elasticsearch.hosts: ["http://10.133.0.188:9201"]
  23. # When this setting's value is true Kibana uses the hostname specified in the server.host
  24. # setting. When the value of this setting is false, Kibana uses the hostname of the host
  25. # that connects to this Kibana instance.
  26. #elasticsearch.preserveHost: true
  27. # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
  28. # dashboards. Kibana creates a new index if the index doesn't already exist.
  29. #kibana.index: ".kibana"
  30. # The default application to load.
  31. #kibana.defaultAppId: "home"
  32. # If your Elasticsearch is protected with basic authentication, these settings provide
  33. # the username and password that the Kibana server uses to perform maintenance on the Kibana
  34. # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
  35. # is proxied through the Kibana server.
  36. #elasticsearch.username: "kibana"
  37. #elasticsearch.password: "pass"
  38. # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
  39. # These settings enable SSL for outgoing requests from the Kibana server to the browser.
  40. #server.ssl.enabled: false
  41. #server.ssl.certificate: /path/to/your/server.crt
  42. #server.ssl.key: /path/to/your/server.key
  43. # Optional settings that provide the paths to the PEM-format SSL certificate and key files.
  44. # These files are used to verify the identity of Kibana to Elasticsearch and are required when
  45. # xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
  46. #elasticsearch.ssl.certificate: /path/to/your/client.crt
  47. #elasticsearch.ssl.key: /path/to/your/client.key
  48. # Optional setting that enables you to specify a path to the PEM file for the certificate
  49. # authority for your Elasticsearch instance.
  50. #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
  51. # To disregard the validity of SSL certificates, change this setting's value to 'none'.
  52. #elasticsearch.ssl.verificationMode: full
  53. # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
  54. # the elasticsearch.requestTimeout setting.
  55. #elasticsearch.pingTimeout: 1500
  56. # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
  57. # must be a positive integer.
  58. #elasticsearch.requestTimeout: 30000
  59. # List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
  60. # headers, set this value to [](an empty list).
  61. #elasticsearch.requestHeadersWhitelist: [ authorization ]
  62. # Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
  63. # by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
  64. #elasticsearch.customHeaders: {}
  65. # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
  66. #elasticsearch.shardTimeout: 30000
  67. # Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying.
  68. #elasticsearch.startupTimeout: 5000
  69. # Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
  70. #elasticsearch.logQueries: false
  71. # Specifies the path where Kibana creates the process ID file.
  72. #pid.file: /var/run/kibana.pid
  73. # Enables you specify a file where Kibana stores log output.
  74. #logging.dest: stdout
  75. # Set the value of this setting to true to suppress all logging output.
  76. #logging.silent: false
  77. # Set the value of this setting to true to suppress all logging output other than error messages.
  78. #logging.quiet: false
  79. # Set the value of this setting to true to log all events, including system usage information
  80. # and all requests.
  81. #logging.verbose: false
  82. # Set the interval in milliseconds to sample system and process performance
  83. # metrics. Minimum is 100ms. Defaults to 5000.
  84. #ops.interval: 5000
  85. # Specifies locale to be used for all localizable strings, dates and number formats.
  86. # Supported languages are the following: English - en , by default , Chinese - zh-CN .
  87. #i18n.locale: "en"

启动

创建docker-compose.yml文件,内容如下:

  1. version: '2'
  2. services:
  3. kibana:
  4. image: kibana:7.6.2
  5. volumes:
  6. - ./kibana.yml:/usr/share/kibana/config/kibana.yml
  7. ports:
  8. - '5602:5602/tcp'

启动:

  1. docker-compose up -d

官方文档

https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docker.html
https://www.elastic.co/guide/en/kibana/current/docker.html

个人微信公众号

在这里插入图片描述

发表评论

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

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

相关阅读