Ansible部署RHCS存储集群详解


一 前期准备

1.1 前置条件

  • 至少有三个不同的主机运行monitor (MON)节点;
  • 至少三个直接存储(非外部SAN硬件)的OSD节点主;
  • 至少两个不同的manager (MGR)节点;
  • 如果使用CephFS,则至少有两个完全相同配置的MDS节点;
  • 如果使用Ceph对象网关,则至少有两个不同的RADOSGW节点。
  • 一个部署节点,可以使用ceph-ansible包中的Ansible剧本来部署和配置集群。
提示:Red Hat Ceph存储还支持在Red Hat OpenStack平台计算节点上部署OSDs、MONs、RGWs,但不支持部署mon和osd。 红帽Ceph存储,默认配置将所有流量放在一个网络上。生产环境中建议公共通信和集群通信配置单独的网络。公共网络用于客户端通信和与mon的通信。集群网络用于OSD心跳、复制、回填和恢复流量。

1.2 准备工作

  • 具备相同操作系统的集群节点,建议RHEL7;
  • 配置软件仓库(CentOS epel源、Ubuntu apt源、RedHat使用subscription-manager命令注册系统);
  • 所有节点配置网络及NTP时间同步;
  • 关闭selinux与防火墙,或放通所有相关流量和端口;
  • 在部署节点安装ansbile;
  • 添加hosts,并确保能正确解析到所有主机;
  • 配置部署节点使用Ansible任务的用户到其他所有节点可以ssh免密登录;
  • 验证部署节点能够在集群节点上能正常运行ansible任务。

1.3 其他注意事项

  1. OSD磁盘不建议使用RAID,Ceph使用复制或纠删码来保护数据
  2. 在生产环境部署Ceph集群,为便于管理,OSD主机应尽量使用统一的硬件。尽可能配置数量、大小和名称都相同的磁盘,有助于确保性能一致,并且简化故障排除;
  3. 需要确认每个OSD主机提供的OSD的数量。密度较小的存储集群意味着osd守护进程分布到更多的主机上,分发工作负载。密度较高的存储意味着重平衡和数据恢复需要更高的流量

附一:组件端口说明

Monitor 6789/TCP:Communication within the Ceph cluster Manager 7000/TCP:Communication with the Ceph Manager dashboard 8003/TCP:Communication with the Ceph Manager RESTful API via HTTPS 9283/TCP:Communication with the Ceph Manager Prometheus plug-in OSD 6800-7300/TCP:Each OSD uses three ports in this range: one for communicating with clients and monitors over the public network; one for sending data to other OSDs over a cluster network,or over the public network if the former does not exist; and another for exchanging heartbeat packets over a cluster network or over the public network if the former does not exists. RADOS Gateway 7480/TCP:RADOS Gateway uses port 7480/TCP,but you can change it, for example to port 80/TCP,or to port 443/TCP if using the SSL/TLS service.

二 部署相关知识点

2.1 Ansible介绍

略,具体Ansible操作见本博客Ansible文章。

2.2 Ansible部署Ceph相关yml

/usr/share/ceph-ansible/group_vars/all.yml:所有节点相关yml配置; /usr/share/ceph-ansible/group_vars/osds.yml:所有OSD节点的yml配置; /usr/share/ceph-ansible/group_vars/client.yml:客户端节点的yml配置。 /usr/share/ceph-ansible:运行Ansible部署的主目录。

2.3 yml主要相关参数

  • all.yml参数
变量 含义
fetch_directory ~/ceph-ansible-keys 用于将身份验证密钥复制到集群节点的临时目录的位置。
ceph_origin repository Ceph来源,repository表示使用包存储库
ceph_repository rhcs 用于安装Red Hat的存储库Ceph存储。rhcs使用官方红帽Ceph存储包。
ceph_repository_type cdn or iso rhcs的安装源,CDN或本地ISO映像。
ceph_rhcs_iso_path path to iso 如果使用iso存储库类型,则指向Red Hat Ceph存储iso的路径。
ceph_rhcs_version 3 Red Hat Ceph安装的版本。
monitor_interface network interface Monitor用于侦听的网络接口。
public_network address and netmask 集群的公共网络的子网,如192.168.122.0/24。
cluster_network address and netmask 集群专用网络的子网。默认设置为public_network的值。
journal_size size in MB 分配给OSD日志的大小。应该是预期的两倍。在大多数情况下不应小于5120 MB。
提示:可以在group_vars/all.yml中将common_single_host_mode这个特殊参数设置为true。用于部署一个单节点、集所有功能于一身的Ceph集群作为测试学习使用。
  • osds.ym
