admin 发表于 2025-12-20 22:38:29

怎样安装使用ceph ansible

Prerequisites
Root Access to OpenStack Control Plane
Root access to your cloud's control plane nodes is required.

Path to the Ceph Configuration Files
Ceph Ansible Inventory
/etc/fm-deploy/ceph-inventory.yml
Ceph Ansible Config
/opt/ceph-ansible/group_vars/all.yml
Preparation
To prepare Ceph Ansible:

docker cp fm-deploy:/opt/ceph-ansible /opt/ceph-ansible
chmod 700 /opt/ceph-ansible
cd /opt/ceph-ansible
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install six

Deploy a Ceph Cluster:

ansible-playbook \
    -i /etc/fm-deploy/ceph-inventory.yml \
    --private-key /root/.ssh/fm-deploy \
    /opt/ceph-ansible/site.yml

Attempt to repair a broken Ceph cluster:

ansible-playbook \
    -i /etc/fm-deploy/ceph-inventory.yml \
    --private-key /root/.ssh/fm-deploy \

admin 发表于 2025-12-22 23:44:32

一:Ansible Playbook示例
---
# ansible-playbook -i inventory ceph-deploy.yml

- name: 部署 Ceph 集群基础组件
hosts: mons,mgrs,osds# 目标主机分组
become: yes# 使用 root 权限
vars:
    ceph_cluster_name: my-cluster# 集群名称
    ceph_fsid: "{{ lookup('password', '/dev/null chars=hex,ascii_letters length=32') }}"# 自动生成唯一集群ID
    ceph_mon_group_name: mons# Monitor 主机组名称
    ceph_mgr_group_name: mgrs# Manager 主机组名称
    ceph_public_network: 192.168.1.0/24# 公共网络
    ceph_cluster_network: 10.0.0.0/24# 集群内部网络

tasks:
    - name: 安装 Ceph 基础软件包
      package:
      name:
          - ceph-mon
          - ceph-mgr
          - ceph-osd
      state: present

    - name: 初始化 Monitor 节点
      command: ceph-mon --cluster {{ ceph_cluster_name }} --mkfs -i {{ inventory_hostname_short }}
      when: inventory_hostname in groups

- name: 部署 OSD 节点
hosts: osds
vars:
    osd_devices:# OSD 磁盘配置
      - /dev/sdb
      - /dev/sdc
    osd_journal_size: 5120# 日志分区大小(MB)
tasks:
    - name: 创建 OSD
      command: ceph-volume lvm create --data {{ item }} --journal-size {{ osd_journal_size }}
      loop: "{{ osd_devices }}"

- name: 部署 CephFS
hosts: mdss# MDS 节点组
vars:
    cephfs_name: myfs# 文件系统名称
    cephfs_data_pool: cephfs_data# 数据池名称
    cephfs_metadata_pool: cephfs_meta# 元数据池名称
    cephfs_pg_num: 128# 放置组数量
tasks:
    - name: 创建文件系统
      command: |
      ceph osd pool create {{ cephfs_data_pool }} {{ cephfs_pg_num }}
      ceph osd pool create {{ cephfs_metadata_pool }} {{ cephfs_pg_num }}
      ceph fs new {{ cephfs_name }} {{ cephfs_metadata_pool }} {{ cephfs_data_pool }}

- name: 部署 RGW 对象存储
hosts: rgws
vars:
    rgw_zone: myzone# 存储区域名称
    rgw_zonegroup: myzg# 区域组名称
    rgw_frontend_port: 7480# 服务端口
    rgw_ssl_enabled: false# 是否启用SSL
tasks:
    - name: 创建 RGW 实例
      command: |
      ceph-deploy rgw create {{ inventory_hostname }} \
          --rgw-zone {{ rgw_zone }} \
          --rgw-zonegroup {{ rgw_zonegroup }} \
          --rgw-frontends "client.port={{ rgw_frontend_port }}"

- name: 验证集群状态
hosts: localhost
tasks:
    - name: 检查集群健康状态
      command: ceph -s
      register: ceph_status
      changed_when: false

    - debug:
      msg: "{{ ceph_status.stdout_lines }}"
AI构建项目

二:参数详细说明
主机组定义
mons: Monitor 节点组,负责集群状态维护

mgrs: Manager 节点组,负责指标收集和监控

osds: OSD 节点组,负责数据存储

mdss: MDS 节点组(CephFS 元数据服务)

rgws: RGW 节点组(对象存储网关)

核心参数
#yaml文件

ceph_cluster_name: my-cluster # 集群标识符

ceph_fsid: # 集群唯一ID,建议自动生成

ceph_public_network: # 客户端访问网络

ceph_cluster_network: # 数据同步内部网络

OSD 配置
#yaml

osd_devices: # 磁盘设备列表(根据实际修改)
- /dev/sdb
- /dev/sdc
osd_journal_size: 5120 # 日志分区大小(MB)

CephFS 参数
#yaml文件

cephfs_name: myfs # 文件系统名称

cephfs_data_pool: # 数据存储池

cephfs_metadata_pool: # 元数据存储池

cephfs_pg_num: # 每个池的PG数量(根据集群规模调整)

RGW 参数
#yaml文件

rgw_zone: # 存储区域名称(需全局唯一)

rgw_zonegroup: # 区域组名称(逻辑分组)

rgw_frontend_port: # 服务监听端口

rgw_ssl_enabled: # 是否启用HTTPS

三:补充配置建议
认证配置(建议添加)
#yaml

cephx: true # 启用认证

client_admin_key: "AQD...==" # 管理员密钥(自己定义)

存储池配置
#yaml

default_pool_replica: 3 # 默认副本数

pgp_num: 128 # 放置组组合数

监控集成
#yaml

ceph_dashboard_enabled: true
grafana_integration: true
prometheus_targets: # 监控服务器地址
- 192.168.1.100:9090

硬件优化
#yaml

osd_memory_target: 4294967296    # OSD内存限制(4GB)

filestore_max_sync_interval: 5         # 文件存储同步间隔

四:ansible执行注意事项
准备 inventory 文件:
#ini文件


ceph-mon1 ansible_host=192.168.1.101
ceph-mon2 ansible_host=192.168.1.102


ceph-osd1 ansible_host=192.168.1.201
ceph-osd2 ansible_host=192.168.1.202


ceph-mds1 ansible_host=192.168.1.301


ceph-rgw1 ansible_host=192.168.1.401
推荐使用官方 ceph-ansible 角色:
yaml

roles:
- role: ceph-ansible
    vars:
      ceph_origin: repository
      ceph_repository: community

网络建议:
公共网络和生产网络分离

每个OSD建议10GbE以上带宽

监控节点使用SSD磁盘

验证步骤:

# 检查集群状态
ceph -s

# 测试CephFS挂载
mount -t ceph mon1:6789:/ /mnt -o name=admin,secret=xxx

# 测试RGW访问
s3cmd --no-ssl --host=rgw1:7480 ls
页: [1]
查看完整版本: 怎样安装使用ceph ansible