docker安装elasticsearch

启动elasticsearch

  • 下载Elasticsearch7.17.5的docker镜像:
docker pull elasticsearch:7.17.5
  • 修改虚拟内存区域大小,否则会因为过小而无法启动:
sysctl -w vm.max_map_count=262144
  • 使用如下命令启动Elasticsearch服务,内存小的服务器可以通过ES_JAVA_OPTS来设置占用内存大小:
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.17.5

docker run -p 9200:9200 -p 9300:9300 --name es \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-e "ingest.geoip.downloader.enabled=false" \
-v /Users/eternity/tool/elastic/plugins:/usr/share/elasticsearch/plugins \
-v /Users/eternity/tool/elastic/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.17.5
  • 启动报错,"stacktrace": ["org.elasticsearch.ElasticsearchException: not all primary shards of [.geoip_databases] index are active",是因为启动时会去更新地图的一些数据库,这里直接禁掉即可,ingest.geoip.downloader.enabled=false``
  • 启动时会发现/usr/share/elasticsearch/data目录没有访问权限,只需要修改/mydata/elasticsearch/data目录的权限,再重新启动即可;
chmod 777 /mydata/elasticsearch/data/
docker restart elasticsearch
  • 开启防火墙:
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload
{
    "name": "4739231e3c6a",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "NybOghB6RkW0etsn7WFvRA",
    "version": {
        "number": "7.17.5",
        "build_flavor": "default",
        "build_type": "docker",
        "build_hash": "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
        "build_date": "2022-06-23T21:57:28.736740635Z",
        "build_snapshot": false,
        "lucene_version": "8.11.1",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
}
posted @ 2023-01-10 13:50  未月廿三  阅读(392)  评论(0编辑  收藏  举报