首页
学习
活动
专区
工具
TVP
发布

在高性能服务器如何部署基于docker容器的elasticsearch集群?

创建三个文件夹

[root@mapabc es-cluster]# lltotal 8drwxr-xr-x 7 root root 216 May 14 18:57 es-cluster01drwxr-xr-x 7 root root 216 May 14 18:59 es-cluster02drwxr-xr-x 7 root root 216 May 14 19:03 es-cluster03

cat config01/elasticsearch.yml

cat config01/elasticsearch.yml# ======================== Elasticsearch Configuration =========================xpack.ml.enabled: falsecluster.initial_master_nodes: ["node-1","node-2","node-3"]## NOTE: Elasticsearch comes with reasonable defaults for most settings.# Before you set out to tweak and tune the configuration, make sure you# understand what are you trying to accomplish and the consequences.## The primary way of configuring a node is via this file. This template lists# the most important settings you may want to configure for a production cluster.## Please consult the documentation for further information on configuration options:# https://www.elastic.co/guide/en/elasticsearch/reference/index.html## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: docker-cluster## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: node-1## Add custom attributes to the node:##node.attr.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):##path.data: /path/to/data## Path to log files:##path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:##bootstrap.memory_lock: true## Make sure that the heap size is set to about half the memory available# on the system and that the owner of the process is allowed to use this# limit.## Elasticsearch performs poorly when the system is swapping the memory.## ---------------------------------- Network -----------------------------------## Set the bind address to a specific IP (IPv4 or IPv6):#network.host: 0.0.0.0## Set a custom port for HTTP:#http.port: 9200## For more information, consult the network module documentation.## --------------------------------- Discovery ----------------------------------## Pass an initial list of hosts to perform discovery when this node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]#discovery.seed_hosts: ["192.168.11.112:19300","192.168.11.112:29300","192.168.11.112:39300"]## Bootstrap the cluster using an initial set of master-eligible nodes:##cluster.initial_master_nodes: ["node-1", "node-2"]## For more information, consult the discovery and cluster formation module documentation.## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:##gateway.recover_after_nodes: 3## For more information, consult the gateway module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: true[root@mapabc es-cluster01]#

cat config02/elasticsearch.yml

[root@mapabc es-cluster01]# cat config02/elasticsearch.yml# ======================== Elasticsearch Configuration =========================xpack.ml.enabled: falsecluster.initial_master_nodes: ["node-1","node-2","node-3"]## NOTE: Elasticsearch comes with reasonable defaults for most settings.# Before you set out to tweak and tune the configuration, make sure you# understand what are you trying to accomplish and the consequences.## The primary way of configuring a node is via this file. This template lists# the most important settings you may want to configure for a production cluster.## Please consult the documentation for further information on configuration options:# https://www.elastic.co/guide/en/elasticsearch/reference/index.html## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: docker-cluster## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: node-2## Add custom attributes to the node:##node.attr.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):##path.data: /path/to/data## Path to log files:##path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:##bootstrap.memory_lock: true## Make sure that the heap size is set to about half the memory available# on the system and that the owner of the process is allowed to use this# limit.## Elasticsearch performs poorly when the system is swapping the memory.## ---------------------------------- Network -----------------------------------## Set the bind address to a specific IP (IPv4 or IPv6):#network.host: 0.0.0.0## Set a custom port for HTTP:#http.port: 9200## For more information, consult the network module documentation.## --------------------------------- Discovery ----------------------------------## Pass an initial list of hosts to perform discovery when this node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]#discovery.seed_hosts: ["192.168.11.112:19300","192.168.11.112:29300","192.168.11.112:39300"]## Bootstrap the cluster using an initial set of master-eligible nodes:##cluster.initial_master_nodes: ["node-1", "node-2"]## For more information, consult the discovery and cluster formation module documentation.## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:##gateway.recover_after_nodes: 3## For more information, consult the gateway module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: true[root@mapabc es-cluster01]#

cat config03/elasticsearch.yml

