#### 1. 环境 - 虚拟机 | 主机名 | IP | | ---------- | ----------- | | 7a(master) | 192.168.0.3 | | 7b | 192.168.0.4 | | 7c | 192.168.0.5 | - docker-ce ``` Version: 18.09.7 ``` #### 2. 修改linux参数 es 要求Linux 的 参数 vm.max_map_count 至少为 262144 ``` # 在文件最后添加一行 sudo vim /etc/sysctl.conf vm.max_map_count=262144 # 加载设置好的系统参数 sudo sysctl -p ``` #### 3. 准备配置文件 - 目录结构 ``` es ├── config │ └── elasticsearch.yml ├── Dockerfile ├── plugins └── README ``` - Dockerfile ``` FROM elasticsearch:7.2.0 LABEL maintainer="Erica" ENV LANG C.UTF-8 ENV TIMEZONE Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone ADD config/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml # 需要添加分词插件时使用 #ADD plugins /usr/share/elasticsearch/plugins EXPOSE 9100 9200 9300 CMD ["elasticsearch"] ``` - 主节点 elasticsearch.yml ``` cluster.name: "myels" node.name: "master" node.master: true node.data: true network.host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 network.publish_host: 192.168.0.3 http.cors.enabled: true http.cors.allow-origin: "*" path.data: /usr/share/elasticsearch/data path.logs: /usr/share/elasticsearch/logs discovery.seed_hosts: - 192.168.0.4:9200 - 192.168.0.5:9200 cluster.initial_master_nodes: - master ``` - 从节点elasticsearch.yml 对应修改 node.name node.master network.publish_host ``` # 192.168.0.4 node.name: "slave-1" node.master: false network.publish_host: 192.168.0.4 discovery.seed_hosts: - 192.168.0.3:9200 - 192.168.0.5:9200 # 192.168.0.5 node.name: "slave-2" node.master: false network.publish_host: 192.168.0.5 discovery.seed_hosts: - 192.168.0.3:9200 - 192.168.0.5:9200 ``` #### 4. 构建镜像,启动容器 此处可以考虑使用docker-compse启动,参考最后的官方文档 ``` docker build -t es:v1 . docker run -itd --name estest -p 9200:9200 -p 9300:9300 -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" -v /data/els/data:/usr/share/elasticsearch/data -v /data/els/logs:/usr/share/elasticsearch/logs es:v1 ``` #### 打开es head查看  #### 6. 参考 ``` https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docker.html ``` 最后修改:2019 年 08 月 23 日 10 : 26 AM © 著作权归作者所有