设为首页 收藏本站
查看: 1043|回复: 0

[经验分享] docker 创建elasticsearch集群镜像

[复制链接]

尚未签到

发表于 2017-12-7 09:26:19 | 显示全部楼层 |阅读模式
  搞了2天终于搞好了



更新:
  2017/2/15: 更改elasticsearch.yml中绑定ip, 可开启集群效果
2017/2/16: supervisord.conf 加入 autostart=true, 开启景象自动启动
  2017/2/16: 更改elasticsearch.yml中ip嗅探, 真正实现热插拔集群
bug: 指定的物理机挂在目录仍然存在问题

  需要: 一个能在linux下正常运行的 elasticsearch-2.4.0 版本, 直接copy进镜像, 安装好head, bigdesk, ik分词  器等, 在elasticsearch中有讲: http://www.cnblogs.com/wenbronk/p/6390462.html
  Dockerfile



############################################
# version : wenbronk/jdk8u121/elasticsearch2.4
# desc : 当前版本安装的escluster 2.4.0
############################################
FROM wenbronk/jdk8u121
MAINTAINER wenbronk "wenbronk@163.com"
# 设置环境变量,所有操作都是非交互式的
ENV DEBIAN_FRONTEND noninteractive
# 添加 supervisord 的配置文件,并复制配置文件到对应目录下面。(supervisord.conf文件和Dockerfile文件在同一路径)
COPY supervisord.conf /etc/supervisor/supervisord.conf
RUN echo "export LC_ALL=C"
# 设置 ES 的环境变量,若有其他的环境变量需要设置,也可以在这里添加。
ENV ES_HOME /var/tmp/elasticsearch-2.4.0
ENV PATH $PATH:$PATH:$ES_HOME/bin
# 创建elasticsearch的数据目录, 同时将权限给admin用户
RUN mkdir /escluster
# 复制elasticsearch-2.4.0(本地能正常运行的es, 安装好ik插件) 到镜像中 /var/tmp
COPY elasticsearch-2.4.0 /var/tmp/elasticsearch-2.4.0   
# 修改文件夹权限
# RUN chown -R admin:admin /var/tmp/elasticsearch-2.4.0
# RUN chown -R admin:admin /escluster
# 挂载/software/elasticsearch-2.4.0/config和/escluster目录
VOLUME ["/var/tmp/elasticsearch-2.4.0/config"]
VOLUME ["/escluster"]
# 容器需要开放ES的9200和9300端口
EXPOSE 9200
EXPOSE 9300
# 执行supervisord来同时执行多个命令,使用 supervisord 的可执行路径启动服务。
CMD ["/usr/bin/supervisord"]
  supervisord.conf



[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:elasticsearch]
command=/bin/bash -c "exec ${ES_HOME}/bin/elasticsearch -DFOREGROUND"
autostart=true

  elasticsearch.yml 文件位于 ${ES_HOME}/config下



# ======================== Elasticsearch Configuration =========================
#
# 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 see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: wenbronk-escluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# node.name: wenbronk-esnode01
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /escluster/data
path.data: /escluster/data
# #
# # Path to log files:
# #
path.logs: /escluster/logs
#
# Path to log files:
#
# path.logs: /escluster/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.memory_lock: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable 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, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.1.110", "[::1]"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
index.analysis.analyzer.ik.type: ik
  创建镜像:



docker build -t wenbronk/jdk8u121/escluster .
  注: 因为es使用非root账户, docker默认使用root账户, 开启一直不成功, supervisord还没来及学, 所以暂时使用root开启es



vim ./bin/elasticsearch
  插入



-Des.insecure.allow.root="true"
DSC0000.png

  启动



docker run -d -p 9990:22 -p 9200:9200 -p 9300:9300 -v /docker/escluster01:/esculster wenbronk/jdk8u121/escluster
docker run -d -p 9991:22 -p 9201:9200 -p 9301:9300 -v /docker/escluster01:/esculster wenbronk/jdk8u121/escluster
docker run -d -p 9992:22 -p 9202:9200 -p 9302:9300 -v /docker/escluster01:/esculster wenbronk/jdk8u121/escluster
  可通过ip查看



http://www.wenbronk.com:9200/_plugin/head/
  或者链接进容器查看



>dockers exec -it CONTAINER_ID /bin/bash
>container>/var/tmp/es/bin/elasticsearch -d

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421574-1-1.html 上篇帖子: VS code docker 调试 asp.net core 下篇帖子: 使用 docker 创建自己的镜像
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表