本次实验我们主要 centos 7 系统上来搭建ceph 集群
准备工作
主机 | IP地址 |
---|---|
s1(主) | 192.168.1.10 |
s2 | 192.168.1.20 |
s3 | 192.168.1.30 |
关闭防火墙以及selinux
[root@s1 ~]# systemctl stop firewalld
[root@s1 ~]# systemctl disable firewalld
[root@s1 ~]# vi /etc/selinux/config
......
SELINUX=disabled
......
[root@s1 ~]# setenforce 0
以上操作三个节点都需要配置
修改本地hosts文件
[root@s1 ~]# vi /etc/hosts //修改hosts文件添加主机记录
192.168.1.10 s1
192.168.1.20 s2
192.168.1.30 s3
[root@s1 ~]# scp /etc/hosts root@s2:/etc/hosts //使用远程复制将修改的文件发送到其他节点上
[root@s1 ~]# scp /etc/hosts root@s3:/etc/hosts
配置本地yum 源
ceph 专用源的网站:
https://mirrors.aliyun.com/ceph/rpm-mimic/el7/noarch/
[root@s1 ~]# yum install -y https://mirrors.aliyun.com/ceph/rpm-mimic/el7/noarch/ceph-deploy-2.0.1-0.noarch.rpm python-setuptools //下载ceph专用源 以及python这个工具
注:三个节点都需要执行这一步
配置时间同步
s1 节点的操作(s1 节点作为集群中的时间服务器)
[root@s1 ~]# yum install -y ntp ntpdate //安装时间服务以及时间同步工具
[root@s1 ~]# ntpdate ntp1.aliyun.com //通过阿里云的时间
3 Oct 18:44:08 ntpdate[15411]: adjust time server 120.25.115.20 offset 0.012798 sec
[root@s1 ~]# clock -w //保存时间
[root@s1 ~]# vim /etc/ntp.conf //修改时间服务器的配置文件
17 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap //前面有注释,去掉即可
18 server 127.127.1.0 //然后添加一个这个代码
21 #server 0.centos.pool.ntp.org iburst
22 #server 1.centos.pool.ntp.org iburst
23 #server 2.centos.pool.ntp.org iburst
24 #server 3.centos.pool.ntp.org iburst
注释掉以sever 开头的行 然后保存退出即可
[root@s1 ~]# systemctl start ntpd //启动时间服务器
[root@s1 ~]# systemctl enable ntpd
s2 和 s3 节点的操作(操作均一致)
[root@s2 ~]# yum install -y ntpdate
[root@s2 ~]# ntpdate s1 //直接同步s1 节点的时间即可
3 Oct 18:48:06 ntpdate[16903]: adjust time server 192.168.1.10 offset 0.006365 sec
[root@s2 ~]# crontab -e //进入周期计划编辑页面
*/2 * * * * /usr/sbin/ntpdate s1 >> /var/log/ntpdate.log
每隔两分钟自动同步s1 的时间服务器
[root@s2 ~]# systemctl restart crond //重启周期计划
[root@s2 ~]# systemctl enable crond
ceph集群的构建
以上所有操作均在s1 上进行
[root@s1 ~]# mkdir /ceph //创建一个工作目录,所有的操作均在这个目录进行
[root@s1 ~]# cd /ceph/
[root@s1 ceph]# ssh-keygen -t rsa //建立主机信任,这样登录就不需要密码了
[root@s1 ceph]# ssh-copy-id s2 //将生成的秘钥发送给其他两个节点
[root@s1 ceph]# ssh-copy-id s3
[root@s1 ceph]# ssh s2 //登录测试
Last login: Sat Oct 3 18:29:06 2020
[root@s2 ~]#
[root@s1 ceph]# ceph-deploy install s1 s2 s3 //安装ceph 会受网速的影响
如果以上出现出现以 ceph --verison 结尾的错误 我们可以这样解决
在每一个节点上先执行 yum install -y ceph 先来进行安装
不过要确保每一个节点都存在如下的源
ceph.repo
ceph.repo.rpmsave
epel.repo
epel-testing.repo
如何在安装的时候遇到 获取 GPG 密钥失败:[Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
我们可以修改 epel.repo 中 gpgcheck=1 改为gpgcheck=0 即可
然后我们再来执行以下的命令即可:
[root@s1 ceph]# ceph-deploy install s1 s2 s3
[root@s1 ceph]# ceph --version //执行完成以后我们在每一个节点都执行这个命令来查看ceph的版本号
ceph version 13.2.10 (564bdc4ae87418a232fc901524470e1a0f76d641) mimic (stable)
配置MOM (mom是ceph的一款健康检测软件)
[root@s1 ceph]# ceph-deploy new s1 s2 s3 //创建一个新的集群 并把 s1 s2 s3 加入到集群中
[root@s1 ceph]# ll //以上操作执行了以后,在对应的目录下就会有这一些文件
总用量 52
-rw-r--r-- 1 root root 226 10月 5 11:47 ceph.conf
-rw-r--r-- 1 root root 44689 10月 5 11:47 ceph-deploy-ceph.log
-rw------- 1 root root 73 10月 5 11:47 ceph.mon.keyring
接下来进行下发配置文件操作(默认情况下三个节点的/etc/ceph 目录下是没有文件的)
[root@s1 ceph]# ceph-deploy config push s1 s2 s3 //分别向s1 s2 s3 同时下发配置文件
[root@s1 ceph]# cd /etc/ceph/
[root@s1 ceph]# ls //下发以后就会多出这一些文件了
ceph.conf rbdmap tmp9KzVL7
然后我们进行下发认证文件操作
[root@s1 ceph]# ceph-deploy mon create-initial //在下发之前,我们先进行初始化认证文件操作
[root@s1 ceph]# ls //初始化完成以后在工作目录也会多出这一些文件
ceph.bootstrap-mds.keyring ceph.bootstrap-osd.keyring ceph.client.admin.keyring ceph-deploy-ceph.log
ceph.bootstrap-mgr.keyring ceph.bootstrap-rgw.keyring ceph.conf ceph.mon.keyring
[root@s1 ceph]# ceph-deploy admin s1 s2 s3 //然后执行下发认证文件操作
S2 S3 均在执行以下操作
[root@s2 ceph]# ls //下发完成以后的/etc/ceph 目录会多出如下的文件
ceph.client.admin.keyring ceph.conf rbdmap tmpU3a8Ve
[root@s2 ceph]# chmod a+x ceph.client.admin.keyring //然后我们给这个文件进行赋予执行权限
配置OSD(osd是用户可以看得到的文件)
注:我们需要在每一个节点都添加一块新的磁盘
[root@s1 ceph]# fdisk -l //查看我们添加的磁盘
........
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
然后执行创建OSD 操作:
[root@s1 ceph]# ceph-deploy osd create --data /dev/sdb s1
[root@s1 ceph]# ceph-deploy osd create --data /dev/sdb s2
[root@s1 ceph]# ceph-deploy osd create --data /dev/sdb s3
[root@s1 ceph]# ceph -s //然后我们查看集群的状态
cluster:
id: 27b3505c-7523-4458-91d0-7e2733c942a7
health: HEALTH_WARN
no active mgr
显示是no active mgr 接下来我们将节点加入到mgr 里面
[root@s1 ceph]# ceph-deploy mgr create s1 s2 s3
[root@s1 ceph]# ceph -s //再次查看
cluster:
id: 27b3505c-7523-4458-91d0-7e2733c942a7
health: HEALTH_WARN
接下来我们启动dash页面
[root@s1 ceph]# ceph mgr module enable dashboard //生成dash页面 这个主要是在浏览器上展示的
[root@s1 ceph]# ceph dashboard create-self-signed-cert //生成ceph证书
Self-signed certificate created
[root@s1 ceph]# ceph mgr services //查看状态
{
"dashboard": "https://s1:8443/"
}
启动dash页面以后,我们需要创建登录用户以及密码
[root@s1 ceph]# ceph dashboard set-login-credentials admin 123 //创用户名为admin 密码为123
Username and password updated
浏览器登录测试
浏览器输入:IP地址:8443
如果登录进来遇到这个问题
这个是时间同步的问题,解决方法如下:
1.关闭掉s1 节点上的ntpd 服务 ,然后在开启,然后在s2 s3 节点重新 使用 ntpdate s1 来进行同步
2.如果以上不行,我们就重启一下 ceph
[root@s1 ~]# systemctl restart ceph\*.service
[root@s1 ~]# systemctl restart ceph\*.target
3.实在不行我们就把时间服务器卸载了重新安装即可
解决之后是这样子的,就代表成功了
至此,ceph集群的搭建就到此完成