首页 > 解决方案 > 将 AWS EBS 挂载到 CoreOS

问题描述

我已经启动了一个具有 100Gb EBS 的 EC2 实例作为https://coreos.com/os/docs/latest/booting-on-ec2.html文档。

#cloud-config
coreos:
  units:
    - name: media-ephemeral.mount
      command: start
      content: |
        [Mount]
        What=/dev/xvdb
        Where=/media/ephemeral
        Type=ext4
    - name: format-ephemeral.service
      command: start
      content: |
        [Unit]
        Description=Formats the ephemeral drive
        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/usr/sbin/wipefs -f /dev/xvdb
        ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdb
    - name: var-lib-docker.mount
      command: start
      content: |
        [Unit]
        Description=Mount ephemeral to /var/lib/docker
        Requires=format-ephemeral.service
        After=format-ephemeral.service
        Before=docker.service
        [Mount]
        What=/dev/xvdb
        Where=/var/lib/docker
        Type=btrfs

如果我运行上述程序,EBS 已正确安装,但在系统重新启动时,卷不是持久的

使用

storage:
  filesystems:
    - name: ephemeral1
      mount:
        device: /dev/xvdb
        format: ext4
        wipe_filesystem: true
systemd:
  units:
    - name: media-ephemeral.mount
      enable: true
      contents: |
        [Unit]
        Before=local-fs.target
        [Mount]
        What=/dev/xvdb
        Where=/media/ephemeral
        Type=ext4
        [Install]
        WantedBy=local-fs.target
    - name: var-lib-docker.mount
      enable: true
      contents: |
        [Unit]
        Description=Mount ephemeral to /var/lib/docker
        Before=local-fs.target
        [Mount]
        What=/dev/xvdb
        Where=/var/lib/docker
        Type=ext4
        [Install]
        WantedBy=local-fs.target
    - name: docker.service
      dropins:
        - name: 10-wait-docker.conf
          contents: |
            [Unit]
            After=var-lib-docker.mount
            Requires=var-lib-docker.mount

根据文档,我得到

core@ip-10-1-2-188 ~ $ sudo /usr/bin/coreos-cloudinit --from-file storage1.conf
2019/01/15 17:09:28 Checking availability of "local-file"
2019/01/15 17:09:28 Fetching user-data from datasource of type "local-file"
2019/01/15 17:09:28 line 2: warning: unrecognized key "storage"
2019/01/15 17:09:28 line 9: warning: unrecognized key "systemd"
2019/01/15 17:09:28 Fetching meta-data from datasource of type "local-file"
2019/01/15 17:09:28 Parsing user-data as cloud-config
2019/01/15 17:09:28 Merging cloud-config from meta-data and user-data
2019/01/15 17:09:28 Updated /etc/environment
2019/01/15 17:09:28 Ensuring runtime unit file "etcd.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "etcd2.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "fleet.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "locksmithd.service" is unmasked

core@ip-10-1-2-188 ~ $ cat /etc/os-release
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1967.3.0
VERSION_ID=1967.3.0
BUILD_ID=2019-01-08-0044
PRETTY_NAME="Container Linux by CoreOS 1967.3.0 (Rhyolite)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://issues.coreos.com"
COREOS_BOARD="amd64-usr"

在 CoreOS 上挂载 EBS 卷的正确方法是什么?

非常感谢任何建议

标签: amazon-ec2coreos

解决方案


看起来你错过了一步。[cloud-configs 已经被弃用了一段时间。您正确地将云配置转换为容器 linux 配置(CLC) 文件,但错过了使用配置转译器(CT) 然后渲染点火序列。您可以通过在线验证器运行配置来检查这一点。通过配置转译器运行该 CLC 配置后,我得到以下内容,它可以正确验证:

{
  "ignition": {
    "config": {},
    "timeouts": {},
    "version": "2.1.0"
  },
  "networkd": {},
  "passwd": {},
  "storage": {
    "filesystems": [
      {
        "mount": {
          "device": "/dev/xvdb",
          "format": "ext4",
          "wipeFilesystem": true
        },
        "name": "ephemeral1"
      }
    ]
  },
  "systemd": {
    "units": [
      {
        "contents": "[Unit]\nBefore=local-fs.target\n[Mount]\nWhat=/dev/xvdb\nWhere=/media/ephemeral\nType=ext4\n[Install]\nWantedBy=local-fs.target\n",
        "enable": true,
        "name": "media-ephemeral.mount"
      },
      {
        "contents": "[Unit]\nDescription=Mount ephemeral to /var/lib/docker\nBefore=local-fs.target\n[Mount]\nWhat=/dev/xvdb\nWhere=/var/lib/docker\nType=ext4\n[Install]\nWantedBy=local-fs.target\n",
        "enable": true,
        "name": "var-lib-docker.mount"
      },
      {
        "dropins": [
          {
            "contents": "[Unit]\nAfter=var-lib-docker.mount\nRequires=var-lib-docker.mount\n",
            "name": "10-wait-docker.conf"
          }
        ],
        "name": "docker.service"
      }
    ]
  }
}

此外,重要的是要注意和之间还有其他差异。其中最重要的是点火只运行一次。因此,对于诸如擦除该临时磁盘的内容之类的事情,您不应该期望每次启动都运行。ignitioncoreos-cloud-initwipe_filesystem: true

尝试使用此配置启动机器。你应该得到预期的结果。


推荐阅读