Red Hat Training

A Red Hat training course is available for Red Hat Ceph Storage

4.3. 恢复 monitor 存储

Ceph 监控器将 cluster map 存储在 LevelDB 等键值存储中。如果存储在 monitor 上损坏,monitor 会意外终止,无法再次启动。Ceph 日志可能包括以下错误:

Corruption: error in middle of record
Corruption: 1 missing files; e.g.: /var/lib/ceph/mon/mon.0/store.db/1234567.ldb

生产集群必须使用至少三个 monitor,以便在出现故障时可以替换为另一个 monitor。然而,在某些情况下,所有 monitor 都可损坏存储。例如,当 monitor 节点配置错误的磁盘或文件系统设置时,断电可能会破坏底层文件系统。

如果存储在所有 monitor 中损坏,您可以使用 OSD 节点上存储的信息恢复它,方法是使用名为 ceph-monstore-toolceph-objectstore-tool 的工具。

重要

此流程无法恢复以下信息:

  • 元数据守护进程服务器(MDS)密钥环和映射
  • 放置组设置:

    • full ratio 使用 ceph pg set_full_ratio 命令设置
    • nearfull ratio 使用 ceph pg set_nearfull_ratio 命令设置
重要

切勿从旧备份恢复 monitor 存储。使用以下步骤从当前集群状态重建 monitor 存储,并从中恢复。

开始前

  • 确定您安装了 rsync 实用程序和 ceph-test 软件包。

步骤:恢复 monitor 存储

从带有损坏存储的 monitor 节点使用以下命令:

  1. 从所有 OSD 节点收集 cluster map:

    ms=<directory>
    mkdir $ms
    
    for host in $host_list; do
      rsync -avz "$ms" root@$host:"$ms"; rm -rf "$ms"
      ssh root@$host <<EOF
      for osd in  /var/lib/ceph/osd/ceph-*; do
        ceph-objectstore-tool --data-path \$osd --op update-mon-db --mon-store-path $ms
      done
    EOF
    rsync -avz root@$host:$ms $ms; done

    使用临时目录替换 <directory> 来存储收集的集群映射,例如:

    $ ms=/tmp/monstore/
    $ mkdir $ms
    $ for host in $host_list; do
      rsync -avz "$ms" root@$host:"$ms"; rm -rf "$ms"
      ssh root@$host <<EOF
      for osd in  /var/lib/ceph/osd/ceph-*; do
        ceph-objectstore-tool --data-path \$osd --op update-mon-db --mon-store-path $ms
      done
    EOF
    rsync -avz root@$host:$ms $ms; done
  2. 设置适当的功能:

    ceph-authtool <keyring>  -n mon. --cap mon 'allow *'
    ceph-authtool <keyring>  -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *'

    使用客户端管理密钥环的路径替换 <keyring>,例如:

    $ ceph-authtool /etc/ceph/ceph.client.admin.keyring  -n mon. --cap mon 'allow *'
    $ ceph-authtool /etc/ceph/ceph.client.admin.keyring  -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *'
  3. 从收集的 map 重建 monitor 存储:

    ceph-monstore-tool <directory> rebuild -- --keyring <keyring>

    使用第一步中的临时目录替换 <directory>,使用到客户端管理密钥环的路径替换 <keyring>,例如:

    $ ceph-monstore-tool /tmp/mon-store rebuild -- --keyring /etc/ceph/ceph.client.admin.keyring
    注意

    如果您不使用 cephfx 身份验证,省略 --keyring 选项:

    $ ceph-monstore-tool /tmp/mon-store rebuild
  4. 备份损坏的存储:

    mv /var/lib/ceph/mon/<mon-ID>/store.db \
       /var/lib/ceph/mon/<mon-ID>/store.db.corrupted

    使用 monitor ID 替换 <mon-ID>,例如 <mon.0>

    # mv /var/lib/ceph/mon/mon.0/store.db \
         /var/lib/ceph/mon/mon.0/store.db.corrupted
  5. 替换损坏的存储:

    mv /tmp/mon-store/store.db /var/lib/ceph/mon/<mon-ID>/store.db

    使用 monitor ID 替换 <mon-ID>,例如 <mon.0>

    # mv /tmp/mon-store/store.db /var/lib/ceph/mon/mon.0/store.db

    对所有存储损坏的 monitor 重复此步骤。

  6. 更改新存储的所有者:

    chown -R ceph:ceph /var/lib/ceph/mon/<mon-ID>/store.db

    使用 monitor ID 替换 <mon-ID>,例如 <mon.0>

    # chown -R ceph:ceph /var/lib/ceph/mon/mon.0/store.db

    对所有存储损坏的 monitor 重复此步骤。

另请参阅