变量 含义
osd_scenario collocated or non-collocated OSD日志部署类型。
devices 用于OSDs的设备的名称列表。 用于并行OSD数据和日志分区或非并行OSD数据分区的设备。
dedicated_devices 用于非并列OSD期刊的设备名称列表。 OSD日志设备。
并置方案:假定所有OSD主机具有相同的硬件并使用相同的设备名称。 group_vars/osds.yml配置示例: osd_scenario: "collocated" devices: - /dev/sdb - /dev/sdc - /dev/sdd 非并置方案:将不同的存储设备用于OSD数据和OSD日志。 group_vars/osds.yml配置示例: osd_scenario: "non-collocated" devices: - /dev/sdb - /dev/sdc dedicated_devices: - /dev/sdd - /dev/sde

2.4 客户端相关命令

命令 含义
ceph -s 查看集群状态。
ceph -w 动态观察集群更改。
ceph df 查看集群剩余空间状态。
ceph osd df 查看OSD使用情况。
ceph auth get-or-create 创建用户。
aeph auth list 查看用户列表。
ceph auth caps 查看用户权限。
ceph auth del 删除用户。

2.5 对象object相关命令

命令 含义
rados -p pool_name ls 查看一个pool中的object。
rados -p pool_name put object_name file_path 上传一个文件作为对象。
rados -p pool_name get object_name file_path 以文件的形式检索object。
rados -p pool_name stat object_name 显示object的统计数据。
rados -p pool_name rm object_name 删除一个object。

三 正式部署

节点 类型 IP 备注
servera 部署节点 172.25.250.10  
serverc mons mgrs osds 172.25.250.12  
serverd mons mgrs osds 172.25.250.13  
servere mons mgrs osds 172.25.250.14  

3.1 部署节点配置主机名

[root@servera ~]# vi /etc/hosts
172.25.250.10 servera
172.25.250.12 serverc
172.25.250.13 serverd
172.25.250.14 servere
提示:主机名应该能正确解析主机名,若管理节点同时也是一个Ceph节点,也要确认能正确解析自己的主机名和IP地址。本实验环境此3.1步骤可省略。

3.2 创建相关用户

[root@servera ~]# useradd student
[root@servera ~]# echo student | passwd --stdin student  #创建非root的管理用户
[root@servera ~]# for i in {a..e}; do echo "====server${i}====";ssh root@server${i} 'useradd -d /home/student -m student; echo "student" | passwd --stdin student'; done                #所有OSD server节点创建student用户
[root@servera ~]# for i in {a..e}; do echo "====server${i}====";ssh root@server${i} 'useradd -d /home/ceph -m ceph; echo "redhat" | passwd --stdin ceph'; done
[root@servera ~]# for i in {a..e}; do echo "====server${i}====";ssh root@server${i} 'echo "student ALL = (root) NOPASSWD:ALL" > /etc/sudoers'; done
[root@servera ~]# for i in {a..e}; do echo "====server${i}====";ssh root@server${i} 'chmod 0440 /etc/sudoers'; done

3.3 配置部署节点免密钥

[root@servera ~]# su - student
[student@servera ~]$ ssh-keygen -f ~/.ssh/id_rsa -N ''
[student@servera ~]$ for i in {a..e}; do echo "====server${i}====";ssh-copy-id student@server$i;ssh-copy-id ceph@server$i; done
 

3.4 配置Ansible Inventory

[student@servera ~]$ sudo vi /usr/share/ceph-ansible/ansible.cfg
log_path = /tmp/ansible.log		        #修改日志路径为student用户可写入的/tmp路径
deprecation_warnings = False		#禁用在ansible-playbook输出结果相关必须要警告
提示:Ansible默认使用/etc/ansible/hosts作为Inventory文件,也可使用-f参数手动指定其他文件。

[student@servera ~]$ sudo vi /etc/ansible/hosts
[mons]
server[c:e]

[mgrs]
server[c:e]
[student@servera ~]$ ansible mons -m ping  #测试mons组节点通信
[student@servera ~]$ ansible mgrs -m ping  #测试mgrs组节点通信
[student@servera ~]$ ansible mons -m command -a id #通过命令测试mons组节点
[student@servera ~]$ ansible mgrs -m command -a id #通过命令测试mgrs组节点

提示:ceph ansible playbook为每种Ceph节点类型使用一个主机组:monitors节点使用mons, osds节点使用osds,managers节点使用mgrs,MDSs使用mdss, Ceph客户端使用clients, RADOS网关节点使用raws, iSCSI网关使用iscsi-gws,启用RBD mirroring使用rd-mirror。 因此需要需要根据Ceph主机的角色将它们在对应的Inventory文件中配置为对应的组。

