ubuntu 搭建 ceph

本文详细介绍了如何在 Ubuntu 16.04 系统上搭建 Ceph 存储集群,包括配置主机、更新源、安装 ntpdate 和 ssh、创建 Ceph 部署应用以及搭建集群的步骤。重点讲解了如何通过 ceph-deploy 工具创建用户、免登陆设置、安装 ceph-deploy,以及初始化 monitor 节点和激活 OSD。

ubuntu 搭建 ceph

首先理解三个概念: 文件存储系统,快存储系统,对象存储系统

准备工作:

  • 虚拟机三台:
    ip: 192.168.87.132 ceph-admin
    ip: 192.168.87.133 node0
    ip: 192.168.87.134 node1
    系统: ubuntu 16.04

1.配置节点host

为了方便后边安装,以及 ssh 方式连接各个节点,我们先修改一下各个节点的 Hostname 以及配置 Hosts 如下:

ceph-admin(192.168.87.132)

$ cat /etc/hostname 
admin

$ cat /etc/hosts

192.168.87.132 admin
192.168.87.133 node0
192.168.87.134 node1

-----------------------------
node0(192.168.87.133) 
$ cat /etc/hostname 
node0

$ cat /etc/hosts

192.168.87.132 admin
192.168.87.133 node0
192.168.87.134 node1

-----------------------------
node1(192.168.87.134) 
$ cat /etc/hostname 
node1

$ cat /etc/hosts

192.168.87.132 admin
192.168.87.133 node0
192.168.87.134 node1

2.更新源

添加 release key

wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add -

添加Ceph软件包源,用Ceph稳定版(如 luminous 等等)替换掉 {ceph-stable-release}

将这条信息写入/etc/apt/sources.list

echo deb https://download.ceph.com/debian-luminous/ $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/ceph.list

更新系统更新源,3台服务器执行以下命令

sudo apt-get clean
sudp apt-get update

3.安装 ntpdate(解决时区问题) 和 ssh(无密码登录)

务必保证3台服务器的时区是一样的,强制更改时区为上海,执行以下命令

ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
bash -c "echo 'Asia/Shanghai' > /etc/timezone"

安装ntpdate

apt-get install -y ntpdate

使用阿里云的时间服务器更新

ntpdate ntp1.aliyun.com

3台服务器都执行一下,确保时间一致!

后续操作,ceph-deploy 节点需要使用 ssh 方式登录各个节点完成 ceph 安装配置工作,所以要确保各个节点上有可用 SSH 服务。

sudo apt-get install openssh-server -y

4.创建 Ceph 部署应用

ceph-deploy 工具必须以普通用户登录 Ceph 节点,且此用户拥有无密码使用 sudo 的权限,因为它需要在安装软件及配置文件的过程中,不必输入密码。官方建议所有 Ceph 节点上给 ceph-deploy 创建一个特定的用户,而且不要使用 ceph 这个名字。这里为了方便,我们使用 cephd 这个账户作为特定的用户,而且每个节点上(admin-node、node0、node1)上都需要创建该账户,并且拥有 sudo 权限。

(1).建立用户
# 在 Ceph 集群各节点进行如下操作

# 创建 ceph 特定用户
# -d<登入目录>:指定用户登入时的启始目录;
# -m:自动建立用户的登入目录;
$ sudo useradd -d /home/cephd -m cephd
$ sudo passwd cephd

# 添加 sudo 权限
$ echo "cephd ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephd
$ sudo chmod 0440 /etc/sudoers.d/cephd
(2).免登陆

接下来在 ceph-deploy 节点(admin-node)上,切换到 cephd 用户,生成 SSH 密钥并把其公钥分发到各 Ceph 节点上,注意使用 cephd 账户生成,且提示输入密码时,直接回车,因为它需要免密码登录到各个节点。

# ceph-deploy (admin-node) 上执行

# 生成 ssh 密钥
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cephd/.ssh/id_rsa): 
Created directory '/home/cephd/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/cephd/.ssh/id_rsa.
Your public key has been saved in /home/cephd/.ssh/id_rsa.pub.
The key fingerprint is:
...

# 将公钥复制到 node0 节点
$ ssh-copy-id cephd@node0
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/cephd/.ssh/id_rsa.pub"
The authenticity of host 'node0 (10.222.77.242)' can't be established.
ECDSA key fingerprint is MD5:3c:e0:a7:a0:e6:3c:dc:c0:df:28:dc:87:16:2d:0f:c6.
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
cephd@node0's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'cephd@node0'"
and check to make sure that only the key(s) you wanted were added.

# 将公钥复制到 node1 节点
$ ssh-copy-id cephd@node1
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/cephd/.ssh/id_rsa.pub"
The authenticity of host 'node1 (10.222.77.253)' can't be established.
ECDSA key fingerprint is MD5:3c:e0:a7:a0:e6:3c:dc:c0:df:28:dc:87:16:2d:0f:c6.
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
cephd@node1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'cephd@node1'"
and check to make sure that only the key(s) you wanted were added.

