Ceph 集群部署 (二)
推荐配置
CPU
16C 或 32C 双路
内存
64G以上
磁盘
NVME 企业级SSD
推荐
intel D7 P5520 数据中心企业级固态硬盘U.2 nvme协议服务器工作站SSD P5520 3.84TB
intel 英特尔 S4510/S4520 数据中心企业级固态硬盘SATA3 S4520 3.84T
mon 服务器
16C 32G 200G
Mgr 服务器
8C 16G 200G
Ceph-deploy
4c 8G 120G
一、部署方式
ceph-ansible:https://github.com/ceph/ceph-ansible #python ceph-salt:https://github.com/ceph/ceph-salt #python ceph-container:https://github.com/ceph/ceph-container #shell ceph-chef:https://github.com/ceph/ceph-chef #Ruby
ceph-deploy:https://github.com/ceph/ceph-deploy #python ceph-deploy是一个 ceph 官方维护的基于 ceph-deploy 命令行部署 ceph 集群的工具,基于 ssh 执行可以 sudo 权限的 shell 命令以及一些 python 脚本 实现 ceph 集群的部署和管理维护。
Ceph-deploy 只用于部署和管理 ceph 集群,客户端需要访问 ceph,需要部署客户端工具。
二、服务器准备
硬件推荐:https://docs.ceph.com/en/latest/start/hardware-recommendations/#
2.1 OSD服务器
三台服务器作为 ceph 集群 OSD 存储服务器,每台服务器支持两个网络,public 网络针对客户端访问,cluster 网络用于集群管理及数据同步,每台三块或以上的磁盘。
10.1.0.30/192.168.10.240
10.0.0.31/192.168.10.241
10.0.0.32/192.168.10.242
三台存储服务器磁盘划分:
/dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf #200G
2.2 Mon 监视服务器
三台服务器作为 ceph 集群 Mon 监视服务器,每台服务器可以和 ceph 集群的 cluster 网络通信。
10.1.0.33/192.168.10.243
10.0.0.34/192.168.10.244
10.0.0.35/192.168.10.245
2.3 ceph-mgr 管理服务器
两个 ceph-mgr 管理服务器,可以和 ceph 集群 的 cluster 网络通信。
10.1.0.30/192.168.10.240
10.0.0.31/192.168.10.241
2.4 Ceph-deploy 部署服务器
一个服务器用于部署 ceph 集群即安装 Ceph-deploy,也可以和 ceph-mgr 等复用。
10.1.0.31/192.168.10.248
三、 服务器环境准备
3.1 配置集群网络
#更改网卡名称为eth*:
sudo vim /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="maybe-ubiquity"
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
~$ sudo update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-55-generic
Found initrd image: /boot/initrd.img-4.15.0-55-generic
done
#配置cluster和public网络
vim /etc/apt/sources.list
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses:
- 10.1.0.39/24
gateway4: 10.1.0.254
nameservers:
addresses:
- 223.5.5.5
eth1:
dhcp4: no
dhcp6: no
addresses: [192.168.10.239/24]
version: 2
#生效
netplan apply
#验证两块网卡IP地址
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether fe:fc:fe:cf:34:9d brd ff:ff:ff:ff:ff:ff
inet 10.1.0.39/24 brd 10.1.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::fcfc:feff:fecf:349d/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether fe:fc:fe:79:6f:6e brd ff:ff:ff:ff:ff:ff
inet 192.168.10.239/24 brd 192.168.10.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::fcfc:feff:fe79:6f6e/64 scope link
valid_lft forever preferred_lft forever
3.2 配置主机名解析
vim /etc/hosts
10.1.0.39 ceph-node1.xx.local ceph-node1
10.1.0.40 ceph-node2.xx.local ceph-node2
10.1.0.41 ceph-node3.xx.local ceph-node3
10.1.0.39 ceph-mon1.xx.local ceph-mon1
10.1.0.40 ceph-mon2.xx.local ceph-mon2
10.1.0.41 ceph-mon3.xx.local ceph-mon3
10.1.0.40 ceph-mgr1.xx.local ceph-mgr1
10.1.0.41 ceph-mgr2.xx.local ceph-mgr2
10.1.0.39 ceph-deploy.xx.local ceph-deploy
3.3 配置apt源
https://download.ceph.com/ #Ceph官方源
https://mirrors.aliyun.com/ceph/ #阿里云镜像仓库
http://mirrors.163.com/ceph/ #网易镜像仓库
https://mirrors.tuna.tsinghua.edu.cn/ceph/ #清华大学镜像源
所有节点添加ceph 源
wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add -
echo deb https://download.ceph.com/debian-pacific/ $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/ceph.list
sudo apt update
3.4 时间同步
# 设置时区
timedatectl set-timezone Asia/Shanghai
#安装chrony
#三节点安装
apt install chrony -y
##服务端配置
vim /etc/chrony/chrony.conf
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
# 因为想修改本地时间,不去和其他服务器同步,将下面这四个pool注释掉
pool ntp.ubuntu.com iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2
# 添加自己作为服务器
#server 192.168.1.1 iburst
# 为了方便客户端连接权限设置为允许所有
allow all
# 当无法和其他同步时,使用本地的时间去给客户端同步
#注释:值10可以被其他值取代(1~15),stratum 1表示计算机具有直接连接的真实时间的参考时间源,例如gps,原子钟都和真实时间很接近欸, #stratum 2表示计算机有一个stratum 1的计算机作为同步时间源,stratum 3表示该计算机有一个stratum 10的计算机作为同步时间源。 #选择stratum 10.这个值是比较大的,表示距离有真实时间的服务器比较远,它的时间不太可靠,因此,local命令选取stratum 10可以 #防止机器本身的时间与真实时间混淆,可以保证该机器不会将本身的时间授给那些可以连接同步到真实时间的ntp服务器的ntp客户端】
local stratum 10
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
# Log files location.
logdir /var/log/chrony
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3
#客户端
# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
pool 10.1.0.39 iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
# Log files location.
logdir /var/log/chrony
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3
#查看 ntp_servers 状态
chronyc sourcestats -v
#强制同步下系统时钟
chronyc -a makestep
#查看 ntp_servers 是否在线
chronyc activity -v
200 OK
3.5 创建普通用户
推荐使用指定的普 通用户部署和运行 ceph 集群,普通用户只要能以非交互方式执行 sudo 命令执行一些特权命令即可,新版的 ceph-deploy 可以指定包含 root 的在内只要可以执行 sudo 命令的用户,不过仍然推荐使用普通用户,比如 ceph、cephuser、cephadmin 这样的用户去管理 ceph 集群。
在包含 ceph-deploy 节点的存储节点、mon 节点和 mgr 节点等创建 ceph 用户。
#创建用户
groupadd -r -g 20235 xceo && useradd -r -m -s /bin/bash -u 20235 -g 20235 xceo && echo xceo:ceamg.com | chpasswd
~ #:id xceo
uid=20235(xceo) gid=20235(xceo) groups=20235(xceo)
#允许ceph 用户以sudo执行特殊权限
echo "ceph ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers
3.6 配置免密登录
root@ceph-node1:~ su - xceo
ceph@ceph-node1:~$
ceph@ceph-node1:~$ ssh-keygen
ssh-copy-id ceph@10.1.0.40
ssh-copy-id ceph@10.1.0.41
ssh ceph-mon1.xx.local
ssh ceph-mon2.xx.local
ssh ceph-mon3.xx.local
ssh ceph-mgr1.xx.local
ssh ceph-mgr2.xx.local
ssh ceph-node1.xx.local
ssh ceph-node2.xx.local
ssh ceph-node3.xx.local
ssh ceph-deploy.xx.local
3.7 其他基本优化
~$ vi /etc/sysctl.conf
添加:
fs.file-max = 10000000000
fs.nr_open = 1000000000
~$ vi /etc/security/limits.conf
#root账户的资源软限制和硬限制
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000
#其他账户的资源软限制和硬限制
* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000
# 将这两个修改过的文件拷贝到其他节点
~$ scp /etc/sysctl.conf ceph-node2:/etc/
~$ scp /etc/sysctl.conf ceph-node3:/etc/
~$ scp /etc/security/limits.conf ceph-node2:/etc/security/
~$ scp /etc/security/limits.conf ceph-node3:/etc/security/
# 在三台虚拟机上分别执行以下命令,让内核参数生效,并重启
~$ sysctl -p
~$ reboot
四、部署 RADOS 集群
4.1 安装Ceph-Deploy 部署工具
#查看可用版本
root@ceph-node1[15:45:17]~ #:apt-cache madison ceph-deploy
ceph-deploy | 2.0.1-0ubuntu1.1 | https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe amd64 Packages
ceph-deploy | 2.0.1-0ubuntu1 | https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 Packages
root@ceph-node1[15:45:17]~ #:apt install ceph-deploy -y
4.2 安装 python 2.7
root@ceph-mon1[09:49:37]~ apt install python2.7
#所有机器设置软链接
ln -sv /usr/bin/python2.7 /usr/bin/python2
#安装好后 执行python2测试 如果可以执行,说明安装好了
root@ceph-mon1[09:49:37]~ #:python2
Python 2.7.18 (default, Jul 1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
4.3 初始化Ceph-Deploy
#切换到xceo账户创建集群目录
~$su - xceo
~$ pwd
/home/xceo
~$ mkdir ceph-cluster
~$ cd ceph-cluster/
~/ceph-cluster$
#查看的结果如下:
xceo@ceph-mon1:~/ceph-cluster$ ceph-deploy --help
usage: ceph-deploy [-h] [-v | -q] [--version] [--username USERNAME] [--overwrite-conf] [--ceph-conf CEPH_CONF] COMMAND ...
Easy Ceph deployment
-^-
/ \
|O o| ceph-deploy v2.0.1
).-.(
'/|||\`
| '|` |
'|`
Full documentation can be found at: http://ceph.com/ceph-deploy/docs
ceph-deploy 使用帮助
ceph-deploy --help
new:开始部署一个新的 ceph 存储集群,并生成 CLUSTER.conf 集群配置文件和 keyring 认证文件。
install: 在远程主机上安装 ceph 相关的软件包, 可以通过--release 指定安装的版本。
rgw:管理 RGW 守护程序(RADOSGW,对象存储网关)。
mgr:管理 MGR 守护程序(ceph-mgr,Ceph Manager DaemonCeph 管理器守护程序)。
mds:管理 MDS 守护程序(Ceph Metadata Server,ceph 源数据服务器)。
mon:管理 MON 守护程序(ceph-mon,ceph 监视器)。
gatherkeys:从指定获 取提供新节点的验证 keys,这些 keys 会在添加新的 MON/OSD/MDS 加入的时候使用。
disk:管理远程主机磁盘。
osd:在远程主机准备数据磁盘,即将指定远程主机的指定磁盘添加到 ceph 集群作为 osd 使用。
repo:远程主机仓库管理。
admin:推送 ceph 集群配置文件和 client.admin 认证文件到远程主机。
config:将 ceph.conf 配置文件推送到远程主机或从远程主机拷贝。
uninstall:从远端主机删除安装包。
purgedata:从/var/lib/ceph 删除 ceph 数据,会删除/etc/ceph 下的内容。
purge: 删除远端主机的安装包和所有数据。
forgetkeys:从本地主机删除所有的验证 keyring, 包括 client.admin, monitor, bootstrap 等认证文件。
pkg:管理远端主机的安装包。
calamari:安装并配置一个 calamari web 节点,calamari 是一个 web 监控平台。
4.4 生成mon配置文件
在管理节点初始化mon节点
xceo@ceph-node1:~/ceph-cluster$ ceph-deploy new --cluster-network 192.168.10.0/24 --public-network 10.1.0.0/24 ceph-mon1.xx.local
[ceph_deploy.conf][DEBUG ] found configuration file at: /home/xceo/.cephdeploy.conf
[ceph_deploy.cli][INFO ] Invoked (2.0.1): /usr/bin/ceph-deploy new --cluster-network 192.168.10.0/24 --public-network 10.1.0.0/24 ceph-mon1.xx.local
[ceph_deploy.cli][INFO ] ceph-deploy options:
[ceph_deploy.cli][INFO ] verbose : False
[ceph_deploy.cli][INFO ] quiet : False
[ceph_deploy.cli][INFO ] username : None
[ceph_deploy.cli][INFO ] overwrite_conf : False
[ceph_deploy.cli][INFO ] ceph_conf : None
[ceph_deploy.cli][INFO ] cluster : ceph
[ceph_deploy.cli][INFO ] mon : ['ceph-mon1.xx.local']
[ceph_deploy.cli][INFO ] ssh_copykey : True
[ceph_deploy.cli][INFO ] fsid : None
[ceph_deploy.cli][INFO ] cluster_network : 192.168.10.0/24
[ceph_deploy.cli][INFO ] public_network : 10.1.0.0/24
[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf object at 0x7fa0a0be30a0>
[ceph_deploy.cli][INFO ] default_release : False
[ceph_deploy.cli][INFO ] func : <function new at 0x7fa0a0bdaf70>
[ceph_deploy.new][DEBUG ] Creating new cluster named ceph
[ceph_deploy.new][INFO ] making sure passwordless SSH succeeds
[ceph-mon1.xx.local][DEBUG ] connected to host: ceph-node1
[ceph-mon1.xx.local][INFO ] Running command: ssh -CT -o BatchMode=yes ceph-mon1.xx.local
[ceph-mon1.xx.local][DEBUG ] connection detected need for sudo
[ceph-mon1.xx.local][DEBUG ] connected to host: ceph-mon1.xx.local
[ceph-mon1.xx.local][INFO ] Running command: sudo /bin/ip link show
[ceph-mon1.xx.local][INFO ] Running command: sudo /bin/ip addr show
[ceph-mon1.xx.local][DEBUG ] IP addresses found: ['10.1.0.39', '192.168.10.239']
[ceph_deploy.new][DEBUG ] Resolving host ceph-mon1.xx.local
[ceph_deploy.new][DEBUG ] Monitor ceph-mon1 at 10.1.0.39
[ceph_deploy.new][DEBUG ] Monitor initial members are ['ceph-mon1']
[ceph_deploy.new][DEBUG ] Monitor addrs are ['10.1.0.39']
[ceph_deploy.new][DEBUG ] Creating a random mon key...
[ceph_deploy.new][DEBUG ] Writing monitor keyring to ceph.mon.keyring...
[ceph_deploy.new][DEBUG ] Writing initial config to ceph.conf...
,是否生成配置文件
xceo@ceph-node1:~/ceph-cluster$ ll
total 24
drwxrwxr-x 2 xceo xceo 4096 May 26 16:29 ./
drwxr-xr-x 5 xceo xceo 4096 May 26 16:15 ../
-rw-rw-r-- 1 xceo xceo 259 May 26 16:29 ceph.conf
-rw-rw-r-- 1 xceo xceo 7307 May 26 16:29 ceph-deploy-ceph.log
-rw------- 1 xceo xceo 73 May 26 16:29 ceph.mon.keyring
xceo@ceph-node1:~/ceph-cluster$ cat ceph.conf
[global]
fsid = 31fdd971-2963-459b-9d6f-588f1811993f
public_network = 10.1.0.0/24
cluster_network = 192.168.10.0/24
mon_initial_members = ceph-mon1
mon_host = 10.1.0.39
auth_cluster_required = cephx
auth_service_required = cephx
auth_client_required = cephx
在安装过程中会报如下错误:
[ceph_deploy][ERROR ] RuntimeError: AttributeError: module 'platform' has no attribute 'linux_distribution'
这是由于python3.7后不再支持platform.linux_distribution
修改方法:
修改/usr/lib/python3/dist-packages/ceph_deploy/hosts/remotes.py
文件为如下所示
def platform_information(_linux_distribution=None):
""" detect platform information from remote host """
"""
linux_distribution = _linux_distribution or platform.linux_distribution
distro, release, codename = linux_distribution()
"""
distro = release = codename = None
try:
linux_distribution = _linux_distribution or platform.linux_distribution
distro, release, codename = linux_distribution()
except AttributeError:
pass
验证初始化完成之后,会得到三个文件
如下:
xceo@ceph-node1:~/ceph-cluster$ ls
ceph.conf ceph-deploy-ceph.log ceph.mon.keyring
-------------------------------------------------
ceph.conf # 配置文件
ceph-deploy-ceph.log #部署的日志
ceph.mon.keyring #mon.keyring