美文网首页
1分钟使用docker构建elasticsearch集群

1分钟使用docker构建elasticsearch集群

作者: webxiaohua | 来源:发表于2020-02-27 17:29 被阅读0次
    1.下载elasticsearch镜像
    docker pull elasticsearch:5.6.8
    
    2.进入工作目录,准备配置环境
    mkdir ES --创建es目录
    cd ES --进入es目录
    mkdir config data/data0 data/data1 data/data2 --创建配置目录和数据目录
    cd config --进入配置目录
    touch es0.yml --创建es配置文件
    touch es1.yml
    touch es2.yml
    

    es0.yml 文件内容:

    cluster.name: elasticsearch-cluster
    node.name: es-node0
    network.bind_host: 0.0.0.0
    network.publish_host: 172.16.128.106
    http.port: 9200
    transport.tcp.port: 9300
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true 
    node.data: true  
    discovery.zen.ping.unicast.hosts: ["172.16.128.106:9300","172.16.128.106:9301","172.16.128.106:9302"]
    discovery.zen.minimum_master_nodes: 2
    

    es1.yml 文件内容:

    cluster.name: elasticsearch-cluster
    node.name: es-node1
    network.bind_host: 0.0.0.0
    network.publish_host: 172.16.128.106
    http.port: 9201
    transport.tcp.port: 9301
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true 
    node.data: true  
    discovery.zen.ping.unicast.hosts: ["172.16.128.106:9300","172.16.128.106:9301","172.16.128.106:9302"]
    discovery.zen.minimum_master_nodes: 2
    

    es2.yml 文件内容:

    cluster.name: elasticsearch-cluster
    node.name: es-node2
    network.bind_host: 0.0.0.0
    network.publish_host: 172.16.128.106
    http.port: 9202
    transport.tcp.port: 9302
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true 
    node.data: true  
    discovery.zen.ping.unicast.hosts: ["172.16.128.106:9300","172.16.128.106:9301","172.16.128.106:9302"]
    discovery.zen.minimum_master_nodes: 2
    

    注意 172.16.128.106 是我的ip,这里要替换成主机的局域网ip

    3.启动集群
    docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v ~/docker/es5/config/es0.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v ~/docker/es5/data/data0:/usr/share/elasticsearch/data --name ES00 elasticsearch:5.6.8
    
    docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v ~/docker/es5/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v ~/docker/es5/data/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch:5.6.8
    
    docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v ~/docker/es5/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v ~/docker/es5/data/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch:5.6.8
    

    启动完成以后就可以通过chrome浏览器插件访问看效果了:


    image.png

    以上就是简单的搭建流程,有问题欢迎留言探讨~

    相关文章

      网友评论

          本文标题:1分钟使用docker构建elasticsearch集群

          本文链接:https://www.haomeiwen.com/subject/vgjxhhtx.html