CoreOS 上具有持久存储的 ElasticSearch 容器

CoreOS 上具有持久存储的 ElasticSearch 容器

我正在尝试运行ElasticSearchDocker 上的集群和 DigitalOcean 上的 CoreOS [stable]。为了让持久存储工作,我尝试了几乎所有的选项,但没有什么主意。

几乎每个 --volume 选项(-v /data/elasticsearch,,-v $(pwd)/esdata:/data/elasticsearch...)都会被忽略,并且在日志中会显示using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/vda9)]]

仅在使用时-v /usr/share/elasticsearch/data:/data/elasticsearch我收到一条错误消息,提示无法在只读文件系统上写入。

我究竟做错了什么?

完整的 elasticsearch.service 是:

[Unit]
Description=ElasticSearch service
After=docker.service
Requires=docker.service

[Service]
TimeoutSec=180
EnvironmentFile=/etc/environment

ExecStartPre=/usr/bin/mkdir -p /data/elasticsearch
ExecStartPre=/usr/bin/docker pull elasticsearch

ExecStart=/bin/bash -c '\
  curl -f ${COREOS_PRIVATE_IPV4}:4001/v2/keys/services/elasticsearch; \
  if [ "$?" = "0" ]; then \
      UNICAST_HOSTS=$(etcdctl ls --recursive /services/elasticsearch \
                      | sed "s/\/services\/elasticsearch\///g" \
                      | sed "s/$/:9300/" \
                      | paste -s -d","); \
  else \
      UNICAST_HOSTS=""; \
  fi; \
  /usr/bin/docker run \
    -v /data/elasticsearch \
    --name %p-%i \
    --net=host \
    elasticsearch \
    --node.name=%p-%i \
    --cluster.name=mysearchcluster \
    --network.publish_host=${COREOS_PRIVATE_IPV4} \
    --discovery.zen.ping.multicast.enabled=false \
    --discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS'

ExecStop=/usr/bin/docker stop %p-%i
ExecStop=/usr/bin/docker rm %p-%i

[X-Fleet]
X-Conflicts=%p@*.service

答案1

在单个节点上运行时,ElasticSearch 不会将任何内容放入 /data/elasticsearch。当我部署多个节点时,就有数据了,而且似乎是持久的。最终的 .service 文件:

[Unit]
Description=ElasticSearch service
After=docker.service
Requires=docker.service

[Service]
TimeoutSec=180
EnvironmentFile=/etc/environment

ExecStartPre=/usr/bin/mkdir -p /data/elasticsearch
ExecStartPre=/usr/bin/docker pull elasticsearch

ExecStart=/bin/bash -c '\
  curl -f ${COREOS_PRIVATE_IPV4}:4001/v2/keys/services/elasticsearch; \
  if [ "$?" = "0" ]; then \
      UNICAST_HOSTS=$(etcdctl ls --recursive /services/elasticsearch \
                      | sed "s/\/services\/elasticsearch\///g" \
                      | sed "s/$/:9300/" \
                      | paste -s -d","); \
  else \
      UNICAST_HOSTS=""; \
  fi; \
  /usr/bin/docker run \
    --volume /data/elasticsearch:/usr/share/elasticsearch/data \
    --name %p-%i \
    --net=host \
    elasticsearch \
    --node.name=%p-%i \
    --cluster.name=myescluster \
    --network.publish_host=${COREOS_PRIVATE_IPV4} \
    --discovery.zen.ping.multicast.enabled=false \
    --discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS'

ExecStop=/usr/bin/docker stop %p-%i
ExecStop=/usr/bin/docker rm %p-%i

[X-Fleet]
X-Conflicts=%p@*.service

相关内容