手动部署Ceph octopus集群

网友投稿 683 2023-04-16

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

手动部署Ceph octopus集群

基础配置

三台环境为centos7.9,以下配置需要在每台机器上执行

配置hosts解析

cat >> /etc/hosts <

关闭防火墙和selinux

systemctl stop firewalld && systemctl disable firewalld setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

分别在三个节点设置主机名

hostnamectl set-hostname node1 hostnamectl set-hostname node2 hostnamectl set-hostname node3

配置主机时间同步

systemctl restart chronyd.service && systemctl enable chronyd.service

使用yum安装

安装yum-plugin-priorities

yum install yum-plugin-priorities

安装依赖包

yum install snappy leveldb gdisk python-argparse gperftools-libs epel-release

添加ceph仓库

建议使用阿里的源,国外的太慢了

安装ceph

yum install ceph -y

部署monitor节点

所有 Ceph 群集至少需要一个monitor,并且至少需要与存储在群集上的对象副本一样多的 OSD。引导初始mon是部署 Ceph 存储群集的第一步,这里我直接在node1、node2、node3创建三个mon。

在node1添加monitor

为集群生成唯一的fsid,fsid是群集的唯一标识符,代表 Ceph 存储群集主要用于 Ceph 文件系统的文件系统 ID

uuidgen

创建ceph配置文件,将生成的fsid添加到配置文件中

vim /etc/ceph/ceph.repo [global] fsid=9c079a1f-6fc2-4c59-bd4d-e8bc232d33a4

为群集创建keyring并生成monitor keyring。monitor通过密钥相互通信。必须生成具有monitor密钥的keyring,并在引导初始monitor时提供keyring。

ceph-authtool --create-keyring /tmp/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'

生成管理员keyring,生成用户并将用户添加到client.admin keyring中。要使用 CLI 工具,必须有一个用户,并且还必须将用户添加到monitor keyring。

ceph-authtool --create-keyring /etc/ceph/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *'

生成引导 osd 密钥,生成用户并将用户添加到client.bootstrap-osd keyring中。

ceph-authtool --create-keyring /var/lib/ceph/bootstrap-osd/ceph.keyring --gen-key -n client.bootstrap-osd --cap mon 'profile bootstrap-osd' --cap mgr 'allow r'

将生成的键添加到 ceph.mon.keyring

ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.client.admin.keyring ceph-authtool /tmp/ceph.mon.keyring --import-keyring /var/lib/ceph/bootstrap-osd/ceph.keyring

更改 ceph.mon.keyring的所有者。

chown ceph:ceph /tmp/ceph.mon.keyring

使用主机名、主机 IP 地址和 FSID 生成monitor映射。将其保存为 :/tmp/monmap

monmaptool --create --add node1 192.168.2.16 --add node2 192.168.2.19 --add node3 192.168.2.18 --fsid 9c079a1f-6fc2-4c59-bd4d-e8bc232d33a4 /tmp/monmap

查看生成的monitor映射文件

monmaptool --print /tmp/monmap

在monitor主机上创建默认数据目录,目录名是{cluster-name}-{hostname}格式

mkdir /var/lib/ceph/mon/ceph-node1 chmod 777 -R /var/lib/ceph/mon/ceph-node3

在node1节点对monitor进行初始化

ceph-mon --mkfs -i node1 --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring

可以查看数据目录生成的文件

编辑ceph配置文件

[global] fsid = 9c079a1f-6fc2-4c59-bd4d-e8bc232d33a4 mon initial members = node1,node2,node3 mon host = 192.168.2.16,192.168.2.19,192.168.2.18 mon clock drift allowed = .5 auth cluster required = cephx auth service required = cephx auth client required = cephx osd pool default size = 3  //创建pool的时候默认pool是3副本 osd pool default min size = 2   //pool最少可写的副本数为2 osd pool default pg num = 8 osd pool default pgp num = 8 osd crush chooseleaf type = 0

将配置文件拷贝到其他节点

scp /etc/ceph/ceph.conf node2:/etc/ceph/ceph.conf scp /etc/ceph/ceph.conf node3:/etc/ceph/ceph.conf

将mon keyring,mon map及admin keyring拷贝到其他节点

scp /tmp/ceph.mon.keyring node2:/tmp/ceph.mon.keyring scp /etc/ceph/ceph.client.admin.keyring node2:/etc/ceph/ceph.client.admin.keyring scp /tmp/monmap node2:/tmp/monmap scp /tmp/ceph.mon.keyring node3:/tmp/ceph.mon.keyring scp /etc/ceph/ceph.client.admin.keyring node3:/etc/ceph/ceph.client.admin.keyring scp /tmp/monmap node3:/tmp/monmap

