docker之Elasticsearch镜像安装及运行、整合Zipkin

镜像官网:https://hub.docker.com/

 

 

拉取最新版本的Elasticsearch服务(具体指定版本,可以去上面提供的官网找到):

docker pull elasticsearch

这时候会出一个报错问题(意思就是找不到这个最新版本):

[root@VM_0_13_centos /]# docker pull elasticsearch
Using default tag: latest
Error response from daemon: manifest for elasticsearch:latest not found: manifest unknown: manifest unknown

既然这样,我就指定一个版本呗,指定的也是2020年6月份的最高版本:

[root@VM_0_13_centos /]# docker pull elasticsearch:7.8.0

启动Elasticsearch: 

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.8.0

启动之后,确实启动成功了,但是几秒钟后,会自动停止,查看日志:

docker logs 2adc715a3a9a   	# 查看某个容器的日志

结果(大概意思就是内存不够):

[root@VM_0_13_centos /]# docker logs 2adc715a3a9a
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid132.log
error:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 1073741824, 0) failed; error='Not enough space' (errno=12)
        at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:126)
        at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:88)
        at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:59)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:137)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:95)
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid132.log
error:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 1073741824, 0) failed; error='Not enough space' (errno=12)
        at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:126)
        at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:88)
        at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:59)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:137)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:95)
[root@VM_0_13_centos /]# 

 这时候需要先找出开始运行的容器:

docker ps -a

然后将之前启动的容器删除(为每次启动出问题的时候,最好将上面 和 这步执行一次): 

docker rm 2adc715a3a9a

解决内存溢出的启动命令:启动命令加一个:        -e "ES_JAVA_OPTS=-Xms512m -Xmx512m"       也可以再大一点。

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" elasticsearch:7.8.0

启动完毕后访问: http://119.27.184.220:9200/   这是我搭建的,访问效果一样则证明Elasticsearch搭建成功。
其实就是一段json数据。

 


如果启动依然不成功,毕竟测试服务器的内存是很小的:

最终版解决方案:

执行:

find / -name jvm.options

执行:(后面的文件地址就是上面查的文件地址,一定要找目录有elasticsearch的目录地址)

vim /var/lib/docker/overlay2/08455b2d4591981dc85d3c6b737d84a7731fecccf903f044ac3ebaaad81f2b3d/diff/usr/share/elasticsearch/config/jvm.options

修改配置:(然后wq命令保存即可)我解释一下:这个配置就是指定Elasticsearch启动需要的最小内存。

#-Xms1g   # 注释掉
#-Xmx1g   # 注释掉
-Xms512m   #修改   一定要比当前服务器剩余内存空间小
-Xmx512m   # 修改  一定要比当前服务器剩余内存空间小

 再执行  elasticsearch启动命令:

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.8.0

然后等2分钟,再访问  http://当前ip地址:9200/   访问成功出现json数据就好了。


 

上面是使用docker启动Elasticsearch。

当Zipkin搭建好了之后,需要Zipkin绑定启动Elasticsearch ,除此之外还可以让zipkin同时绑定Rabbitmq 和 Elasticsearch
Zipkin服务端部署传送门:Docker之Zipkin服务端部署,及整合RabbitMq、Elasticsearch

 

写好了。

 

你可能感兴趣的:(SpringCloud,docker)