ansible、playbook、华为云、ceph
首先在华为云上购买搭建ceph集群所需云主机:
然后购买ceph所需存储磁盘
将购买的磁盘挂载到用来搭建ceph的云主机上
在跳板机上安装ansible
查看ansible版本,检验ansible是否安装成功
配置主机分组
测试结果
书写playbook文件内容如下:
---
#将yum文件同步到各个节点
- hosts: ceph
remote_user: root
tasks:
- copy:
src: /etc/yum.repos.d/ceph.repo
dest: /etc/yum.repos.d/ceph.repo
- shell: yum clean all
#给ceph-0001主机安装ceph-deploy,创建工作目录,初始化配置文件
- hosts: ceph-
remote_user: root
tasks:
- yum:
name: ceph-deploy
state: installed
- file:
path: /root/ceph-cluster
state: directory
mode: ''
#给所有ceph节点安装ceph相关软件包
- hosts: ceph
remote_user: root
tasks:
- yum:
name: ceph-osd,ceph-mds
state: installed
#给ceph-,ceph-,ceph-0003安装ceph-mon
- hosts: ceph-,ceph-,ceph-
remote_user: root
tasks:
- yum:
name: ceph-mon
state: installed
#初始化mon服务
- hosts: ceph-
tasks:
- shell: 'chdir=/root/ceph-cluster ceph-deploy new ceph-0001 ceph-0002 ceph-0003'
- shell: 'chdir=/root/ceph-cluster ceph-deploy mon create-initial'
#准备磁盘分区,创建journal盘,并永久修改设备权限,使用ceph-deploy工具初始化数据磁盘,初始化OSD集群,部署ceph文件系统
- hosts: ceph
remote_user: root
tasks:
- shell: parted /dev/vdb mklabel gpt
- shell: parted /dev/vdb mkpart primary %
- shell: chown ceph.ceph /dev/vdb1
- copy:
src: /etc/udev/rules.d/-vdb.rules
dest: /etc/udev/rules.d/-vdb.rules
- hosts: ceph-
remote_user: root
tasks:
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0001:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0002:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0003:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0004:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0005:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy disk zap ceph-0006:vdc'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0001:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0002:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0003:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0004:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0005:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy osd create ceph-0006:vdc:/dev/vdb1'
- shell: 'chdir=/root/ceph-cluster ceph-deploy mds create ceph-0006'
- shell: 'chdir=/root/ceph-cluster ceph osd pool create cephfs_data 128'
- shell: 'chdir=/root/ceph-cluster ceph osd pool create cephfs_metadata 128'
- shell: 'chdir=/root/ceph-cluster ceph fs new myfs1 cephfs_metadata cephfs_data'
playbook具体执行过程如下:
前往ceph-0001管理主机上验证:集群已搭建成功