Docker安装elasticsearch6.5

一、安装elasticsearch

1、拉取镜像

docker pull elasticsearch:6.5.0

2、 启动容器

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 elasticsearch:6.5.0
3573e7af2aea8767415847b0c1214e3d08d11ce09ecf745eeb501f02d4530624

使用docker ps查看发现容器并没有启动成功,查看日志

docker logs -f 3573
image.png

查看max_map_count的值

$ cat /proc/sys/vm/max_map_count
65530

重新设置max_map_count的值

$ sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144

永久更改max_map_count值,
vm.max_map_count=200000直接写到/etc/sysctl.conf中,然后执行sysctl -p
重新启动容器

docker start  elasticsearch

浏览器访问

http://ip:9200
{
  "name" : "IK4_5lR",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "xw5vUFlqSu2G6lPOSq_8AQ",
  "version" : {
    "number" : "6.5.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "816e6f6",
    "build_date" : "2018-11-09T18:58:36.352602Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

二、安装elasticsearch-head插件

1、拉取镜像

docker pull mobz/elasticsearch-head:5

2、启动容器

docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5

访问 http://ip:9100

image.png

提示未连接,修改elasticsarch-head的监听
进入容器

docker exec -it es-head bash

使用vim会提示vim命令不存在,安装vim命令,若是安装时报错,说yum command not found ,使用apt-get update,然后使用apt-get install vim -y 进行安装下载即可

root@616029884dd4:/usr/src/app# vim Gruntfile.js 
bash: vim: command not found
root@616029884dd4:/usr/src/app# yum install -y vim
bash: yum: command not found
root@616029884dd4:/usr/src/app# apt-get update

es-head使用的grunt-server作为服务器的,所以他的启动后监听的host默认是localhost, 所以我们要修改其中的配置文件,增加一些配置,这样可以使得能够被外部访问的到,修改Gruntfile.js文件,添加hostname


image.png

chon
重启es-head

docker restart es-head
image.png

连接elasticsearch的地址,查看控制台会提示跨域错误,修改elasticsearch.yml解决跨域问题,在文件最后添加

http.cors.enabled: true
http.cors.allow-origin: "*" 

以挂载的方式启动es

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -v /home/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:6.5.0

elasticsearch.yml的内容

cluster.name: "docker-cluster"
network.host: 0.0.0.0

# minimum_master_nodes need to be explicitly set when bound on a public IP
# # set to 1 to allow single node clusters
# # Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1

# head setting  解决跨域问题
http.cors.enabled: true
http.cors.allow-origin: "*" 

可能会启动失败,出现权限不足的问题,这时候需要关闭selinux

[root@localhost home]# docker logs -f df99
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2019-08-15 07:11:55,026 main ERROR No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
Exception in thread "main" SettingsException[Failed to load settings from /usr/share/elasticsearch/config/elasticsearch.yml]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:102)
    at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86)
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:215)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:370)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:421)
    at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
    at java.base/java.nio.file.Files.newInputStream(Files.java:155)
    at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1189)
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
    ... 6 more

启动之后再次连接就连接成功了


image.png

三、安装ik分词器

进入到容器里

docker exec -it elasticsearch bash
cd bin
[root@d6bd6a5487ae bin]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.0/elasticsearch-analysis-ik-6.5.0.zip

你可能感兴趣的:(Docker安装elasticsearch6.5)