目录
[二. 基于 ceph-deploy 部署 Ceph 集群](#二. 基于 ceph-deploy 部署 Ceph 集群)
10节点为admin,20-40为node,50为client:
[配置 hosts 解析:](#配置 hosts 解析:)
[在 admin 管理节点配置 ssh 免密登录所有节点:](#在 admin 管理节点配置 ssh 免密登录所有节点:)
[所有节点配置 Ceph yum源:](#所有节点配置 Ceph yum源:)
[所有节点都创建一个 Ceph 工作目录,后续的工作都在该目录下进行:](#所有节点都创建一个 Ceph 工作目录,后续的工作都在该目录下进行:)
[安装 ceph-deploy 部署工具:](#安装 ceph-deploy 部署工具:)
[管理节点为其它节点安装 Ceph 软件包:](#管理节点为其它节点安装 Ceph 软件包:)
[在管理节点初始化 mon 节点:](#在管理节点初始化 mon 节点:)
[配置初始化 mon 节点,并向所有节点同步配置:](#配置初始化 mon 节点,并向所有节点同步配置:)
[部署能够管理 Ceph 集群的节点:](#部署能够管理 Ceph 集群的节点:)
[部署 osd 存储节点:](#部署 osd 存储节点:)
[部署 mgr 节点:](#部署 mgr 节点:)
[重启 dashboard:](#重启 dashboard:)
一.ceph分布式存储
ceph:存储机制会把数据分散存储到多个节点上,具有高扩展性、高性能、高可用性等优点。
Ceph架构(自上往下)
客户端(主机/虚拟机/容器/应用程序APP):在Ceph中进行数据读写的终端。
LibRADOS对象访问接口:提供访问存储接口给客户端使用。Ceph默认提供三个接口:RBD块存储接口、RGW对象存储接口、CephFS文件存储接口。还支持用户使用java、python、C、C++等编程语言二次开发自定义访问接口。
RADOS基础存储系统(统一存储池):提供存储能力的。Ceph中一切都是以对象(object)形式存储的。RADOS就是负责存储这些对象的,并保证数据的一致性和可靠性。
OSD的存储引擎:
FileStore:是L版本(12.x)以前版本的唯一可选的OSD存储引擎,将数据对象存储为文件系统的文件,性能上有所不足
BlueStore:是L版本(12.x)开始的默认OSD存储引擎,将数据对象直接存储在块设备上,具有更好的数据读写性能和可靠性
Ceph的存储过程:
1)文件默认会按照4M大小进行分片成一个或多个数据对象(object)
2)每个数据对象都有一个oid(由文件ID(ino)和分片编号(ono)组成),通过对oid使用HASH算法得到一个16进制的特征码,再除以Pool中的PG总数取余,获取到数据对象的pgid(整体由poolid+pgid组成)
3)通过对pgid使用CRUSH算法得到PG对应的OSD的ID,如果是多副本,则是主从OSD的ID(注:PG与OSD的对应关系是在创建存储池Pool的时候就确定好的)
4)将数据对象存储到对应的OSD里
二. 基于 ceph-deploy 部署 Ceph 集群
准备五台服务器,192.168.233.{10..50}:
20-40节点上添加3块硬盘,一个网卡:




10节点为admin,20-40为node,50为client:





配置 hosts 解析:





安装常用软件和依赖包:
bash
yum -y install epel-release
yum -y install yum-plugin-priorities yum-utils ntpdate python-setuptools python-pip gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel zip unzip ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssh openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced python wget lsof iptraf strace lrzsz kernel-devel kernel-headers pam-devel tcl tk cmake ncurses-devel bison setuptool popt-devel net-snmp screen perl-devel pcre-devel net-snmp screen tcpdump rsync sysstat man iptables sudo libconfig git bind-utils tmux elinks numactl iftop bwm-ng net-tools expect snappy leveldb gdisk python-argparse gperftools-libs conntrack ipset jq libseccomp socat chrony sshpass


在 admin 管理节点配置 ssh 免密登录所有节点:

bash
sshpass -p '123' ssh-copy-id -o StrictHostKeyChecking=no root@admin
sshpass -p '123' ssh-copy-id -o StrictHostKeyChecking=no root@node01
sshpass -p '123' ssh-copy-id -o StrictHostKeyChecking=no root@node02
sshpass -p '123' ssh-copy-id -o StrictHostKeyChecking=no root@node03




10节点配置时间同步:
修改配置文件:


开启chrony:


开启 NTP:
bash
timedatectl set-ntp true

设置时区:
bash
timedatectl set-timezone Asia/Shanghai

强制同步下系统时钟:
bash
chronyc -a makestep

查看时间同步状态:
bash
timedatectl status

查看 ntp 源服务器信息:

将当前的UTC时间写入硬件时钟:

所有节点重启依赖于系统时间的服务:





关闭无关服务:




所有node节点修改网卡配置:






重启网卡:



所有节点配置 Ceph yum源:
bash
wget https://download.ceph.com/rpm-nautilus/el7/noarch/ceph-release-1-1.el7.noarch.rpm --no-check-certificate










将包移动到/opt下:





安装ceph:










所有节点都创建一个 Ceph 工作目录,后续的工作都在该目录下进行:


安装 ceph-deploy 部署工具:

查看版本,2.0.1 默认部署的是 mimic 版的 Ceph,若想安装其他版本的 Ceph,可以用 --release 手动指定版本:

管理节点为其它节点安装 Ceph 软件包:
bash
yum install -y ceph-mon ceph-radosgw ceph-mds ceph-mgr ceph-osd ceph-common ceph

节点下载:
修改ceph的源:


改为阿里云下载:
bash
sed -i 's#download.ceph.com#mirrors.aliyun.com/ceph#' ceph.repo



其他节点下载 Ceph 包:
生成初始配置:
在管理节点运行下述命令,告诉 ceph-deploy 哪些是 mon 监控节点:
bash
ceph-deploy new --public-network 192.168.233.0/24 --cluster-network 192.168.100.0/24 node01 node02 node03
.命令执行成功后会在 /etc/ceph 下生成配置文件:
ceph.conf : ceph的配置文件
ceph-deploy-ceph.log : monitor的日志
ceph.mon.keyring : monitor的密钥环文件

在管理节点初始化 mon 节点:
bash
ceph-deploy mon create node01 node02 node03

节点上查看下mon状态:

配置初始化 mon 节点,并向所有节点同步配置:
bash
ceph-deploy --overwrite-conf mon create-initial

命令执行成功后会在 /etc/ceph 下生成配置文件:

ceph.bootstrap-mds.keyring : 引导启动 mds 的密钥文件
ceph.bootstrap-mgr.keyring : 引导启动 mgr 的密钥文件
ceph.bootstrap-osd.keyring : 引导启动 osd 的密钥文件
ceph.bootstrap-rgw.keyring : 引导启动 rgw 的密钥文件
ceph.client.admin.keyring : ceph客户端和管理端通信的认证密钥,拥有ceph集群的所有权限
在节点上查看下配置文件:


主节点上看下ceph信息:

从节点看:

查看 mon 集群选举的情况:
bash
ceph quorum_status --format json-pretty | grep leader

部署能够管理 Ceph 集群的节点:
bash
ceph-deploy --overwrite-conf config push node01 node02 node03

本质就是把 ceph.client.admin.keyring 集群认证文件拷贝到各个节点:
bash
ceph-deploy admin node01 node02 node03

在 从 节点上查看:


部署 osd 存储节点:
查看下从节点的磁盘情况:



添加节点:
bash
ceph-deploy --overwrite-conf osd create node01 --data /dev/sdb
ceph-deploy --overwrite-conf osd create node02 --data /dev/sdb
ceph-deploy --overwrite-conf osd create node03 --data /dev/sdb


看下从节点的磁盘情况:

在添加其他两个节点:


看下状态:



扩容 osd 节点:
bash
ceph-deploy --overwrite-conf osd create node01 --data /dev/sdc
ceph-deploy --overwrite-conf osd create node02 --data /dev/sdc
ceph-deploy --overwrite-conf osd create node03 --data /dev/sdc
ceph-deploy --overwrite-conf osd create node01 --data /dev/sdd
ceph-deploy --overwrite-conf osd create node02 --data /dev/sdd
ceph-deploy --overwrite-conf osd create node03 --data /dev/sdd

看下状态:

看下从节点:

将剩下磁盘继续添加后,查看状态:



主节点看下状态:

部署 mgr 节点:


解决 HEALTH_WARN 问题:mons are allowing insecure global_id reclaim问题:
禁用不安全模式:
bash
ceph config set mon auth_allow_insecure_global_id_reclaim false


从节点下载mgr:
开启 dashboard 模块:
bash
ceph mgr module enable dashboard --force

禁用 dashboard 的 ssl 功能:
bash
ceph config set mgr mgr/dashboard/ssl false

配置 dashboard 监听的地址和端口:
bash
ceph config set mgr mgr/dashboard/server_addr 192.168.233.20
ceph config set mgr mgr/dashboard/server_port 8000

重启 dashboard:
bash
ceph mgr module disable dashboard
ceph mgr module enable dashboard --force

确认访问 dashboard 的 url:

设置 dashboard 账户以及密码:

bash
ceph dashboard set-login-credentials admin -i dashboard_passwd.txt

访问页面:


