任务目标

  1. 完成ceph集群部署

任务平台

  1. 物理设备—
  2. 操作系统:openEuler 22.03 LTS SP2

部署指南

任务一:配置准备

  1. 重命名hostname
1
2
3
4
5
6
7
8
# 将10.10.3.117的主机名改为future-ceph-node0
hostnamectl set-hostname future-ceph-node0 && bash
# 将10.10.3.118的主机名改为future-ceph-node1
hostnamectl set-hostname future-ceph-node1 && bash
# 将10.10.3.119的主机名改为future-ceph-node2
hostnamectl set-hostname future-ceph-node2 && bash
# 将10.10.3.120的主机名改为future-ceph-node3
hostnamectl set-hostname future-ceph-node3 && bash
  1. 安装前的配置修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --state

# selinux永久关闭
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
cat /etc/selinux/config


# 添加hosts
cat >> /etc/hosts << EOF
10.10.3.117 future-ceph-node0
10.10.3.118 future-ceph-node1
10.10.3.119 future-ceph-node2
10.10.3.120 future-ceph-node3
EOF
#查看
cat /etc/hosts


#同步时间
yum install ntp -y
systemctl start ntpd
systemctl enable ntpd
yum install chrony -y
systemctl start chronyd
systemctl enable chronyd
#修改配置,添加内容
echo "
server 10.10.3.70 iburst
allow 10.10.3.0/24
" >> /etc/chrony.conf
timedatectl set-ntp true
systemctl restart chronyd
timedatectl status
date

添加节点SSH互相通信
ssh-keygen -t rsa
ssh-copy-id 10.10.3.118
ssh-copy-id 10.10.3.119
ssh-copy-id 10.10.3.120

任务二:部署Ceph作为分布式存储

配置下载源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
echo "[ceph]
name=ceph
baseurl=http://mirrors.aliyun.com/ceph/rpm-mimic/el7/x86_64/
gpgcheck=0
priority=1

[ceph-noarch]
name=cephnoarch
baseurl=https://mirrors.aliyun.com/ceph/rpm-mimic/el7/noarch/
gpgcheck=0
priority=1

[ceph-source]
name=Ceph source packages
baseurl=http://mirrors.aliyun.com/ceph/rpm-mimic/el7/SRPMS/
enabled=0
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
" >/etc/yum.repos.d/ceph.repo

下载python2

  1. 安装zlib库,不然安装pip时会报错(还要重新编译python)
1
yum -y install zlib*
  1. 安装 GCC 包,如果没有安装 GCC,请使用以下命令进行安装
1
yum -y install gcc openssl-devel bzip2-devel
  1. 下载Python-2.7.18
1
2
3
4
cd /usr/src
yum -y install wget
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar xzf Python-2.7.18.tgz
  1. 在编译之前还需要在安装源文件中修改Modules/Setup.dist文件,将注释去掉
1
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
  1. 编译Python-2.7.18(make altinstall用于防止替换默认的 python 二进制文件 /usr/bin/python)
1
2
3
4
cd /usr/src/Python-2.7.18
./configure --enable-optimizations
yum install -y make
make altinstall

不要覆盖或链接原始的 Python 二进制文件,这可能会损坏系统

  1. 设置环境变量
1
2
3
4
vi /etc/profile
export PYTHON_HOME=/usr/local/
PATH=$PATH:$PYTHON_HOME/bin
source /etc/profile
  1. 下载安装pip的脚本
1
curl "https://bootstrap.pypa.io/pip/2.7/get-pip.py" -o "get-pip.py"
  1. 运行下载安装脚本
1
python2.7 get-pip.py 

下载ceph

1
2
3
4
5
6
7
#future-ceph-node0下载
pip2 install ceph-deploy
yum install -y ceph ceph-radosgw
#其他节点下载
yum install -y ceph ceph-radosgw
#检查安装包是否完整
rpm -qa |egrep -i "ceph|rados|rbd"

部署ceph集群

管理节点
部署Monitor
  1. 创建配置文件目录,并创建配置文件
1
2
mkdir /etc/ceph/
touch /etc/ceph/ceph.conf
  1. 为集群生成一个FSDI:
1
2
uuidgen
38ac0084-40b7-4c93-b561-a16d6a6478c5
  1. 集群创建一个钥匙串,为Monitor 服务创建一个密钥:
1
ceph-authtool --create-keyring /tmp/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
  1. 创建一个管理员钥匙串,生成一个client.admin用户,并将此用户添加到钥匙串中:
1
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 *'
  1. 创建bootstrap-osd钥匙串,将client.bootstrap-osd 用户添加到此钥匙串中:
1
ceph-authtool --create-keyring /var/lib/ceph/bootstrap-osd/ceph.keyring --gen-key -n client.bootstrap-osd --cap mon 'profile bootstrap-osd'
  1. 将生成的key加入ceph.mon.keyring.
1
2
3
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
  1. 使用主机名和IP地址以及FSID生成monitor map:
1
monmaptool --create --add future-ceph-node0 10.10.3.117 --fsid 79fd2206-39ca-4ec4-9cd2-96e065c6361e /tmp/monmap
  1. 创建mon的目录,使用 集群名称-主机名的形式:
1
mkdir  /var/lib/ceph/mon/ceph-future-ceph-node0
  1. 填入第一个mon守护进程的信息:
1
ceph-mon --mkfs -i future-ceph-node0 --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring
  1. 配置/etc/ceph/ceph.conf文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cat /etc/ceph/ceph.conf
################################################
[global]
fsid = 79fd2206-39ca-4ec4-9cd2-96e065c6361e # 生成的FSID
mon initial members =future-ceph-node0
mon host = 10.10.3.117
public network = 10.10.3.0/24
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
osd journal size = 1024
osd pool default size = 3
osd pool default min size = 2
osd pool default pg num = 333
osd pool default pgp num = 333
osd crush chooseleaf type = 1

################################################
  1. 由于我们使用使用root操作的,需要设置权限为ceph(也可以修改systemd的启动文件,将ceph用户改为root),并启动Monitor
1
2
3
chown  -R ceph:ceph /var/lib/ceph
systemctl start ceph-mon@future-ceph-node0.service
systemctl enable ceph-mon@future-ceph-node0.service
  1. 确认服务已经正常启动:
1
2
3
ceph -s
yum install -y net-tools
netstat -lntp|grep ceph-mon
部署Manager

当我们配置好ceph-mon服务之后,就需要配置ceph-mgr服务。

  1. 生成一个认证密钥(ceph-mgr为自定义的名称):
1
2
3
4
5
6
7
8
9
#10.10.3.117
ceph auth get-or-create mgr.ceph-mgr mon 'allow profile mgr' osd 'allow *' mds 'allow *'
[mgr.ceph-mgr]
key = AQBMNTZl5adxEhAAk6Jk/CKNWUyNb2DoKXUPvQ==

#10.10.3.118
ceph auth get-or-create mgr.ceph-mgr1 mon 'allow profile mgr' osd 'allow *' mds 'allow *'
[mgr.ceph-mgr1]
key = AQDbRTZlgjXWBBAAGew4Xta+t9vgIWPCWC8EVg==
  1. 创建存放此密钥的文件的目录
1
2
3
4
5
6
7
8
9
10
11
12
13
#10.10.3.117
sudo -u ceph mkdir /var/lib/ceph/mgr/ceph-ceph-mgr
#将产生的密钥文件存入此目录下,并命名为keyring
vi /var/lib/ceph/mgr/ceph-ceph-mgr/keyring
[mgr.ceph-mgr]
key = AQBMNTZl5adxEhAAk6Jk/CKNWUyNb2DoKXUPvQ==

#10.10.3.118
sudo -u ceph mkdir /var/lib/ceph/mgr/ceph-ceph-mgr1
#将产生的密钥文件存入此目录下,并命名为keyring
vi /var/lib/ceph/mgr/ceph-ceph-mgr1/keyring
[mgr.ceph-mgr1]
key = AQDbRTZlgjXWBBAAGew4Xta+t9vgIWPCWC8EVg==
  1. 启动ceph-mgr服务
