CentOS7上使用docker安装Elasticsearch

1、搜索elasticsearch的镜像

# docker search elasticsearch

2、拉取镜像

# docker pull elasticsearch

3、查看镜像

# docker images

4、启动镜像

# docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name ES_01 5acf0e8da90b

-e:限制初始内存和最大内存(默认初始占用2G内存空间);

-d:后台运行;

-p:默认进行web通信使用9200端口,将虚拟机的9200映射到ES的9200;

-p:分布式下各结点之间的通信使用9300端口;

--name:容器名

5、查看启动的容器

# docker ps

6、测试

网页输入:“主机地址:9200”,出现如下json数据,即成功!

坑一:

容器已启动,但用网页无法打开“http://192.168.128.21:9200”,查看日志,发现报错:

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N

...

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

...

解决办法:

一、运行:

[root@localhost ~]# sysctl -w vm.max_map_count=262144

二、进入容器,并修改config目录下的两个文件:

①jvm.options文件:将-Xms和-Xmx的值都改为2g:

# docker exec -it ES622 /bin/bash
# cd config
# vi jvm.options
-Xms2g
-Xmx2g

elasticsearch.yml文件,增加或替换下面两个配置:

# ​​vi config/elasticsearch.yml 

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

 

最后退出并重新启动容器:

# exit
# docker restart ES622

发布了26 篇原创文章 · 获赞 18 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_41056197/article/details/96474855