docker-compose搭建elasticsearch集群,整合head

搭建环境

 ubantu17    `已经安装好docker 17.06.2-ce` 

搭建步骤

1. 新建文件es1.yml,es2.yml

/* es1.yml */
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
node.name: master
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1

/* es2.yml  */
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
node.name: node2
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: es1

2. 配置head

一定要在镜像中进行配置如下的两个文件
/usr/src/app/Gruntfile.js
/usr/src/app/_site/app.js

  • Gruntfile.js修改以下片段,
     connect: {
                server: {
                    options: {
                        /* 默认监控:127.0.0.1,修改为:0.0.0.0 */
                        hostname: '0.0.0.0',
                        port: 9100,
                        base: '.',
                        keepalive: true
                    }
                }
  • app.js修改以下代码片段:
/* 修改localhost为elasticsearch集群地址,Docker部署中,一般是elasticsearch宿主机地址 */
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
  • 为了方便修改将上面的两个文件复制出来挂载在宿主机上,宿主机和容器之间的复制命令为
    docker cp host_path containerID:container_path  --从主机复制到容器
    docker cp containerID:container_path host_path --从容器复制到主机

3. 启动docker-compose up

  • 修改虚拟内存
##
cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf
##
echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf
##
mv /tmp/system_sysctl.conf /etc/sysctl.conf
  • docker-compose文件内容
version: '2.0'
services:
    elasticsearch-central:
        image: elasticsearch:5.6.4
        container_name: es1
        volumes:
            /* 修改挂载位置 */
           - /root/apollo/elasticsearch/data:/usr/share/elasticsearch/data 
           - /root/apollo/elasticsearch/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
        environment:
           - ES_CLUSTERNAME=elasticsearch
        command: elasticsearch
        ports:
           - "9200:9200"
           - "9300:9300"
    elasticsearch-data:
        image: elasticsearch:5.6.4
        container_name: es2
        volumes:
            /* 修改挂载位置 */
           - /root/apollo/elasticsearch/data2:/usr/share/elasticsearch/data
           - /root/apollo/elasticsearch/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
        environment:
           - ES_CLUSTERNAME=elasticsearch
        command: elasticsearch
        ports:
           - "9201:9200"
           - "9301:9300"
        links:
           - elasticsearch-central:elasticsearch
    elasticsearch-head:
        image: mobz/elasticsearch-head:5
        container_name: head
        volumes:
            /* 修改挂载位置 */
           - /root/apollo/elasticsearch/head/Gruntfile.js:/usr/src/app/Gruntfile.js
           - /root/apollo/elasticsearch/head/app.js:/usr/src/app/_site/app.js        
        ports:
           - "9100:9100"           
        links:
           - elasticsearch-central:elasticsearch
  • 启动
    docker-compose up 启动
    docker-compose down 关闭

参考链接

elasticsearch官网

你可能感兴趣的:(docker)