1
2
3
4
5
6
7
8
ceph-mgr -i ceph-mgr
ceph-mgr -i ceph-mgr1
systemctl enable ceph-mgr@future-ceph-node0
systemctl enable ceph-mgr@future-ceph-node1
#检查服务是否启动,查看ceph状态
ceph -s
#查看当前mgr中可用的模块
ceph mgr module ls
创建OSD
1
2
3
4
5
ceph-volume lvm create --data /dev/sdb
#查看当前的lvm逻辑卷
ceph-volume lvm list
#查看ceph状态
ceph -s
安装配置Ceph-dashboard
  1. 开启dashboard功能
1
ceph mgr module enable dashboard
  1. 创建证书
1
ceph dashboard create-self-signed-cert
  1. 配置web登录的用户名和密码
1
2
3
#创建/etc/ceph/dashboard.key,并将密码写入
echo "密码" >/etc/ceph/dashboard.key
ceph dashboard ac-user-create k8s administrator -i /etc/ceph/dashboard.key
  1. 修改dashboard默认端口(可选)

配置端口,默认端口是8443,修改为18443,修改后需重启mgr,修改端口才生效。

1
2
ceph config set mgr mgr/dashboard/server_port 18443
systemctl restart ceph-mgr.target
  1. 查看发布服务地址并登录
1
ceph mgr services

{

​ “dashboard”: “https://future-ceph-node0:8443/

}

node节点
扩展Monitor
  1. 修改master节点上的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
vi /etc/ceph/ceph.conf
[global]
fsid = 79fd2206-39ca-4ec4-9cd2-96e065c6361e # 生成的FSID
mon initial members =future-ceph-node0,future-ceph-node1,future-ceph-node2,future-ceph-node3 # 主机名
mon host = 10.10.3.117,10.10.3.118,10.10.3.119,10.10.3.120 # 对应的IP
public network = 10.10.3.0/24
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
osd journal size = 1024
osd pool default size = 3
osd pool default min size = 2
osd pool default pg num = 333
osd pool default pgp num = 333
osd crush chooseleaf type = 1
[mon]
mon allow pool delete = true

[mds.future-ceph-node0]
host = future-ceph-node0
  1. 将配置和密钥文件分发到其它的节点上(master节点)