在node2、node3上添加monitor

分别在这两个节点创建数据目录

mkdir /var/lib/ceph/mon/ceph-node2 chmod 777 -R /var/lib/ceph/mon/ceph-node2 mkdir /var/lib/ceph/mon/ceph-node3 chmod 777 -R /var/lib/ceph/mon/ceph-node3

分别在这两个节点对monitor进行初始化

ceph-mon --mkfs -i node2 --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring ceph-mon --mkfs -i node3 --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring

分别在三个节点启动ceph-mon服务

systemctl start ceph-mon@node1 && systemctl enable ceph-mon@node1 systemctl start ceph-mon@node2 && systemctl enable ceph-mon@node2 systemctl start ceph-mon@node3 && systemctl enable ceph-mon@node3

image.png

可以看到提示3 monitors have not enabled msgr2"

执行以下命令恢复正常

ceph mon enable-msgr2

image.png

创建MGR

在运行ceph-mon守护程序的每个节点上,还应该设置一个ceph-mgr守护程序。

创建密钥目录

所有mgr节点都要执行

sudo -u ceph mkdir /var/lib/ceph/mgr/ceph-`hostname -s` cd /var/lib/ceph/mgr/ceph-`hostname -s`

创建身份验证密钥

ceph auth get-or-create mgr.`hostname -s` mon 'allow profile mgr' osd 'allow *' mds 'allow *' > keyring

启动mgr守护进程

systemctl enable ceph-mgr@`hostname -s` && systemctl start ceph-mgr@`hostname -s`

看样子状态有点异常,在所有节点执行下面的命令之后重启机器即可解决

Module 'restful' has failed dependency: No module named 'pecan'

pip3 install pecan werkzeug

image.png

部署osd

Ceph提供了该ceph-volume实用程序,该实用程序可以准备逻辑卷,磁盘或分区以供Ceph使用。该ceph-volume实用程序通过增加索引来创建OSD ID。

创建osd

在node1执行

ceph-volume lvm create --data /dev/sdb

上面的创建过程可以分为两个阶段(准备和激活):

ceph-volume lvm prepare --data /dev/sdb 查看osd fsid ceph-volume lvm list ceph-volume lvm activate {ID} {FSID}

当创建完osd之后,我们发现osd服务已经起来了

当我们在node2、node3节点执行此命令的时候报错了,发现缺少密钥文件

拷贝密钥文件

scp /var/lib/ceph/bootstrap-osd/ceph.keyring node2:/var/lib/ceph/bootstrap-osd/ceph.keyring scp /var/lib/ceph/bootstrap-osd/ceph.keyring node3:/var/lib/ceph/bootstrap-osd/ceph.keyring

修改密钥属主属组

chown ceph.ceph /var/lib/ceph/bootstrap-osd/ceph.keyring

分别在node2、node3创建osd

ceph-volume lvm create --data /dev/sdb

也可以分步执行

ceph-volume lvm prepare --data /dev/sdb ##获取osd id 和osd fsid ceph-volume lvm list ##激活osd ceph-volume lvm activate {ID} {FSID}

最后状态是这样的

添加MDS

创建mds数据目录

mkdir -p /var/lib/ceph/mds/ceph-`hostname -s` chown -R ceph.ceph /var/lib/ceph/mds/ceph-`hostname -s`

创建keyring

ceph-authtool --create-keyring /var/lib/ceph/mds/ceph-`hostname -s`/keyring --gen-key -n mds.`hostname -s`

导入keyring并设置权限

ceph auth add mds.`hostname -s` osd "allow rwx" mds "allow" mon "allow profile mds" -i /var/lib/ceph/mds/ceph-`hostname -s`/keyring chown ceph:ceph /var/lib/ceph/mds/ceph-`hostname -s`/keyring

修改ceph.conf配置文件

cat >> /etc/ceph/ceph.conf <

启动mds服务

systemctl enable ceph-mds@`hostname -s` && systemctl start ceph-mds@`hostname -s`

现在状态应该是这样的

对象存储RGW安装

RGW是Ceph对象存储网关服务RADOS Gateway的简称,是一套基于LIBRADOS接口封装而实现的FastCGI服务,对外提供RESTful风格的对象存储数据访问和管理接口。RGW基于HTTP协议标准,因此非常适用于Web类的互联网应用场景,用户通过使用SDK或者其他客户端工具,能够很方便地接入RGW进行图片、视频以及各类文件的上传或下载,并设置相应的访问权限,共享给其他用户。

安装radosgw

yum install ceph-radosgw -y

创建rgw相关的资源池

资源池列表及部分资源池功能介绍如下。