3.5 创建site.yml

[student@servera ~]$ cd /usr/share/ceph-ansible/
[student@servera ceph-ansible]$ sudo cp site.yml.sample site.yml
[student@servera ceph-ansible]$ sudo vi site.yml
#……
- hosts: osds
  gather_facts: false
  become: True
  serial: 1                  #在osd(80行左右)添加此行

提示:添加serial: 1添,会减慢了OSD的部署,但是使我们更有可能预测哪个OSD编号被分配给哪个OSD主机,以便将来的实验室练习。

3.6 创建all.yml

[student@servera ~]$ cd /usr/share/ceph-ansible/group_vars/
[student@servera group_vars]$ sudo cp all.yml.sample all.yml
[student@servera group_vars]$ sudo vi all.yml
---
dummy:
ntp_service_enabled: false   #本实验采用chrony进行时钟同步
ceph_origin: repository
ceph_repository: rhcs
ceph_rhcs_version: "3"
ceph_repository_type: cdn
rbd_cache: "true"    #开启RBD回写缓存
rbd_cache_writethrough_until_flush: "false" #在切换回写之前,不从写透开始。
rbd_client_directories: false  #不要创建客户机目录(它们应该已经存在)。
monitor_interface: eth0
journal_size: 1024    #本环境存储设备很小,OSD日志比通常建议的要小
public_network: 172.25.250.0/24
cluster_network: "{{ public_network }}"
ceph_conf_overrides:
  global:
    mon_osd_allow_primary_affinity: 1
    mon_clock_drift_allowed: 0.5  #允许MON时钟间隔最多0.5秒
    osd_pool_default_size: 2
    osd_pool_default_min_size: 1  #降低存储池复制大小的默认设置
    mon_pg_warn_min_per_osd: 0  #见提示一
    mon_pg_warn_max_per_osd: 0  #见提示二
    mon_pg_warn_max_object_skew: 0  #见提示三
  client:
    rbd_default_features: 1   #仅为以后的练习启用一组特定的客户机功能

提示一:根据每个OSD的pg数量关闭集群健康警告。通常,第一个变量被设置为30,如果OSD中的每个“in”平均少于30个pg,集群就会发出警告。 提示二:此变量默认值为300,如果OSD中的每个“in”平均超过300个pg,集群就会发出警告,在本实验的小集群中可能没有很多pg,因此采用禁用。 提示三:根据某个池中对象的数量大于集群中一组池中对象的平均数量,关闭集群健康警告。同样,我们有一个非常小的集群,这避免了通常指示我们需要调优集群的额外警告。

3.7 正式部署Ceph集群

[student@servera ~]$ cd /usr/share/ceph-ansible/
[student@servera ceph-ansible]$ ansible-playbook site.yml
001 提示:若部署成功,则对于每个MON节点,前面的命令输出应该显示failed=0。在playbook执行过程中,可能会有许多非致命的警告,它们不会被当做“失败”任务,可以忽略。

3.8 确认验证Ceph集群

[student@servera ~]$ ssh ceph@serverc ceph -s
002
[student@servera ~]$ ssh ceph@serverc cat /etc/ceph/ceph.conf
003
[student@servera ~]$ ssh ceph@serverc ps aux | grep ceph-mon
004

3.9 创建osds.yml

[student@servera ~]$ cd /usr/share/ceph-ansible/group_vars/
[student@servera group_vars]$ sudo cp osds.yml.sample osds.yml
[student@servera group_vars]$ sudo vi osds.yml
---
dummy:
osd_scenario: "collocated"   #OSD使用并列的OSD形式
devices:
  - /dev/vdb    #使用/dev/vdb作为后端存储设备

3.10 配置Ansible Inventory

[student@servera ~]$ sudo vi /etc/ansible/hosts
[mons]
server[c:e]

[mgrs]
server[c:e]

[osds]
server[c:e]     #追加osds组

3.11 正式部署OSD节点

[student@servera ~]$ cd /usr/share/ceph-ansible/
[student@servera ceph-ansible]$ ansible-playbook site.yml
005 提示:若部署成功,则对于每个OSD节点,前面的命令输出应该显示failed=0。在playbook执行过程中,可能会有许多非致命的警告,它们不会被当做“失败”任务,可以忽略。

3.12 确认验证OSD节点

[student@servera ~]$ ssh ceph@serverc ceph -s
006
[student@servera ~]$ ssh ceph@serverc ceph -w		#使用此命令监视集群事件
提示:ceph -w命令将继续显示集群的运行状况和当前事件。要终止该命令,可按ctrl+c。

