Docker部署ElasticSearch(Centos 7)

5 篇文章 0 订阅
5 篇文章 0 订阅

1.搜索ElasticSearch镜像

[sandwich@192 ~]$ docker search elasticsearch
NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
elasticsearch                                Elasticsearch is a powerful open source sear…   5292      [OK]       
nshou/elasticsearch-kibana                   Elasticsearch-7.15.1 Kibana-7.15.1              132                  [OK]
mobz/elasticsearch-head                      elasticsearch-head front-end and standalone …   81                   
elastichq/elasticsearch-hq                   Official Docker image for ElasticHQ: Elastic…   76                   [OK]
itzg/elasticsearch                           Provides an easily configurable Elasticsearc…   71                   [OK]
elastic/elasticsearch                        The Elasticsearch Docker image maintained by…   56                   
taskrabbit/elasticsearch-dump                Import and export tools for elasticsearch       27                   [OK]
lmenezes/elasticsearch-kopf                  elasticsearch kopf                              18                   [OK]
justwatch/elasticsearch_exporter             Elasticsearch stats exporter for Prometheus     17                   
barnybug/elasticsearch                       Latest Elasticsearch 1.7.2 and previous rele…   17                   [OK]
blacktop/elasticsearch                       Alpine Linux based Elasticsearch Docker Image   16                   [OK]
esystemstech/elasticsearch                   Debian based Elasticsearch packing for Lifer…   15                   
monsantoco/elasticsearch                     ElasticSearch Docker image                      11                   [OK]
mesoscloud/elasticsearch                     [UNMAINTAINED] Elasticsearch                    9                    [OK]
centerforopenscience/elasticsearch           Elasticsearch                                   4                    [OK]
dtagdevsec/elasticsearch                     elasticsearch                                   4                    [OK]
barchart/elasticsearch-aws                   Elasticsearch AWS node                          3                    
praseodym/elasticsearch-curator              Elasticsearch Curator                           3                    [OK]
dsteinkopf/elasticsearch-ingest-attachment   elasticsearch + ingest-attachment to be used…   1                    [OK]
jetstack/elasticsearch-pet                   An elasticsearch image for kubernetes PetSets   1                    [OK]
phenompeople/elasticsearch                   Elasticsearch is a powerful open source sear…   1                    [OK]
kuzzleio/elasticsearch                       Elasticsearch container based on Alpine Linu…   1                    [OK]
axway/elasticsearch-docker-beat              "Beat" extension to read logs of containers …   1                    [OK]
wreulicke/elasticsearch                      elasticsearch                                   0                    [OK]
travix/elasticsearch-kubernetes              To run ElasticSearch in kubernetes and expor…   0                    [OK]

2.拉取镜像

[sandwich@192 ~]$ docker pull docker.io/elasticsearch:$version

拉取镜像的时候,可以指定版本,如果不指定,默认使用latest。

3.查看镜像

[sandwich@192 ~]$ docker images
REPOSITORY      TAG       IMAGE ID       CREATED       SIZE
elasticsearch   latest    5acf0e8da90b   3 years ago   486MB

4.运行容器

[sandwich@192 ~]$ docker run -d --name es01 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" 5acf0e8da90b
ca732e87f83aa571ee6d72ae237a0bb78b8db41b6553461471f247f0b3e4405e

5.查看容器

