Ceph Cluster

参考:

无桌面的Linux虚拟机安装(CentOS)(一)_vmware安装centos7 不要桌面-CSDN博客

[centOS7安装使用cephadm](https://www.cnblogs.com/zhangrui153169/p/17749717.html

bootstrap-a-new-cluster

ip划分

hostnameipgateway
admin192.168.1.2192.168.1.1
DNS服务器192.168.1.1
物理机192.168.1.3192.168.1.1
node1192.168.1.4192.168.1.1
node2192.168.1.5192.168.1.1
node3192.168.1.6192.168.1.1
cephclient192.168.1.7192.168.1.1

password: 888999

物理机ip配置检查pannel中的vmware network adapter vmnet8,其中ipv4的属性配置分配了ip地址192.168.1.3

主机解析

 root
 vim /etc/hosts
 ​
 加入
 192.168.1.2 admin
 192.168.1.4 node1
 192.168.1.5 node2
 192.168.1.6 node3
 192.168.1.7 cephclient
 ​
 后边的名称应该于hostname对应

修改主机名

 使用hostname node1 可以修改主机名称
 sudo hostnamectl set-hostname node1 
 命令会同时更新/etc/hostname和/etc/hosts文件,并且更改会立即生效并保留到下次重启。

交给admin节点root权限

 交给admin节点在node123和cephclient上的root权限
 ​
 sudo visudo
 编辑sudoers文件,在root   ALL=(ALL)   ALL下加入:
 cephadmin       ALL=(root)      NOPASSWD:ALL

genertate the key for admin

 ssh-keygen
 ​
 ssh-keygen 是一个用于生成、管理和转换SSH密钥的命令行工具。通过使用 ssh-keygen,可以创建新的SSH密钥对,包括私钥和公钥,这些密钥用于SSH认证,以便在不输入密码的情况下远程登录到服务器。
 ​
 (默认情况下,私钥保存在 ~/.ssh/id_rsa,公钥保存在~/.ssh/id_rsa.pub):
 ​
 ssh-keygen -t rsa -b 4096
 这个命令会生成一个4096位的RSA密钥对。-t rsa 指定了密钥类型为RSA,-b 4096 指定了密钥长度为4096位。
 ​
 使用这个密钥对进行SSH登录,需要将公钥(.pub 文件)复制到远程服务器的 ~/.ssh/authorized_keys 文件中。可以手动完成这个过程,或者使用 ssh-copy-id 工具来自动完成。
 ​
 ssh-copy-id user@remote_host
 其中 user 是远程服务器上的用户名,remote_host 是远程服务器的地址。
 ​
 一旦公钥被添加到远程服务器的 authorized_keys 文件中,就可以使用SSH密钥对进行无密码登录了。
 前面我们在 /etc/hosts中添加了主机ip以及主机名
 这里也可以
 ssh-copy-id node1@node1
 ​
 后续通过
 ssh node1@node1远程登陆
 第一次添加,控制台输出了:
 ​
 $ ssh-copy-id node1@node1
 ​
 /bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/cephadmin/.ssh/id_rsa.pub"
 The authenticity of host 'node1 (192.168.1.4)' can't be established.
 ECDSA key fingerprint is SHA256:/vTi9FmUt4+u9Mj6rORC2gqXiZNzson+j18x6KYmDec.
 ECDSA key fingerprint is MD5:16:f4:26:f6:c8:b9:de:33:ea:29:60:78:cb:55:4c:0b.
 Are you sure you want to continue connecting (yes/no)? yes
 /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
 /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
 ​
 ​
 公钥来源:ssh-copy-id 命令识别到公钥文件位于/home/cephadmin/.ssh/id_rsa.pub。这是默认的公钥文件位置
 ​
 主机认证:当第一次连接到一个新的远程服务器时,SSH客户端会询问是否信任该服务器的主机密钥。这是因为SSH客户端需要验证服务器的身份,以防止中间人攻击。看到的ECDSA和MD5指纹就是远程服务器的主机密钥的指纹。
 ​
 确认连接:系统询问是否确认继续连接。已经输入了 yes确认了服务器的主机密钥,并且同意继续复制公钥的操作。
 ​
 安装公钥:ssh-copy-id 命令正在尝试使用新生成的密钥登录远程服务器,以确定哪些密钥需要被安装到 ~/.ssh/authorized_keys 文件中。

ready to install cephadm

 REQUIREMENTS
 ​
 Python 3
 ​
 Systemd
 ​
 Podman or Docker for running containers
 ​
 Time synchronization (such as Chrony or the legacy ntpd)
 ​
 LVM2 for provisioning storage devices

intall python3

 Python 3:
 root下
 cephadm需要Python 3来运行。你可以通过运行以下命令来验证Python 3是否已经安装以及其版本:
 python3 --version
 如果Python 3未安装,你可以通过包管理器安装它。在CentOS上,你可以使用以下命令:
 yum install -y python3

intall systemd

 cephadm依赖于Systemd来管理守护进程和服务。大多数现代Linux发行版都使用Systemd作为默认的初始化系统。你可以通过运行以下命令来检查Systemd是否在你的系统上运行:
 systemctl --version
 [cephadmin@admin ~]$ systemctl --version
 systemd 219
 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN

intall docker

 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 
 安装docker所需依赖,-y表示安装过程中一些询问自动回复yes
 ​
 添加Docker的官方仓库到你的系统中。
 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 ​
 安装Docker Engine - Community:
 从Docker仓库中安装最新版本的Docker Engine - Community。
 sudo yum install -y docker-ce docker-ce-cli containerd.io
 y
 docker --version
 ​
 sudo systemctl start docker 
 sudo systemctl enable docker 设置docker开机启动
 ​
 sudo systemctl status docker 查看docker是否运行

intall lvm2

 LVM2 for provisioning storage devices:
 ​
 LVM2(逻辑卷管理器)是Linux下常用的磁盘管理工具,用于创建和管理逻辑卷,这对于配置Ceph存储设备是必要的。你可以通过运行以下命令来检查LVM2是否安装:
 lvm version
 如果LVM2未安装,你可以使用以下命令来安装它:
 sudo yum install lvm2
 ​
 实际上这是安装docker前必需的东西,在前面安装docker前已经添加了

intall chronyd

 Time synchronization:
 ​
 为了确保集群中的所有节点时间同步,你需要安装和配置时间同步服务,如Chrony或ntpd。你可以通过运行以下命令来检查这些服务的状态:
 systemctl status chronyd    # 对于Chrony
 systemctl status ntpd      # 对于ntpd
 ​
 在虚拟机中已经配置并运行了chrony服务。

同步admin,client以及三个node的时间

 admin中操作
 vim /etc/chrony.conf
 server ntp1.aliyun.com iburst
 server ntp2.aliyun.com iburst
 ​
 allow 192.168.1.0/24
 ​
 其余节点:
 配置它们的 /etc/chrony.conf 文件
 server 192.168.1.2 iburst 这里也可以用admin,即主机名替代ip,我们已经在hosts中解析过主机了。
 启动并设置 chronyd 服务开机自启:
 sudo systemctl start chronyd
 sudo systemctl enable chronyd
 chronyc sources 验证时间同步状态

close SELINUX and firewall

why do we need to close them before intalling cephadm?

  1. 集群通信:Ceph集群中的节点需要相互通信以同步状态、交换数据和执行集群操作。如果防火墙设置不当,可能会阻止这些必要的通信,导致集群无法正常工作。

  2. 服务端口:Ceph使用多个端口来运行其服务。如果在安装cephadm时防火墙没有关闭,可能需要手动打开这些端口,这可能会增加配置的复杂性。

  3. 简化安装过程:在安装过程中关闭防火墙可以简化配置步骤,避免在安装过程中遇到网络相关的错误。Ceph集群涉及多个服务和守护进程之间的复杂交互,这些服务可能需要访问特定的文件和端口。SELinux的严格策略可能会阻止这些访问,导致集群配置和运行出现问题。

  4. 测试和验证:在测试和验证Ceph集群的安装和配置时,关闭防火墙可以确保所有的测试都能在没有网络干扰的情况下进行。

  5. 避免依赖服务被阻止:Ceph集群可能需要访问外部服务,如Docker或Podman镜像仓库,防火墙可能会阻止这些服务的访问。

 临时关闭SELINUX
 setenforce 0
 永久关闭SELinux,可以编辑/etc/selinux/config文件,将SELINUX=enforcing 更改为 SELINUX=disabled,然后重启系统。
 sestatus 可用于检查是否启动了SELINUX
 ​
 关闭防火墙
 systemctl stop firewalld
 systemctl disable firewalld
 ​
 systemctl enable firewalld重新启动防火墙

设置阿里云镜像加速器

 vim /etc/docker/daemon.json
 {
   "registry-mirrors": ["https://lerc8rqe.mirror.aliyuncs.com"]
 }
 ​
 systemctl daemon-reload
 systemctl restart docker
 docker info
 滑动至底部可以看到
 Registry Mirrors:
   https://lerc8rqe.mirror.aliyuncs.com/

安装cephadm

 使用 curl 获取 cephadm 脚本的最新版本
 cd /root/
 curl --remote-name --location https://github.com/ceph/ceph/raw/pacific/src/cephadm/cephadm
 chmod +x cephadm
 ​
 参考这里,我们选择name为Quincy的这一版本
 https://docs.ceph.com/en/latest/releases/#active-releases
 ​
 # ./cephadm add-repo --release <ceph_version,such as octopus>
 ./cephadm add-repo --release Quincy
 但得到response:
 Ceph does not support pacific or later for this version of this linux distro and therefore cannot add a repo for it
 ​
 故改为较低版本的Octopus
 ./cephadm add-repo --release Octopus
 ​
 response:
 Writing repo to /etc/yum.repos.d/ceph.repo...
 Enabling EPEL...
 Completed adding repo.
 然后添加成功
 ​
 # 修改镜像源为国内阿里云地址
 sed -i 's/download.ceph.com/mirrors.aliyun.com\/ceph/' /etc/yum.repos.d/ceph.repo
 sed -i 's/release.gpg/release.asc/' /etc/yum.repos.d/ceph.repo
 这两个 sed 命令用于修改 /etc/yum.repos.d/ceph.repo 文件,将 Ceph 仓库的地址更改为阿里云的镜像地址,以加快下载速度。第一个命令替换了基础URL,第二个命令更改了GPG密钥文件的路径。
 ​
 ​
 # 安装cephadm
 ./cephadm install
 ​
 确认 cephadm 是否已加入 PATH 环境变量
 which cephadm
  
 返回如下内容表示添加成功
 /usr/sbin/cephadm

create a new cluster

admin上操作

执行命令

The first step in creating a new Ceph cluster is running the cephadm bootstrap command on the Ceph cluster’s first host. The act of running the cephadm bootstrap command on the Ceph cluster’s first host creates the Ceph cluster’s first Monitor daemon. You must pass the IP address of the Ceph cluster’s first host to the ceph bootstrap command, so you’ll need to know the IP address of that host.

创建个新Ceph集群的第一步是在集群控制节点使用 cephadm bootstrap命令。该命令会创建Ceph集群的第一个监视守护进程。你必须把集群的控制节点的ip传递给这个命令。

 cephadm bootstrap --mon-ip 192.168.1.2

分析命令的回复

 运行得到回复:
 Verifying podman|docker is present...
 Verifying lvm2 is present...
 Verifying time synchronization is in place...
 ​
 Unit chronyd.service is enabled and running
 Repeating the final host check...
 podman|docker (/usr/bin/docker) is present
 systemctl is present
 lvcreate is present
 Unit chronyd.service is enabled and running
 ​
 Host looks OK
 Cluster fsid: f739d924-eb18-11ee-8ee9-000c29b038d5
 ​
 Verifying IP 192.168.1.2 port 3300 ...
 Verifying IP 192.168.1.2 port 6789 ...
 Mon IP 192.168.1.2 is in CIDR network 192.168.1.0/24
 ​
 验证lvm2, chronyd, docker 
 Pulling container image quay.io/ceph/ceph:v15...
 cephadm 开始从容器镜像仓库(在这个例子中是 quay.io)拉取 Ceph 的容器镜像(版本标记为 v15)。这是设置 Ceph 集群的一个关键步骤,因为 Ceph 的各种守护进程和工具将作为容器运行。
 ​
 Extracting ceph user uid/gid from container image...
 Creating initial keys...
 Creating initial monmap...
 Creating mon...
 Waiting for mon to start...
 Waiting for mon...
 ​
 mon is available
 Assimilating anything we can from ceph.conf...
 Generating new minimal ceph.conf...
 ​
 Restarting the monitor...
 Setting mon public_network...
 ​
 Creating mgr...
 Verifying port 9283 ...
 ​
 Wrote keyring to /etc/ceph/ceph.client.admin.keyring
 表示 Ceph 集群的管理员密钥环已经被创建并保存在 文件中。这个密钥环包含了用于集群管理操作的密钥。
 ​
 Wrote config to /etc/ceph/ceph.conf
 Ceph 集群的配置文件已经被创建并保存文件中。这个配置文件包含了集群的各种设置和参数,是集群操作的基础。
  
 Waiting for mgr to start...
 Waiting for mgr...
 mgr not available, waiting (1/10)...
 mgr not available, waiting (2/10)...
 mgr not available, waiting (3/10)...
 mgr not available, waiting (4/10)...
 mgr is available
 管理节点已经准备好接受命令和处理请求,可以开始使用 Ceph 的管理功能了。
 ​
 Enabling cephadm module...
 Waiting for the mgr to restart...
 Waiting for Mgr epoch 5...
 Mgr epoch 5 is available
 Setting orchestrator backend to cephadm...
 启用cephadm木块,重启mgr
生成ssh密钥
 Generating ssh key...
 Wrote public SSH key to to /etc/ceph/ceph.pub
 Adding key to root@localhost's authorized_keys...
 Adding host admin...
 生成了ssh密钥并写入文件,公钥添加到ceph.pub和authorized_keys中
 Deploying mon service with default placement...
 Deploying mgr service with default placement...
 Deploying crash service with default placement...
 Enabling mgr prometheus module...
 Deploying prometheus service with default placement...
 Deploying grafana service with default placement...
 Deploying node-exporter service with default placement...
 Deploying alertmanager service with default placement...
 Enabling the dashboard module...
 Waiting for the mgr to restart...
 Waiting for Mgr epoch 13...
 Mgr epoch 13 is available

生成自签名证书

 Generating a dashboard self-signed certificate...
 Creating initial admin user...
 Fetching dashboard port number...
 Ceph Dashboard is now available at:
 ​
          URL: https://admin:8443/
         User: admin
     Password: por0w8z7k6
 #Ceph Dashboard 使用了一个自签名的 SSL 证书来启用安全的 HTTPS 连接。这是为了确保通过 Ceph Dashboard 传输的数据是加密的。创建了初始管理员用户用于登录Dashboard
 ​
 ​
 You can access the Ceph CLI with:
 ​
 sudo /usr/sbin/cephadm shell --fsid f739d924-eb18-11ee-8ee9-000c29b038d5 -c /etc/ceph/ceph.conf -k /etc/ceph/ceph.client.admin.keyring
 #上述命令可用于访问Ceph CLI
 ​
 Please consider enabling telemetry to help improve Ceph:
     ceph telemetry on
 ​
 For more information see:
 https://docs.ceph.com/docs/master/mgr/telemetry/
 #启用遥测模块 ceph telemetry on,以帮助改进 Ceph。遥测模块会将匿名数据发送回 Ceph 开发者,以便更好地了解 Ceph 的使用情况和用户可能遇到的问题。这些数据会在公共仪表板上可视化,让社区可以快速查看集群报告的汇总统计信息。
 ​
 Bootstrap complete.

访问https://admin:8443/

我们虚拟机的网络设置使用的NAT。

虚拟机将通过物理机的网络接口访问外部网络。在这种情况下,虚拟机对于外部网络是隐藏的,但你仍然可以在物理机上通过特定的端口转发规则访问虚拟机。你需要在物理机上设置端口转发,将特定端口的流量转发到虚拟机的IP地址和端口。

浏览器直接输入网址后反馈:

Your connection is not private

Attackers might be trying to steal your information from 192.168.1.2 (for example, passwords, messages, or credit cards). Learn more

NET::ERR_CERT_AUTHORITY_INVALID

直接advanced,确认连接,然后登录我们的账号密码

 URL: https://admin:8443/
 https://192.168.1.2:8443/
         User: admin
     Password: por0w8z7k6
     #修改密码为Mar235may

启用ceph command

The cephadm shell command launches a bash shell in a container with all of the Ceph packages installed. By default, if configuration and keyring files are found in /etc/ceph on the host, they are passed into the container environment so that the shell is fully functional. Note that when executed on a MON host, cephadm shell will infer the config from the MON container instead of using the default configuration. If --mount <path> is given, then the host <path> (file or directory) will appear under /mnt inside the container:

 cephadm shell
 #该命令会登录进一个安装所有Ceph包的容器的bash shell。
 #默认情况下,如果配置文件和密钥在/etc/ceph 中被找到,他们会被传递到容器环境中以便shell功能齐全。
 记住当命令运行在MON host时,它的配置来自MON容器而非默认配置。如果  --mount <path> 被给定,那么 host <path>文件或目录会出现在容器中/mnt下

Confirm that the ceph command is accessible with:

 ceph -v

Confirm that the ceph command can connect to the cluster and also its status with:

 ceph status

方便访问,我们可以在主机上安装 ceph-common 软件包,该软件包包含所有 Ceph 命令,包括 cephrbdmount.ceph

 cephadm install ceph-common

将ceph.pub (集群公钥)配置到其他节点

 # ssh-copy-id -f -i /etc/ceph/ceph.pub root@*<new-host>*
 ​
 ssh-copy-id -f -i  /etc/ceph/ceph.pub root@node1

add hosts

 ceph orch host add node1
 ​
 ceph orch host ls  查看当前集群的系欸但
 HOST   ADDR   LABELS  STATUS  
 admin  admin                  
 node1  node1                  
 node2  node2                  
 node3  node3     
 然后使用ceph -s得到
 cluster:
     id:     f739d924-eb18-11ee-8ee9-000c29b038d5
     health: HEALTH_WARN
             Reduced data availability: 1 pg inactive
             OSD count 0 < osd_pool_default_size 3
  
   services:
     mon: 3 daemons, quorum admin,node2,node1 (age 7m)
     mgr: admin.onaijw(active, since 51m), standbys: node1.qrqsrg
     osd: 0 osds: 0 up, 0 in
 集群有三个监视器(mon)守护进程运行在admin, node2, node1上,并且有一个管理器(mgr)守护进程在admin.onaijw上运行。
 没有OSD部署
  
   data:
     pools:   1 pools, 1 pgs
     objects: 0 objects, 0 B
     usage:   0 B used, 0 B / 0 B avail
     pgs:     100.000% pgs unknown
              1 unknown
              
              

deploy other moniters

 root@admin:
 默认情况下,随着集群的增长,Ceph 会自动部署 MON 守护程序
 ceph orch apply mon 3 修改MON部署的默认数量,默认为5
 ceph orch apply mon --unmanaged 禁用MON自动部署

deploy MGR

 ceph orch ls mgr    查看MGR的数量
 查看具体运行 MGR 的节点可通过如下 
 ceph orch ps --daemon_type mgr
 ​
 扩展MGR节点
 # ceph orch apply mgr *<host1,host2,host3,...>*
 ceph orch apply mgr ceph-mon01,ceph-mon02,ceph-mon03

Deploy OSD

OSD daemons will adjust their memory consumption based on the osd_memory_target config option (several gigabytes, by default). If Ceph is deployed on dedicated nodes that are not sharing memory with other services, cephadm can automatically adjust the per-OSD memory consumption based on the total amount of RAM and the number of deployed OSDs.

OSD守护进程会基于osd_memory_target配置选项来调整他们的存储小号。如果Ceph被部署在指定的不和其他设备共享存储的节点,cephadm会自动调整每一个OSD存储消耗基于RAM的总数和已经部署的OSD的数量。

Both the limits and the current memory consumed by each daemon are visible from the ceph orch ps output in the MEM LIMIT column:

每个守护线程消耗的限制和当前内存都可以通过ceph orch ps查看。

 查看 cephadm 发现的设备列表,可运行以下命令:
 ceph orch device ls
 使用 --wide 选项提供与设备相关的所有详细信息,包括设备可能不适合用作 OSD 的任何原因

It is recommended that advanced OSD specs include the service_id field set. The plain osd service with no service id is where OSDs created using ceph orch daemon add or ceph orch apply osd --all-available-devices are placed. Not including a service_id in your OSD spec would mix the OSDs from your spec with those OSDs and potentially overwrite services specs created by cephadm to track them. Newer versions of cephadm will even block creation of advanced OSD specs without the service_id present.

建议高级的OSD规范包含service_id 字段集。没有service id的普通服务通常被布置在用 ceph orch daemon addceph orch apply osd --all-available-devices创建的OSD中。

方案1: use available device automatically

自动使用任何可用且未使用的存储设备

 ceph orch apply osd --all-available-devices

行上述命令后:

  • 如果向集群中添加新硬盘,将自动用于创建新的 OSD

  • 如果删除 OSD 并清理 LVM 物理卷,将自动创建新的 OSD

如果要禁用在可用设备上自动创建 OSD,可使用非托管参数

 ceph orch apply osd --all-available-devices --unmanaged=true
方案2: specify the device and host

Ceate an OSD from a speicfic device on a specific host:

 ceph orch daemon add osd *<host>*:*<device-path>*
 ​
 ceph orch daemon add osd node1:/dev/sdb
方案3:Service Specification(后续再试)

You can use Advanced OSD Service Specifications to categorize device(s) based on their properties. This might be useful in forming a clearer picture of which devices are available to consume. Properties include device type (SSD or HDD), device model names, size, and the hosts on which the devices exist:

 ceph orch apply -i spec.yml

你可以使用高级OSD服务规范把设备基于属性分类。这也许有助于了解哪些设备是可用的。属性包含设备类型SSD或HDD,设备名称,大小,设备所属主机。

Service Specifications of type osd are a way to describe a cluster layout, using the properties of disks. Service specifications give the user an abstract way to tell Ceph which disks should turn into OSDs with which configurations, without knowing the specifics of device names and paths.

OSD类型的服务规范是一种使用磁盘属性描述集群的方式。服务规范给使用者一种抽象的方式来告诉Ceph那个磁盘应该以哪种配置转换为OSDs,而无需知道设备名称和路径。

for each device and each host, we can define a yaml or json file that allows us to describe the layout. Here’s the most basic example.

对于每一个设备和主机,我们可以定义一个允许我们描述布局的yaml 或者json 文件。这里是一个最基础的例子:

Create a file called (for example) osd_spec.yml:

 service_type: osd
 service_id: default_drive_group  # custom name of the osd spec
 placement:
   host_pattern: '*'              # which hosts to target
 spec:
   data_devices:                  # the type of devices you are applying specs to
     all: true                    # a filter, check below for a full list

This means :

  1. Turn any available device (ceph-volume decides what ‘available’ is) into an OSD on all hosts that match the glob pattern ‘*’. (The glob pattern matches against the registered hosts from host ls) A more detailed section on host_pattern is available below.

    将可用的设备转换为所有主机上匹配glob模式的OSD(glob模式与主机ls中注册了的主机匹配)。下面提供了有关host_pattern的更详细部分。

  2. Then pass it to osd create like this:

     ceph orch apply -i /path/to/osd_spec.yml

    This instruction will be issued to all the matching hosts, and will deploy these OSDs.

    Setups more complex than the one specified by the all filter are possible. See Filters for details.、

    A --dry-run flag can be passed to the apply osd command to display a synopsis of the proposed layout.

    这个指令会被报告给所有匹配的主机并且部署这些OSD。

    可以进行比“all”过滤器指定的设置更复杂的设置。详见过滤器。

    --dry-run 标志可以被传递给 apply osd 命令来展示建议布局的概要。

     ceph orch apply -i /path/to/osd_spec.yml --dry-run
    部署osd_spec.yml
     vim /etc/ceph/osd_spec.yml
Warning

When deploying new OSDs with cephadm, ensure that the ceph-osd package is not already installed on the target host. If it is installed, conflicts may arise in the management and control of the OSD that may lead to errors or unexpected behavior.

在用cephadm部署一个新OSD时,确保 ceph-osd包 在目标主机上没有被安装。如果安装了,在管理控制OSD会发生冲突,可能导致意外的错误或行为。

Create Ceph Block Device

A block is a sequence of bytes (often 512). Block-based storage interfaces are a mature and common way to store data on media including HDDs, SSDs, CDs, floppy disks, and even tape. The ubiquity of block device interfaces is a perfect fit for interacting with mass data storage including Ceph.

Ceph block devices are thin-provisioned, resizable, and store data striped over multiple OSDs. Ceph block devices leverage RADOS capabilities including snapshotting, replication and strong consistency. Ceph block storage clients communicate with Ceph clusters through kernel modules or the librbd library.

一个块是一个比特序列。基于块的存储接口是一个在媒介(HDDs,SSDs,CDs,软盘,磁带等)上存储数据成熟,常用的方法。普遍存在的块设备接口非常适合和包含在Ceph中大量数据进行交互。

Ceph块设备是精简配置,可调整大小的,并且在多个OSDs上存储条带化的数据。Ceph块设备利用RADOS共呢个,包括快照,复制和强一致性。Ceph块存储客户端和Ceph集群通过kernel模块或者librdb库通信。

Basic Block Device Commands

The rbd command enables you to create, list, inspect and remove block device images. You can also use it to clone images, create snapshots, rollback an image to a snapshot, view a snapshot, etc. For details on using the rbd command, see RBD – Manage RADOS Block Device (RBD) Images for details.

rbd命令允许你创建,列表,审查,移除块设备映像。你也可以用它来克隆映像,创建快照,回滚映像到快照,查看一个快照,etc。更多使用rbd的细节看URL。

Create a block device pool
  1. Use the ceph tool to create a pool.

     ceph osd pool create <pool_name> <pg_num> <pgp_num>
    • <pool_name> 是您想要创建的存储池的名称。

    • <pg_num> 是放置数据的 Placement Groups(PGs)的数量。

    • <pgp_num> 是每个 Placement Group 中的副本(plaes)的数量。

    例如,创建一个名为 my_pool 的存储池,包含 8 个 PGs 和 2 个 plaes:

     复制
     ceph osd pool create my_pool 8 2
  2. 启用应用程序

     ceph osd pool application enable mypool <app-name>
     <appname> 可以是 cephfs(Ceph 文件系统)、rbd(RADOS 块设备)、rgw(RADOS 网关,用于对象存储)或者自定义应用程序的名称

  3. Use the rbd tool to initialize the pool for use by RBD:

     rbd pool init <pool-name>

    Note

    The rbd tool assumes a default pool name of ‘rbd’ if no pool name is specified in the command.

rbd工具会设置一个默认池的名字rbd如果没有在命令中给定name。

ceph客户端密钥配置

此时三个节点和client无法和集群通信

需要创建一个Ceph密钥环文件,以便通信。使用ceph auth get-or-create命令创建客户端,并将其输出保存到一个密钥环文件中。

但实际上使用 ceph auth ls 我们可以看到每个客户端的key以及对mon,osd的配置策略。

 ceph auth get-or-create client.<client-name> mon 'allow r' osd 'allow rwx pool=<pool-name>'
  • <client-name> 是您为客户端指定的名称。

  • <pool-name> 是客户端将要与之交互的存储池的名称。

 ceph auth get-or-create client.cephclient mon 'allow r' osd 'allow rwx pool=test'
 密钥允许该客户端以只读方式访问监视器(mon)数据,并允许读写访问名为 test 的存储池。
 ​
 result:
 [client.cephclient]
     key = AQDssgtmHVOQFRAAZvJIh17QOh7dCXjU9ZhIUQ==
     
     
 [root@client cephclient]# ceph-authtool /etc/ceph/client]# scp ./ceph.client.admin.keyring root@node1
 scp ./ceph.client.admin.keyring root@cephclient:/etc/ceph
 [root@admin ceph]# scp ./ceph.client.admin.keyring root@node1 /etc/ceph/
 cp: "./ceph.client.admin.keyring" 与"/etc/ceph/ceph.client.admin.keyring" 为同一文件
 cp: "root@node1" 与"/etc/ceph/root@node1" 为同一文件
 cephclient.keyring --add-key AQDssgtmHVOQFRAAZvJIh17QOh7dCXjU9ZhIUQ==
 added entity client.admin auth(key=AQDssgtmHVOQFRAAZvJIh17QOh7dCXjU9ZhIUQ==)

deploy the Ceph FS

A Ceph file system requires at least two RADOS pools, one for data and one for metadata. There are important considerations when planning these pools:

一个ceph文件系统至少需要两个RADOS池,一个存储数据,一个存元数据。在设计这些池时需要注意:

  • We recommend configuring at least 3 replicas for the metadata pool, as data loss in this pool can render the entire file system inaccessible. Configuring 4 would not be extreme, especially since the metadata pool’s capacity requirements are quite modest.

    我们建议为了元数据池至少配置三个副本,因为池中数据丢失会导致整个文件系统不可用。配置4个不会过多,尤其是当元数据池的能力需求非常适中。

  • We recommend the fastest feasible low-latency storage devices (NVMe, Optane, or at the very least SAS/SATA SSD) for the metadata pool, as this will directly affect the latency of client file system operations.

    我们建议元数据池使用最快可用低延迟存储设备,因为这会直接影响文件系统客户端的操作延迟。

  • We strongly suggest that the CephFS metadata pool be provisioned on dedicated SSD / NVMe OSDs. This ensures that high client workload does not adversely impact metadata operations. See Device classes to configure pools this way.

    我们强烈建议提供指定的SSD或NVMe OSD给文件系统元数据池使用。这确保了高客户端负载不会映像元数据操作。

  • The data pool used to create the file system is the “default” data pool and the location for storing all inode backtrace information, which is used for hard link management and disaster recovery. For this reason, all CephFS inodes have at least one object in the default data pool. If erasure-coded pools are planned for file system data, it is best to configure the default as a replicated pool to improve small-object write and read performance when updating backtraces. Separately, another erasure-coded data pool can be added (see also Erasure code) that can be used on an entire hierarchy of directories and files (see also File layouts).

    用于创建文件系统的数据池是默认的数据池,也是存储所有incode回溯信息的位置,用于硬件链接管理和灾难恢复。由于这个原因,所有CephFS incodes在默认数据池拥有至少一个对象。如果为FS设计了纠删码池,最好将默认池配置为一个复制池以在更新回溯时提高小对象的读写。另外,可以添加额外的纠删码数据池用在文件和目录的层次结构。

 ceph osd pool create cephfs_data
 ceph osd pool create cephfs_metadata
 ​
 ceph fs new <fs_name> <metadata> <data> [--force] [--allow-dangerous-metadata-overlay] [<fscid:int>] [--recover]
 ceph fs new cephfs01 cephfs_metadata cephfs_data
 ceph orch apply mds cephfs01 --placement="3 node1 node2 node3"

Mounting CephFS

General Pre-requisite

此处相关设计cephX,后续补充

挂载cephfs01

挂载前需确保挂载目录下是空的

 ceph-fuse -m node1:6789,node2:6789,node3:6789 /mnt/data
 ​
 参数后面跟的是 Ceph 集群监控器(Monitor)节点的地址和端口,用逗号分隔。这里指定了三个监控器节点 node1、node2 和 node3,每个节点后面跟着的 6789 是 Ceph 集群的监控器端口。
 /mnt/data:这是挂载 CephFS 的本地文件系统路径。
 ​
 ceph-fuse[5909]: starting ceph client
 2024-04-20T15:57:41.411+0800 7fc22c0c1f40 -1 init, newargv = 0x55fa172ea9c0 newargc=9
 ​
 ceph-fuse[5909]: starting fuse
 第一行表明 ceph-fuse 正在启动 Ceph 客户端进程,并显示了进程 ID(在这个例子中是 5909)。
 ​
 第二行是启动时间戳和一些内部参数,用于初始化 Ceph 客户端。
 ​
 第三行表明 FUSE 正在启动,并且 ceph-fuse 进程将开始作为 FUSE 服务运行。
 ​
 ​
 fusermount -u /mnt/data 命令来卸载 FUSE 挂载点

错误处理

部署过程中存在一些疏漏,在此补充:

1.仅有admin可以ceph -s,其他主机不行

其他主机使用ceph -s报错:

 Error initializing cluster client: ObjectNotFound('RADOS object not found (error calling conf_read_file)',)

解决方案:

使用scp将admin的ceph.conf ceph.client.admin.keyring复制到其他节点对应位置。

 # scp ./ceph.client.admin.keyring root@node1:/etc/ceph/
 ceph.client.admin.keyring                             100%   63    57.9KB/s   00:00    
 [root@admin ceph]# scp ./ceph.conf root@node1:/etc/ceph/
 ceph.conf                                             100%  173    80.0KB/s   00:00
 ​
 其他节点使用ceph -s时也需要root权限才行

2.后续相关再补充

  • 16
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值