测试没有问题,接下来,修改 ceph-deploy 管理节点上的 ~/.ssh/config 文件,这样无需每次执行 ceph-deploy 都要指定 –username cephd 。这样做同时也简化了 ssh 和 scp 的用法

$ cat ~/.ssh/config
Host node0
   Hostname node0
   User cephd
Host node1
   Hostname node1
   User cephd

测试一下在 ceph-deploy 管理节点免密码登录各个节点。

$ ssh node0
Last login: Fri Dec  8 15:50:08 2017 from admin

$ ssh node1
Last login: Fri Dec  8 15:49:27 2017 from admin
(3).安装 ceph-deploy
# admin上执行
sudo apt-get install ceph-deploy -y

5.搭建集群

好了,经过上边一系列的预检设置后,我们就可以开始 Ceph 存储集群搭建了,集群结构为 admin-node (ceph-deploy、Monitor)、node0(osd.0)、node1(osd.1)。首先要提一下的是,如果我们在安装过程中出现了问题,需要重新操作的时候,例如想清理我搭建的这个集群的话,可以使用以下命令。

# ceph-deploy (admin-node) 上执行

# 清理配置
ceph-deploy purgedata admin node0 node1
ceph-deploy forgetkeys

# 清理 Ceph 安装包
ceph-deploy purge admin node0 node1

好了,现在开始搭建。首先 Cephd 用户创建一个目录 ceph-cluster 并进入到该目录执行一系列操作。因为我们设计的 monitor 节点在 admin-node 节点上,所以,执行如下命令。

# 创建执行目录
$ mkdir ~/ceph-cluster && cd ~/ceph-cluster

# 创建集群
$ ceph-deploy new admin
[ceph_deploy.conf][DEBUG ] found configuration file at: /home/cephd/.cephdeploy.conf
[ceph_deploy.cli][INFO  ] Invoked (1.5.39): /bin/ceph-deploy new admin
[ceph_deploy.cli][INFO  ] ceph-deploy options:
[ceph_deploy.cli][INFO  ]  username                      : None
[ceph_deploy.cli][INFO  ]  func                          : <function new at 0xf24938>
[ceph_deploy.cli][INFO  ]  verbose                       : False
[ceph_deploy.cli][INFO  ]  overwrite_conf                : False
[ceph_deploy.cli][INFO  ]  quiet                         : False
[ceph_deploy.cli][INFO  ]  cd_conf              
### 安装和配置 Ceph 分布式存储系统 #### 准备工作环境 对于Ubuntu系统的Ceph集群部署,建议每台机器具备至少2核CPU、2GB内存以及10Gbps双网卡连接速度。硬盘空间应不少于20GB,并且操作系统推荐使用稳定版本如Ubuntu 18.04[^2]。 #### 配置软件源并安装Ceph组件 为了确保能够获取最新的Ceph包,在所有节点上执行如下命令来添加官方仓库: ```bash sudo apt update && sudo apt upgrade -y wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add - echo deb https://download.ceph.com/deb-octopus/ $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/ceph.list sudo apt-get update ``` 接着可以在管理节点和其他节点上通过`apt install ceph-common -y`指令完成基础工具集的安装[^1]。 #### 初始化Monitor服务 选择一台作为初始MON监控器节点,运行以下脚本来设置第一个监视进程实例: ```bash sudo cephadm bootstrap --mon-ip <monitor_node_ip> ``` 此过程会自动生成必要的密钥环文件并将它们保存到当前目录下;同时还会创建默认的CRUSH映射表结构用于后续的数据分布策略定义。 #### 添加其他Monitors和服务节点 利用刚才生成的管理员证书材料,可以继续向集群中加入更多的监视者或者其他类型的守护程序(OSD/MGR)。例如要增加一个新的MDS元数据服务器,则需在目标主机执行下面这条语句: ```bash ssh root@<new_mds_host> "hostnamectl set-hostname mds.<cluster_fqdn>" scp ~/ceph.conf ~/client.admin.keyring root@mds.<cluster_fqdn>:~ ssh root@mds.<cluster_fqdn> "mkdir -R ceph:ceph /var/lib/ceph" ceph orch host add mds.<cluster_fqdn> ceph orch apply mds myfs --placement="1 mds.<cluster_fqdn>" ``` 这里假设新成员被命名为`mds.<cluster_fqdn>`,并且属于名为`myfs`的文件系统的一部分。 #### 创建Pool资源池 当整个架构搭建完毕之后就可以着手建立实际用来承载对象存储单元的对象池了。比如想要新建一个叫做`testpool`的通用型容器,只需简单调用一次API请求即可实现目的: ```bash sudo docker exec mon ceph osd pool create testpool 64 64 ``` 上述操作指定了PG数量均为64个副本,默认采用Erasure Coding纠删码模式进行冗余保护[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值