#查看正在运行的容器
[sandwich@192 ~]$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
#查看所有容器,包括未运行的容器
[sandwich@192 ~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS                          PORTS     NAMES
ca732e87f83a   5acf0e8da90b   "/docker-entrypoint.…"   About a minute ago   Exited (1) About a minute ago             es01

由此可见容器启动之后自动退出了,通过日志查看退出原因

[sandwich@192 ~]$ docker logs ca732e87f83a
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /tmp/hs_err_pid1.log

由此可见是分配内存的时候失败了
查看jvm的默认配置位置

[sandwich@192 ~]$ sudo find / -name jvm.options
[sudo] password for sandwich: 
find: ‘/run/user/1000/gvfs’: Permission denied
/var/lib/docker/overlay2/749000cce1a8140569f7126ef74f2ca3e860becd2025715796644cad8ee5fbb6/diff/etc/elasticsearch/jvm.options
[sandwich@192 ~]$ sudo less /var/lib/docker/overlay2/749000cce1a8140569f7126ef74f2ca3e860becd2025715796644cad8ee5fbb6/diff/etc/elasticsearch/jvm.options

可以查到jvm默认配置是固定的2g内存,但是这个虚拟机内存大小才1G
在这里插入图片描述
在这里插入图片描述
修改vm option的内存,重新运行

[sandwich@192 ~]$ docker run -d -e "ES_JAVA_OPTS=-Xms512m -Xmx512m"  --name es02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" 5acf0e8da90b
fc749e192a0fb0ab9c03b4a7a28a5d62f84d6f24cea37e4cd5c2dd5dfc2c646d
[sandwich@192 ~]$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                                  NAMES
fc749e192a0f   5acf0e8da90b   "/docker-entrypoint.…"   9 seconds ago   Up 7 seconds   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   es02

容器跑起来了。
通过浏览器ip+port访问
在这里插入图片描述

6.进入容器修改elasticsearch.yml配置

# 进入容器
[sandwich@192 ~]$ docker exec -it es02 /bin/bash
root@fc749e192a0f:/usr/share/elasticsearch# ls
NOTICE.txt  README.textile  bin  config  data  lib  logs  modules  plugins
root@fc749e192a0f:/usr/share/elasticsearch# cd config/
root@fc749e192a0f:/usr/share/elasticsearch/config# ls
elasticsearch.yml  log4j2.properties  scripts
root@fc749e192a0f:/usr/share/elasticsearch/config# vi elasticsearch.yml
bash: vi: command not found
root@fc749e192a0f:/usr/share/elasticsearch/config# vim elasticsearch.yml
bash: vim: command not found

由此可知容器里面并没有安装vi和vim, 先安装编辑工具

apt-get update
apt-get install vim

然后给elasticsearch.yml文件添加如下内容
在这里插入图片描述

cluster.name:自定义集群名称。
network.host:当前es节点绑定的ip地址,默认127.0.0.1,如果需要开放对外访问这个属性必须设置。
http.cors.enabled:是否支持跨域,默认为false。
http.cors.allow-origin:当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。

退出容器内部

root@fc749e192a0f:/usr/share/elasticsearch/config# exit
exit

7.重启容器

[sandwich@192 ~]$ docker restart es02
es02

重启访问不了了
在这里插入图片描述
又出了问题,继续检查问题。

[sandwich@192 ~]$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[sandwich@192 ~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS                         PORTS     NAMES
fc749e192a0f   5acf0e8da90b   "/docker-entrypoint.…"   36 minutes ago      Exited (78) 58 seconds ago               es02
ca732e87f83a   5acf0e8da90b   "/docker-entrypoint.…"   About an hour ago   Exited (1) About an hour ago             es01
# 由以上信息可知容器已经挂掉了
# 查看日志
[sandwich@192 ~]$ docker logs fc749e192a0f
[2021-10-31T19:15:08,517][INFO ][o.e.n.Node               ] [] initializing ...
[2021-10-31T19:15:08,716][INFO ][o.e.e.NodeEnvironment    ] [0-jtb3l] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/nvme0n1p3)]], net usable_space [11.7gb], net total_space [17.6gb], spins? [possibly], types [xfs]
[2021-10-31T19:15:08,717][INFO ][o.e.e.NodeEnvironment    ] [0-jtb3l] heap size [503.6mb], compressed ordinary object pointers [true]
[2021-10-31T19:15:08,718][INFO ][o.e.n.Node               ] node name [0-jtb3l] derived from node ID [0-jtb3liR_S7CLVAUIaa4w]; set [node.name] to override
[2021-10-31T19:15:08,718][INFO ][o.e.n.Node               ] version[5.6.12], pid[1], build[cfe3d9f/2018-09-10T20:12:43.732Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_181/25.181-b13]
[2021-10-31T19:15:08,720][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Xms512m, -Xmx512m, -Des.path.home=/usr/share/elasticsearch]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [aggs-matrix-stats]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [ingest-common]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-expression]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-groovy]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-mustache]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-painless]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [parent-join]
[2021-10-31T19:15:10,838][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [percolator]
[2021-10-31T19:15:10,839][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [reindex]
[2021-10-31T19:15:10,839][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [transport-netty3]
[2021-10-31T19:15:10,839][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [transport-netty4]
[2021-10-31T19:15:10,839][INFO ][o.e.p.PluginsService     ] [0-jtb3l] no plugins loaded
[2021-10-31T19:15:14,739][INFO ][o.e.d.DiscoveryModule    ] [0-jtb3l] using discovery type [zen]
[2021-10-31T19:15:15,575][INFO ][o.e.n.Node               ] initialized
[2021-10-31T19:15:15,575][INFO ][o.e.n.Node               ] [0-jtb3l] starting ...
[2021-10-31T19:15:15,783][INFO ][o.e.t.TransportService   ] [0-jtb3l] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2021-10-31T19:15:15,799][WARN ][o.e.b.BootstrapChecks    ] [0-jtb3l] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2021-10-31T19:15:18,881][INFO ][o.e.c.s.ClusterService   ] [0-jtb3l] new_master {0-jtb3l}{0-jtb3liR_S7CLVAUIaa4w}{GwpjUGDzSJqdgaw0MOBNKg}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[, ]
[2021-10-31T19:15:18,921][INFO ][o.e.h.n.Netty4HttpServerTransport] [0-jtb3l] publish_address {172.17.0.2:9200}, bound_addresses {0.0.0.0:9200}
[2021-10-31T19:15:18,922][INFO ][o.e.n.Node               ] [0-jtb3l] started
[2021-10-31T19:15:18,925][INFO ][o.e.g.GatewayService     ] [0-jtb3l] recovered [0] indices into cluster_state
[2021-10-31T19:50:14,265][INFO ][o.e.n.Node               ] [0-jtb3l] stopping ...
[2021-10-31T19:50:14,283][INFO ][o.e.n.Node               ] [0-jtb3l] stopped
[2021-10-31T19:50:14,283][INFO ][o.e.n.Node               ] [0-jtb3l] closing ...
[2021-10-31T19:50:14,298][INFO ][o.e.n.Node               ] [0-jtb3l] closed
[2021-10-31T19:50:18,927][INFO ][o.e.n.Node               ] [] initializing ...
[2021-10-31T19:50:19,105][INFO ][o.e.e.NodeEnvironment    ] [0-jtb3l] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/nvme0n1p3)]], net usable_space [11.6gb], net total_space [17.6gb], spins? [possibly], types [xfs]
[2021-10-31T19:50:19,105][INFO ][o.e.e.NodeEnvironment    ] [0-jtb3l] heap size [503.6mb], compressed ordinary object pointers [true]
[2021-10-31T19:50:19,106][INFO ][o.e.n.Node               ] node name [0-jtb3l] derived from node ID [0-jtb3liR_S7CLVAUIaa4w]; set [node.name] to override
[2021-10-31T19:50:19,107][INFO ][o.e.n.Node               ] version[5.6.12], pid[1], build[cfe3d9f/2018-09-10T20:12:43.732Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_181/25.181-b13]
[2021-10-31T19:50:19,107][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Xms512m, -Xmx512m, -Des.path.home=/usr/share/elasticsearch]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [aggs-matrix-stats]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [ingest-common]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-expression]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-groovy]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-mustache]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [lang-painless]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [parent-join]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [percolator]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [reindex]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [transport-netty3]
[2021-10-31T19:50:21,617][INFO ][o.e.p.PluginsService     ] [0-jtb3l] loaded module [transport-netty4]
[2021-10-31T19:50:21,618][INFO ][o.e.p.PluginsService     ] [0-jtb3l] no plugins loaded
[2021-10-31T19:50:24,860][INFO ][o.e.d.DiscoveryModule    ] [0-jtb3l] using discovery type [zen]
[2021-10-31T19:50:25,685][INFO ][o.e.n.Node               ] initialized
[2021-10-31T19:50:25,686][INFO ][o.e.n.Node               ] [0-jtb3l] starting ...
[2021-10-31T19:50:25,898][INFO ][o.e.t.TransportService   ] [0-jtb3l] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300}
[2021-10-31T19:50:25,912][INFO ][o.e.b.BootstrapChecks    ] [0-jtb3l] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2021-10-31T19:50:25,928][INFO ][o.e.n.Node               ] [0-jtb3l] stopping ...
[2021-10-31T19:50:25,949][INFO ][o.e.n.Node               ] [0-jtb3l] stopped
[2021-10-31T19:50:25,949][INFO ][o.e.n.Node               ] [0-jtb3l] closing ...
[2021-10-31T19:50:25,970][INFO ][o.e.n.Node               ] [0-jtb3l] closed

由以上日志可以看出是JVM的512m内存太小了,内存不足VM尝试去获取虚拟内存,结果虚拟内存也小,就直接退出了。
把内存加大到2G
在这里插入图片描述
重新启动容器

[sandwich@192 ~]$ docker run -d -e "ES_JAVA_OPTS=-Xms1g -Xmx1g"  --name es04 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" 5acf0e8da90b
68cbaa21f39d1598756e72cbea102076620c02ac29b88879f678890b079873f8

并按照之前的步骤修改elasticsearch.yml,并重启es4

[sandwich@192 etc]$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                                  NAMES
1e0597047577   5acf0e8da90b   "/docker-entrypoint.…"   6 minutes ago   Up 6 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   es04
[sandwich@192 etc]$ docker restart ex04
Error response from daemon: No such container: ex04
[sandwich@192 etc]$ docker restart es04
es04

看到修改后的cluster name
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT三明治

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值