ubuntu 搭建 ceph

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]
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值