一文带你看懂使用ansible的palybook的方式实现 搭建ceph分布式集群搭建,包含部署 CephFS(文件存储),部署 RGW(对象存储)

Ansible 搭建教程和模块简介与示例

以下是使用 Ansible Playbook 搭建 Ceph 集群并部署 CephFS 和 RGW 的详细示例及参数解释:

一: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[ceph_mon_group_name]

- 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 }}"

二:参数详细说明

  1. 主机组定义

    • mons: Monitor 节点组,负责集群状态维护

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

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

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

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

  2. 核心参数

    #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文件

[mons]
ceph-mon1 ansible_host=192.168.1.101
ceph-mon2 ansible_host=192.168.1.102

[osds]
ceph-osd1 ansible_host=192.168.1.201
ceph-osd2 ansible_host=192.168.1.202

[mdss]
ceph-mds1 ansible_host=192.168.1.301

[rgws]
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

注意: 建议根据实际硬件环境调整 PG 数量、副本策略和网络配置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值