[root@mapabc es-cluster01]# cat config03/elasticsearch.yml# ======================== Elasticsearch Configuration =========================xpack.ml.enabled: falsecluster.initial_master_nodes: ["node-1","node-2","node-3"]## NOTE: Elasticsearch comes with reasonable defaults for most settings.# Before you set out to tweak and tune the configuration, make sure you# understand what are you trying to accomplish and the consequences.## The primary way of configuring a node is via this file. This template lists# the most important settings you may want to configure for a production cluster.## Please consult the documentation for further information on configuration options:# https://www.elastic.co/guide/en/elasticsearch/reference/index.html## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: docker-cluster## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: node-3## Add custom attributes to the node:##node.attr.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):##path.data: /path/to/data## Path to log files:##path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:##bootstrap.memory_lock: true## Make sure that the heap size is set to about half the memory available# on the system and that the owner of the process is allowed to use this# limit.## Elasticsearch performs poorly when the system is swapping the memory.## ---------------------------------- Network -----------------------------------## Set the bind address to a specific IP (IPv4 or IPv6):#network.host: 0.0.0.0## Set a custom port for HTTP:#http.port: 9200## For more information, consult the network module documentation.## --------------------------------- Discovery ----------------------------------## Pass an initial list of hosts to perform discovery when this node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]#discovery.seed_hosts: ["192.168.11.112:19300","192.168.11.112:29300","192.168.11.112:39300"]## Bootstrap the cluster using an initial set of master-eligible nodes:##cluster.initial_master_nodes: ["node-1", "node-2"]## For more information, consult the discovery and cluster formation module documentation.## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:##gateway.recover_after_nodes: 3## For more information, consult the gateway module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: true[root@mapabc es-cluster01]#

cat es-cluster01/Dockerfile

[root@mapabc es-cluster]# cat es-cluster01/DockerfileFROM arm64v8/openjdk:8-jreVOLUME /tmpMAINTAINER hujunfeng 419644560@qq.com#修改时区 centosRUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeRUN echo "Asia/shanghai" > /etc/timezoneADD elasticsearch-7.6.2.tar.gz /usr/local/COPY config01/elasticsearch.yml /usr/local/elasticsearch-7.6.2/config/elasticsearch.ymlRUN useradd -d /home/es -m es -s /bin/bashRUN chown -R es:es /usr/local/elasticsearch-7.6.2USER esCMD ["/usr/local/elasticsearch-7.6.2/bin/elasticsearch"][root@mapabc es-cluster]#

cat es-cluster02/Dockerfile

[root@mapabc es-cluster]# cat es-cluster02/DockerfileFROM arm64v8/openjdk:8-jreVOLUME /tmpMAINTAINER hujunfeng 419644560@qq.com#修改时区 centosRUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeRUN echo "Asia/shanghai" > /etc/timezoneADD elasticsearch-7.6.2.tar.gz /usr/local/COPY config02/elasticsearch.yml /usr/local/elasticsearch-7.6.2/config/elasticsearch.ymlRUN useradd -d /home/es -m es -s /bin/bashRUN chown -R es:es /usr/local/elasticsearch-7.6.2USER esCMD ["/usr/local/elasticsearch-7.6.2/bin/elasticsearch"][root@mapabc es-cluster]#

cat es-cluster03/Dockerfile

[root@mapabc es-cluster]# cat es-cluster03/DockerfileFROM arm64v8/openjdk:8-jreVOLUME /tmpMAINTAINER hujunfeng 419644560@qq.com#修改时区 centosRUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeRUN echo "Asia/shanghai" > /etc/timezoneADD elasticsearch-7.6.2.tar.gz /usr/local/COPY config03/elasticsearch.yml /usr/local/elasticsearch-7.6.2/config/elasticsearch.ymlRUN useradd -d /home/es -m es -s /bin/bashRUN chown -R es:es /usr/local/elasticsearch-7.6.2USER esCMD ["/usr/local/elasticsearch-7.6.2/bin/elasticsearch"][root@mapabc es-cluster]#

cat es-cluster01/start-build.sh

[root@mapabc es-cluster]# cat es-cluster01/start-build.shdocker rm -f my-es-app-19300docker build -t my-es-19300 .docker run -d --name my-es-app-19300 -p 19200:9200 -p 19300:9300 my-es-19300[root@mapabc es-cluster]#

cat es-cluster03/start-build.sh

[root@mapabc es-cluster]# cat es-cluster02/start-build.shdocker rm -f my-es-app-29300docker build -t my-es-29300 .docker run -d --name my-es-app-29300 -p 29200:9200 -p 29300:9300 my-es-29300[root@mapabc es-cluster]#

cat es-cluster03/start-build.sh

[root@mapabc es-cluster]# cat es-cluster03/start-build.shdocker rm -f my-es-app-39300docker build -t my-es-39300 .docker run -d --name my-es-app-39300 -p 39200:9200 -p 39300:9300 my-es-39300[root@mapabc es-cluster]#

最后成功!

这里有一个问题就是,通过数据卷挂载的方式,不OK。因为es启动用到非root方式启动。所以会有权限问题。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20200514A0O6EM00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券