根据服务器情况修改系统配置 /etc/sysctl.conf
vm.max_map_count=520288

fs.file-max=20000000
fs.aio-max-nr=262144
vm.memory_failure_early_kill=1
vm.max_map_count=135217728
net.ipv4.ip_local_port_range=40000 60999



选创建专用网络

docker network create es-net


下载镜像 版本号要不一定要太高的,否则可能没有对应的IK和kibana
ElasticsearchKibanaX-PackBeats^*Elastic Agent^*Logstash^*ES-Hadoop (jar)APM ServerApp SearchEnterprise SearchConnector Clients*Elastic Endgame 
版本号对应关系查看:http://www.elastic.co/cn/support/matrix#matrix_compatibility

docker pull docker.elastic.co/elasticsearch/elasticsearch:8.7.0

镜像名太长了改成es
docker tag 镜像id es


docker rmi docker.elastic.co/elasticsearch/elasticsearch:8.7.0

安装单机版本,

#先安装一个默认版本
docker run -d --name es \
-e "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" \
-e "discovery.type=single-node" \
--privileged \
--network es-net \
-p 9200:9200 \
-p 9300:9300 \
es:8.7.0
复制容器配置文件 
docker cp es:/usr/share/elasticsearch/config /dp/vm/es1
创建目录 /dp/vm/es1/data  /dp/vm/es1/plugins /dp/vm/es1/logs
设置权限chmod 777 /dp/vm/es1/*
删除容器
重新创建
docker run -d --name es \
-e "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" \
-e "discovery.type=single-node" \
-v /dp/vm/es/config:/usr/share/elasticsearch/config \
-v /dp/vm/es/data:/usr/share/elasticsearch/data \
-v /dp/vm/es/logs:/usr/share/elasticsearch/logs \
-v /dp/vm/es/plugins:/usr/share/elasticsearch/plugins \
--privileged \
--network es-net \
-p 9200:9200 \
-p 9300:9300 \
es:8.7.0

说明:
-e "cluster.name=es-docker-cluster":设置集群名称
-e "http.host=0.0.0.0":监听的地址,可以外网访问
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m":内存大小
-e "discovery.type=single-node":非集群模式
-v /dp/vm/es/config:/usr/share/elasticsearch/config 挂载逻辑卷,绑定 es 的数据目录
--privileged:授予逻辑卷访问权
--network es-net :加入一个名为 es-net 的网络中
-p 9200:9200:端口映射配置

es8 默认开启安全功能, 外部无法直接访问:
修改配置文件 vi /dp/vm/es/config/elasticsearch.yml

把xpack.security.enabled: true 改成false
xpack.security.enabled: false
xpack.security.enrollment.enabled: false

重启容器访问curl http://127.0.0.1:9200返回一个json格式表示访问成功
{
{
  "name" : "d9697c48c7bf",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "KX2VwdB0Q5qfGCc0VbJ8aw",
  "version" : {
    "number" : "8.7.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "09520b59b6bc1057340b55750186466ea715e30e",
    "build_date" : "2023-03-27T16:31:09.816451435Z",
    "build_snapshot" : false,
    "lucene_version" : "9.5.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}