解决ceph 100.000% pgs not active

这里写自定义目录标题

欢迎使用Markdown编辑器

虚拟机单节点安装完ceph后,只创建了两个OSD,导致状态是100.000% pgs not active,用python rados往pool存数据一直卡着,存不了。

root@controller ceph-test]# ceph -s
  cluster:
    id:     c5544727-e047-47e3-85fc-6cc5dab8b314
    health: HEALTH_WARN
            Reduced data availability: 192 pgs inactive
            Degraded data redundancy: 192 pgs undersized
            OSD count 2 < osd_pool_default_size 3
            mon is allowing insecure global_id reclaim
 
  services:
    mon: 1 daemons, quorum controller (age 13h)
    mgr: controller(active, since 13h)
    osd: 2 osds: 2 up (since 12h), 2 in (since 12h)
 
  data:
    pools:   2 pools, 192 pgs
    objects: 0 objects, 0 B
    usage:   2.0 GiB used, 38 GiB / 40 GiB avail
    pgs:     100.000% pgs not active
             192 undersized+peered

将crush map导出
ceph osd getcrushmap -o /etc/ceph/crushmap
输出5,这一步的输出和osd数量有关系
将crush map反编译为可读模式
crushtool -d /etc/ceph/crushmap -o /etc/ceph/crushmap.txt
修改curshmap,主要是修改OSD级别
sed -i ‘s/step chooseleaf firstn 0 type host/step chooseleaf firstn 0 type osd/’ /etc/ceph/crushmap.txt
grep ‘step chooseleaf’ /etc/ceph/crushmap.txt
输出step chooseleaf firstn 0 type osd
crushtool -c /etc/ceph/crushmap.txt -o /etc/ceph/crushmap-new
将修改过的crush map导入集群
ceph osd setcrushmap -i /etc/ceph/crushmap-new
输出6
现在再看ceph -s,pg没用那个问题了

[root@controller ceph-cluster]# ceph -s
  cluster:
    id:     c5544727-e047-47e3-85fc-6cc5dab8b314
    health: HEALTH_WARN
            Degraded data redundancy: 192 pgs undersized
            OSD count 2 < osd_pool_default_size 3
            mon is allowing insecure global_id reclaim
 
  services:
    mon: 1 daemons, quorum controller (age 13h)
    mgr: controller(active, since 13h)
    osd: 2 osds: 2 up (since 13h), 2 in (since 13h)
 
  data:
    pools:   2 pools, 192 pgs
    objects: 0 objects, 0 B
    usage:   2.0 GiB used, 38 GiB / 40 GiB avail
    pgs:     192 active+undersized

我现在再运行代码,没问题,数据存进去了,对象名是/root/ceph-test/123.txt

[root@controller ceph-test]# python pooltest.py 
Object contents = /root/ceph-test/123.txt
[root@controller ceph-test]# rados -p data2 ls
/root/ceph-test/123.txt
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
使用 `cephfs.MountInfo` 也可以实现上面的问题。下面是使用 `cephfs.MountInfo` 的代码: ```go package main import ( "fmt" "io/ioutil" "github.com/ceph/go-ceph/cephfs" ) func main() { // 获取一个 Ceph 连接 mountInfo, err := cephfs.NewMountInfo("", "", "/etc/ceph/ceph.conf") if err != nil { panic(err) } defer mountInfo.Destroy() // 挂载 Ceph 文件系统 err = mountInfo.Mount() if err != nil { panic(err) } defer mountInfo.Unmount() // 创建一个文件并写入数据 fs, err := cephfs.New(mountInfo.Context()) if err != nil { panic(err) } defer fs.Shutdown() file, err := fs.OpenFile("/test.txt", cephfs.O_CREATE|cephfs.O_WRONLY, 0644) if err != nil { panic(err) } defer file.Close() _, err = file.Write([]byte("Hello world!")) if err != nil { panic(err) } // 读取文件内容 data, err := ioutil.ReadFile("/mnt/myceph/test.txt") if err != nil { panic(err) } fmt.Println(string(data)) } ``` 在代码中,我们使用 `cephfs.NewMountInfo()` 方法获取一个 `cephfs.MountInfo` 对象,并使用 `/etc/ceph/ceph.conf` 配置文件来连接 Ceph 集群。然后,我们使用 `mountInfo.Mount()` 方法挂载 Ceph 文件系统,使用 `cephfs.New()` 方法创建一个 `Ceph` 对象,通过 `fs.OpenFile()` 方法创建 `/test.txt` 文件并向文件中写入数据。 需要注意的是,使用 `cephfs.MountInfo` 挂载文件系统时,需要手动调用 `mountInfo.Unmount()` 方法来卸载文件系统,而不是使用 `Ceph` 对象的 `fs.Shutdown()` 方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值