docker安装elasticsearch 7.4.2

参考链接1
参考链接2

1.首先下载镜像

docker pull elasticsearch:7.4.2			

2.启动容器

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /temp/cloud_elk/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /temp/cloud_elk/elasticsearch/data:/usr/share/elasticsearch/data \
-v /temp/cloud_elk/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2

注意
第一次启动docker会把elasticsearch.yml生成目录修改成文件。然后修改文件内容以后重启即可!

# 集群名称
cluster.name: my-cluster
# 节点名称
node.name: node-1
# 绑定的网络接口地址
network.host: 0.0.0.0
# 是否支持跨域,默认为false
http.cors.enabled: true

重启命令

docker restart elasticsearch

方式一:

如果启动失败,可以尝试调整ES_JAVA_OPTS=“-Xms64m -Xmx128m"加大内存

方式二:

如果是ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];”,
原因是缺少读写使用 ,增加权限即可

chmod -R 777 /temp/cloud_elk/elasticsearch/

其他:

如果加大内存后仍启动失败使用命令:docker logs elasticsearch 查看日志详细信息并百度找寻答案

启动成功测试:

curl -X GET http://localhost:9200/

返回结果如下!

{
  "name" : "node-1",
  "cluster_name" : "my-cluster",
  "cluster_uuid" : "N7zJ4qPIQ5Oz-kDgyj9cBw",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

如果访问显示curl: (56) Recv failure: Connection reset by peer,就是访问失败!
注意配置文件是否正确,然后重启。
如果是购买的服务器,在测试时,请注意防火墙和端口的开放问题!

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