使用Docker安裝ElasticSearch 以及我遇到的問題
-
第一步先准備好需要掛載到docker里面的目錄和文件
例如:mkdir -p /usr/local/esdata/config mkdir -p /usr/local/esdata/data mkdir -p /usr/local/esdata/plugins vi /usr/local/esdata/config/elasticsearch.yml #文本輸入如下 http.host: 0.0.0.0
2.第二步下載並啟動es容器
docker run
--name elasticsearch
-p 9200:9200
-p 9300:9300 -e "discovery.type=single-node"
-e ES_JAVA_OPTS="-Xms64m -Xmx128m"
-v /usr/local/esdata/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /usr/local/esdata/data:/usr/share/es/data
-v /usr/local/esdata/plugins:/usr/share/elasticsearch/plugins
-d elasticsearch:7.7.0
直接docker run Docker會自動pull
記錄一下我安裝時遇到的問題:
Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/usr/local/mydata/config/elasticsearch.yml\\\" to rootfs \\\"/var/lib/docker/overlay2/c4fc8e876eb44269911cd4ddb18c9039df0bd26c93a6d26642a8a6c2b17510c5/merged\\\" at \\\"/var/lib/docker/overlay2/c4fc8e876eb44269911cd4ddb18c9039df0bd26c93a6d26642a8a6c2b17510c5/merged/usr/share/elasticsearch/config/elasticsearch.yml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Error: failed to start containers: elasticsearch
這句報錯的重點是這一句:
mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
意思是說掛載的 elasticsearch.yml 是一個目錄而不是文件,粗心將路徑寫錯了,修改了之后成功啟動es容器

值得一提的是kibana和es版本要一致否則就會kibana連接就會失敗