1
2
3
4
5
6
7
8
9
#生成公钥,复制到node节点主机上
ssh-keygen -t rsa
ssh-copy-id 10.10.3.118
ssh-copy-id 10.10.3.119
ssh-copy-id 10.10.3.120
#复制认证密钥
scp /etc/ceph/* 10.10.3.118:/etc/ceph/
scp /etc/ceph/* 10.10.3.119:/etc/ceph/
scp /etc/ceph/* 10.10.3.120:/etc/ceph/
  1. 在node节点创建ceph相关目录,并添加权限:
1
2
3
4
5
6
mkdir -p  /var/lib/ceph/{bootstrap-mds,bootstrap-mgr,bootstrap-osd,bootstrap-rbd,bootstrap-rgw,mds,mgr,mon,osd}
chown -R ceph:ceph /var/lib/ceph

sudo -u ceph mkdir /var/lib/ceph/mon/ceph-future-ceph-node1
sudo -u ceph mkdir /var/lib/ceph/mon/ceph-future-ceph-node2
sudo -u ceph mkdir /var/lib/ceph/mon/ceph-future-ceph-node3
  1. 修改node节点的配置文件,以node1为例(其他节点相似)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[global]
fsid = 79fd2206-39ca-4ec4-9cd2-96e065c6361e # 生成的FSID
mon initial members =future-ceph-node0,future-ceph-node1,future-ceph-node2,future-ceph-node3 # 主机名
mon host = 10.10.3.117,10.10.3.118,10.10.3.119,10.10.3.120 # 对应的IP
public network = 10.10.3.0/24
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
osd journal size = 1024
osd pool default size = 3
osd pool default min size = 2
osd pool default pg num = 333
osd pool default pgp num = 333
osd crush chooseleaf type = 1
[mon]
mon allow pool delete = true

[mon.future-ceph-node1]
mon_addr = 10.10.3.118:6789
host = future-ceph-node1
  1. 获取集群中的密钥和map,以node1为例(其他节点相似)
1
2
ceph auth get mon. -o /tmp/monkeyring
ceph mon getmap -o /tmp/monmap
  1. 使用已有的密钥和map添加一个新的Monitor,指定主机名,以node1为例(其他节点相似)
1
sudo -u ceph ceph-mon --mkfs -i future-ceph-node1 --monmap /tmp/monmap --keyring /tmp/monkeyring
  1. 启动服务,以node1为例(其他节点相似)
1
2
3
4
5
systemctl start ceph-mon@future-ceph-node1
systemctl enable ceph-mon@future-ceph-node1
#查看mon状态
ceph -s
ceph mon stat
添加OSD

从已经存在的osd的master节点上拷贝初始化的密钥文件

1
2
3
scp -p  /var/lib/ceph/bootstrap-osd/ceph.keyring  10.10.3.118:/var/lib/ceph/bootstrap-osd/
scp -p /var/lib/ceph/bootstrap-osd/ceph.keyring 10.10.3.119:/var/lib/ceph/bootstrap-osd/
scp -p /var/lib/ceph/bootstrap-osd/ceph.keyring 10.10.3.120:/var/lib/ceph/bootstrap-osd/

在node节点添加osd

1
2
3
4
5
6
ceph-volume lvm create --data /dev/sdb

systemctl restart ceph-osd@future-ceph-node1
systemctl enable ceph-osd@future-ceph-node1
#查看状态
ceph -s

添加Mds

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#创建目录
sudo -u ceph mkdir -p /var/lib/ceph/mds/ceph-future-ceph-node0
#创建密钥
ceph-authtool --create-keyring /var/lib/ceph/mds/ceph-future-ceph-node0/keyring --gen-key -n mds.future-ceph-node0
#导入密钥,并设置caps
ceph auth add mds.future-ceph-node0 osd "allow rwx" mds "allow" mon "allow profile mds" -i /var/lib/ceph/mds/ceph-future-ceph-node0/keyring
#手动启动服务
ceph-mds --cluster ceph -i future-ceph-node0 -m future-ceph-node0:6789
chown -R ceph:ceph /var/lib/ceph/mds/
systemctl start ceph-mds@future-ceph-node0
systemctl enable ceph-mds@future-ceph-node0
#检查服务是否启动
ps -ef|grep ceph-mds
#检查ceph 集群状态
ceph -s

创建CephFS

创建pools

1
2
3
4
5
6
7
8
9
#存储数据
ceph osd pool create cephfs_data 64
#存储元数据
ceph osd pool create cephfs_metadata 64
#启用cephfs文件系统
ceph fs new cephfs cephfs_metadata cephfs_data
#查看文件系统状态
ceph fs ls
ceph mds stat
  1. 挂载cephfs

内核驱动挂载

1
2
3
4
5
6
7
8
9
10
11
#安装依赖
yum install -y ceph-common
#创建挂载点
mkdir /data
#获取存储密钥(管理节点)
cat /etc/ceph/ceph.client.admin.keyring
#将117中的/data 挂载到其他主机的/data
mount -t ceph 10.10.3.117:6789:/ /data -o name=admin,secret=AQBLfS9l612IGhAAOF1iJqT6+rHJPCxqQegqCA==

#卸载
umount /data

用户控件挂载

1
2
3
4
5
6
7
8
yum install ceph-fuse -y
#挂载到其他主机
ceph-fuse -m 10.10.3.117:6789 /data
#查看挂载配置
df -h |grep code

#卸载
fusermount -u /mnt/cephfs

创建rbd池

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#创建rbd池
ceph osd pool create rbd-k8s 64 64
#启用
ceph osd pool application enable rbd-k8s rbd
#初始化
rbd pool init rbd-k8s
#查看
ceph osd lspools
#查看映像
rbd ls rbd-k8s
#查看映像信息
rbd info --pool rbd-k8s --image mars-c09bb992-963e-43dd-8e5c-e3a1d723b1c8
#映射镜像
rbd map --pool rbd-k8s --image mars-c09bb992-963e-43dd-8e5c-e3a1d723b1c8
#格式化
mkfs.ext4 /dev/rbd0
#挂载到本地
mount /dev/rbd0 /data/code
#查看
lsblk
#取消挂载
umount /dev/rbd0
#取消映射
rbd unmap /dev/rbd0