docker运行ElasticSearch
拉取最新版镜像下载最新版ElasticSearchdocker pull elasticsearch默认会使用latestd的tag拉取最新版本,但是报错了Using default tag: latestError response from daemon: manifest for elasticsearch:latest not found: manifest unknown: manife
拉取最新版镜像
下载最新版ElasticSearch
docker pull elasticsearch
默认会使用latestd的tag拉取最新版本,但是报错了
Using default tag: latest
Error response from daemon: manifest for elasticsearch:latest not found: manifest unknown: manifest unknown
大致意思是,找不最新版?what,那我们手动指定版本
docker search没有提供查看所有版本的能力,我们可以去华为云的官方地址上查看最新版本https://mirrors.huaweicloud.com/elasticsearch/
目前最新版是7.8.0,ok我们指定版本为7.8.0
[root@qcy ~]# docker pull elasticsearch:7.8.0
7.8.0: Pulling from library/elasticsearch
524b0c1e57f8: Pull complete
7a096b8f20be: Pull complete
9dd8117fbfec: Pull complete
335891dbdd0e: Pull complete
dfce820717b4: Pull complete
82d3459719f7: Pull complete
2e79822fece3: Pull complete
2f80b981dd6a: Pull complete
05f8a08da0ba: Pull complete
好了,镜像拉取下来了
接着我们运行他
运行
docker run -d -p 9200:9200 -p 9300:9300 --name elastic_search elasticsearch:7.8.0
Elasticsearch 分web(9200)和tcp(9300)两种对外服务接口
docker ps 发现没有启动起来,于是使用docker logs -f 容器id查看日志,发现
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)
看得出来,该版本至少要求JVM拥有1G的内存。可在阿里云上,内存十分的珍贵,这个时候我们可以修改jvm运行的最小内存。
修改JVM内存
首先找到jvm.options文件
[root@qcy ~]# find / -name jvm.options
/var/lib/docker/overlay2/a0dd29c922a8c18e3aac1f569b53641e72dc6f16d76be8e84b04a4e2899f5d2a/diff/usr/share/elasticsearch/config/jvm.options
可以看到,默认要求是1g,云主机上可没那么多的内存,所以就给他128MB吧,呜呜呜
[root@qcy ~]# vi /var/lib/docker/overlay2/a0dd29c922a8c18e3aac1f569b53641e72dc6f16d76be8e84b04a4e2899f5d2a/diff/usr/share/elasticsearch/config/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms128m
-Xmx128m
保存,使用docker start 容器id 启动容器试试
当然,也可以在启动时,使用-e指定jvm内存
docker run -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_POTS="-Xms128m -Xmx128m" --name elastic_search elasticsearch:7.8.0
纳尼?启动还是报错
ERROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log
{"type": "server", "timestamp": "2020-09-11T08:23:09,586Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "793a3c13cb16", "message": "stopping ..." }
{"type": "server", "timestamp": "2020-09-11T08:23:09,606Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "793a3c13cb16", "message": "stopped" }
{"type": "server", "timestamp": "2020-09-11T08:23:09,606Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "793a3c13cb16", "message": "closing ..." }
{"type": "server", "timestamp": "2020-09-11T08:23:09,627Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "793a3c13cb16", "message": "closed" }
{"type": "server", "timestamp": "2020-09-11T08:23:09,629Z", "level": "INFO", "component": "o.e.x.m.p.NativeController", "cluster.name": "docker-cluster", "node.name": "793a3c13cb16", "message": "Native controller process has stopped - no new native processes can be started" }
提升进程的虚拟内存空间
修改sysctl.conf配置
vi /etc/sysctl.conf
在最后一行添加
vm.max_map_count=262144
接着
[root@qcy ~]# sysctl -p
sysctl -p 的意思是从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载
这次再启动,应该没什么问题了吧?
然鹅,事实是报了一个新的错误
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log
配置为单机
由于我们暂时是单机部署的,需要指定为单节点模式,修改启动命令,加上-e "discovery.type=single-node"
docker run -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_POTS="-Xms128m -Xmx128m" -e "discovery.type=single-node" --name elastic_search elasticsearch:7.8.0
再次启动,终于不报错了,舒服了。
检查服务运行情况
如果是云主机上,记得在防火墙中开放9200端口。这个时候访问ip:9200,可以得到以下信息:
{
"name" : "6a3a276b4e66",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "62g1XzSxSGWGH3VU4sbQog",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
"build_date" : "2020-06-14T19:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
说明服务运行正常
更多推荐
所有评论(0)