.rgw:region和zone配置信息。.rgw.root:region和zone配置信息。.rgw.control:存放notify信息。.rgw.gc:用于资源回收。.rgw.buckets:存放数据。.rgw.buckets.index:存放元数据信息。.rgw.buckets.extra:存放元数据扩展信息。.log:日志存放。.intent-log:日志存放。.usage:存放用户已用容量信息。.users:存放用户信息。.users.email:存放用户E-mail信息。.users.swift:存放swift类型的账号信息。.users.uid:存放用户信息。

ceph osd pool create .rgw 8 8 ceph osd pool create .rgw.root 8 8 ceph osd pool create .rgw.control 8 8 ceph osd pool create .rgw.gc 8 8 ceph osd pool create .rgw.buckets 8 8 ceph osd pool create .rgw.buckets.index 8 8 ceph osd pool create .rgw.buckets.extra 8 8 ceph osd pool create .log 8 8 ceph osd pool create .intent-log 8 8 ceph osd pool create .usage 8 8 ceph osd pool create .users 8 8 ceph osd pool create .users.email 8 8 ceph osd pool create .users.swift 8 8 ceph osd pool create .users.uid 8 8

创建过程会遇到这个报错,原因是每个osd默认最多只支持250个pg,这里有两种解决办法,一种是删除之前创建的pool,并新建pool时把pg设置小一点,另一种则是修改osd默认最大pg数,这里我用了第二种,修改完配置文件后,重启mon

Error ERANGE: pg_num 8 size 3 would mean 771 total pgs, which exceeds max 750 (mon_max_pg_per_osd 250 * num_in_osds 3)

编辑配置文件

vim /etc/ceph/ceph.conf [global] mon_max_pg_per_osd = 1000  #重启mon systemctl restart ceph-mon@`hostname -s`

可以使用rados lspools查看是否创建成功

新建RADOSGW用户和keyring

创建keyring

ceph-authtool --create-keyring /etc/ceph/ceph.client.radosgw.keyring chown ceph:ceph /etc/ceph/ceph.client.radosgw.keyring

生成ceph-radosgw服务对应的用户和key

ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.rgw.node1 --gen-key ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.rgw.node2 --gen-key ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.rgw.node3 --gen-key

添加用户访问权限

ceph-authtool -n client.rgw.node1 --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring ceph-authtool -n client.rgw.node2 --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring ceph-authtool -n client.rgw.node3 --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring

将keyring导入集群中

ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.rgw.node1 -i /etc/ceph/ceph.client.radosgw.keyring ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.rgw.node2 -i /etc/ceph/ceph.client.radosgw.keyring ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.rgw.node3 -i /etc/ceph/ceph.client.radosgw.keyring

编辑配置文件

cat >> /etc/ceph/ceph.conf << EOF [client.rgw.node1] host=node1 keyring=/etc/ceph/ceph.client.radosgw.keyring log file=/var/log/radosgw/client.radosgw.gateway.log rgw_frontends = civetweb port=8080 [client.rgw.node2] host=node2 keyring=/etc/ceph/ceph.client.radosgw.keyring log file=/var/log/radosgw/client.radosgw.gateway.log rgw_frontends = civetweb port=8080 [client.rgw.node3] host=node3 keyring=/etc/ceph/ceph.client.radosgw.keyring log file=/var/log/radosgw/client.radosgw.gateway.log rgw_frontends = civetweb port=8080 EOF

创建日志目录

mkdir /var/log/radosgw chown ceph:ceph /var/log/radosgw

拷贝keyring、ceph.confceph.conf到node2、node3

scp /etc/ceph/ceph.client.radosgw.keyring node2:/etc/ceph/ceph.client.radosgw.keyring scp /etc/ceph/ceph.client.radosgw.keyring node3:/etc/ceph/ceph.client.radosgw.keyring scp /etc/ceph/ceph.conf node2:/etc/ceph/ceph.conf scp /etc/ceph/ceph.conf node3:/etc/ceph/ceph.conf

在node2、node3部署RGW

修改keyring属主

chown ceph:ceph /etc/ceph/ceph.client.radosgw.keyring

创建日志目录并授权

mkdir /var/log/radosgw chown ceph:ceph /var/log/radosgw

启动rgw服务

systemctl start ceph-radosgw@rgw.`hostname -s` && systemctl enable ceph-radosgw@rgw.`hostname -s`

查看ceph状态,发现有个小问题

使用ceph health detail查看详情,根据提示enable即可

使用curl访问服务

上一篇:一文搞懂Undo Log版本链与ReadView机制如何让事务读取到该读的数据
下一篇:Zabbix5.2实战系列之如何开启Https(LAMP)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~