3.13 测试及验证

[ceph@serverc ~]$ sudo systemctl stop ceph-mon.target	#停止serverc的mon进程
[ceph@serverc ~]$ ceph -s				        #观察Ceph状态
007
[ceph@serverc ~]$ sudo systemctl start ceph-mon.target	#重启开启mon进程
[ceph@serverc ~]$ sudo systemctl stop ceph-osd.target	#停止serverc的osd进程
[ceph@serverc ~]$ ceph -s				        #观察Ceph状态
008
[ceph@serverc ~]$ ceph osd tree				#查看osd情况
009
[ceph@serverc ~]$ sudo systemctl start ceph-osd.target	#重启开启osd进程
[ceph@serverc ~]$ sudo systemctl stop ceph-osd@0	        #停止serverc的osd id为0的进程
[ceph@serverc ~]$ ceph osd tree				#查看osd情况
010
[ceph@serverc ~]$ sudo systemctl start ceph-osd@0	#重启开启osd 0进程
[ceph@serverc ~]$ ceph -s				#观察Ceph状态
011
[ceph@serverc ~]$ ceph -v			#查看Ceph版本

3.14 创建client.yml

[student@servera ~]$ cd /usr/share/ceph-ansible/group_vars/
[student@servera group_vars]$ sudo cp clients.yml.sample clients.yml
[student@servera group_vars]$ sudo vi clients.yml
---
dummy:
copy_admin_key: true

3.15 配置Ansible Inventory

[student@servera ~]$ sudo vi /etc/ansible/hosts
[mons]
server[c:e]

[mgrs]
server[c:e]

[osds]
server[c:e]

[clients]
servera     #追加client客户端

3.16 正式部署client节点

[student@servera ~]$ cd /usr/share/ceph-ansible/
[student@servera ceph-ansible]$ ansible-playbook site.yml
012 提示:若部署成功,则对于每个OSD节点,前面的命令输出应该显示failed=0。在playbook执行过程中,可能会有许多非致命的警告,它们不会被当做“失败”任务,可以忽略。

3.17 确认验证

[kiosk@foundation0 ~]$ ssh ceph@servera			#使用ceph用户登录servera
[ceph@servera ~]$ ceph -s					#查看Ceph集群
013

四 扩容Ceph集群

4.1 扩容前置条件

  • 在不中断服务的前提下,扩展ceph集群存储容量
  • 可通过ceph-ansible以两种方式扩展集群中的存储:
    • 可以添加额外OSD主机到集群(scale-out)
    • 可以添加额外存储设备到现有的OSD主机(scale-up)
  • 开始部署额外的OSD前,需确保集群处于HEALTH_OK状态
  • 相关主机解析已正常添加指hosts

4.2 创建相关用户

[root@serverf ~]# useradd student
[root@serverf ~]# echo student | passwd --stdin student          #创建非root的管理用户
[root@serverf ~]# useradd -d /home/student -m student; echo "student" | passwd --stdin student'                                                #所有OSD server节点创建student用户
[root@serverf ~]# useradd -d /home/ceph -m ceph; echo "redhat" | passwd --stdin ceph'
[root@serverf ~]# echo "student ALL = (root) NOPASSWD:ALL" > /etc/sudoers'
[root@serverf ~]# chmod 0440 /etc/sudoers

4.3 配置部署节点免密钥

[root@servera ~]# su - student
[student@servera ~]$ ssh-copy-id student@serverf;ssh-copy-id ceph@serverf

4.4 扩容额外的OSD主机

[student@servera ~]$ sudo vi /etc/ansible/hosts  #配置Ansible Inventory
[student@servera ~]$ sudo vi /etc/ansible/hosts
[mons]
server[c:e]

[mgrs]
server[c:e]

[osds]
server[c:e]
serverf       #追加serverf

[clients]
servera

4.5 添加额外OSD存储设备

devices:
  - /dev/vdb
  - /dev/vdc
  - /dev/vdd						#追加存储设备

4.6 正式部署OSD节点

[student@servera ~]$ cd /usr/share/ceph-ansible/
[student@servera ceph-ansible]$ ansible-playbook site.yml
014 提示:若部署成功,则对于每个OSD节点,前面的命令输出应该显示failed=0。在playbook执行过程中,可能会有许多非致命的警告,它们不会被当做“失败”任务,可以忽略。

4.7 确认验证

[ceph@servera ~]$ ceph -s
015
 [ceph@servera ~]$ ceph osd tree
017
[ceph@servera ~]$ ceph osd df
017

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2019-03/157530.htm

相关内容