zoukankan      html  css  js  c++  java
  • Elasticsearch docker安装

    Elasticsearch 安装

    我们之前已经使用过elasticsearch了,这里不再对它进行介绍了,直接下载安装,本章节将采用Docker安装,不过在市面上还有很多采用linxu安装,关于linux安装,已经提供了安装手册,这里就不讲了。

    (1)docker镜像下载

    docker pull elasticsearch:5.6.8
    

    (2)安装es容器

    docker run -di --name=changgou_elasticsearch -p 9200:9200 -p 9300:9300 elasticsearch:5.6.8
    

    9200端口(Web管理平台端口) 9300(服务默认端口)

    浏览器输入地址访问:http://192.168.211.132:9200/

    (3)开启远程连接

    上面完成安装后,es并不能正常使用,elasticsearch从5版本以后默认不开启远程连接,程序直接连接会报如下错误:

    failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{5ttLpMhkRjKLkvoY7ltUWg}{192.168.211.132}{192.168.211.132:9300}]
    

    我们需要修改es配置开启远程连接,代码如下:

    登录容器

    docker exec -it changgou_elasticsearch /bin/bash
    

    查看目录结构 输入: dir

    root@07f22eb41bb5:/usr/share/elasticsearch# dir
    NOTICE.txt  README.textile  bin  config  data  lib  logs  modules  plugins
    

    进入config目录

    cd config
    

    查看文件

    root@07f22eb41bb5:/usr/share/elasticsearch/config# ls
    elasticsearch.yml  log4j2.properties  scripts
    

    修改elasticsearch.yml文件

    root@07f22eb41bb5:/usr/share/elasticsearch/config# vi elasticsearch.yml
    bash: vi: command not found
    

    vi命令无法识别,因为docker容器里面没有该命令,我们可以安装该编辑器。

    安装vim编辑器

    apt-get update
    apt-get install vim
    

    安装好了后,修改elasticsearch.yml配置,如下图:

    vi elasticsearch.yml
    

    修改如下图:

    同时添加下面一行代码:

    cluster.name: my-application
    

    重启docker

    docker restart changgou_elasticsearch
    

    (4)系统参数配置

    重启后发现重启启动失败了,这时什么原因呢?这与我们刚才修改的配置有关,因为elasticsearch在启动的时候会进行一些检查,比如最多打开的文件的个数以及虚拟内存区域数量等等,如果你放开了此配置,意味着需要打开更多的文件以及虚拟内存,所以我们还需要系统调优

    修改vi /etc/security/limits.conf ,追加内容 (nofile是单个进程允许打开的最大文件个数 soft nofile 是软限制 hard nofile是硬限制 )

    * soft nofile 65536
    * hard nofile 65536
    

    修改vi /etc/sysctl.conf,追加内容 (限制一个进程可以拥有的VMA(虚拟内存区域)的数量 )

    vm.max_map_count=655360
    

    执行下面命令 修改内核参数马上生效

    sysctl -p
    

    重新启动虚拟机,再次启动容器,发现已经可以启动并远程访问

    reboot
    

    (5)跨域配置

    修改elasticsearch/config下的配置文件:elasticsearch.yml,增加以下三句命令,并重启:

    http.cors.enabled: true
    http.cors.allow-origin: "*"
    network.host: 192.168.211.132
    

    其中:
    http.cors.enabled: true:此步为允许elasticsearch跨域访问,默认是false。
    http.cors.allow-origin: "":表示跨域访问允许的域名地址(表示任意)。

    重启

     docker restart changgou_elasticsearch
    

    小提示:如果想让容器开启重启,可以执行下面命令

    docker update --restart=always 容器名称或者容器id
    
  • 相关阅读:
    第二十章 springboot + consul(1)
    附2 hystrix详述(2)- 配置
    附1 hystrix详述(1)
    第十九章 springboot + hystrix(1)
    第十八章 springboot + thymeleaf
    第十七章 springboot + devtools(热部署)
    Nginx(二):虚拟主机配置
    SpringMVC中异常处理详解
    五分钟读懂UML类图
    Java web中WEB-INF目录理解
  • 原文地址:https://www.cnblogs.com/angdh/p/15676721.html
Copyright © 2011-2022 走看看