首页 > 其他分享 >自动化部署ceph集群

自动化部署ceph集群

时间:2023-01-12 09:33:33浏览次数:55  
标签:storage01 shell name hostname ceph ansible 集群 自动化

1. 环境准备

1.1 机器准备

主机名 IP
storage01 10.0.0.10
storage02 10.0.0.11
storage03 10.0.0.12
  • 系统Ubuntu22.04

2. 初始化准备

2.1 安装软件

  • 解压离线包(如果没有自己配置源安装即可,实在不会加Q:360120854)
tar xvf ansible.tar.gz -C /opt/
  • 备份源文件
cp /etc/apt/sources.list{,.bak}
  • 配置指定源文件
cat > /etc/apt/sources.list << EOF
deb [trusted=yes] file:// /opt/ansible/debs/
EOF
  • 加载源
apt clean all

apt update
  • 安装软件
apt install -y ansible samba smbclient

2.2 配置hosts解析

vim /etc/hosts
10.0.0.10 storage01
10.0.0.11 storage02
10.0.0.12 storage03

2.3 配置免密

# 创建密钥
ssh-keygen

# 配置免密
ssh-copy-id -i /root/.ssh/id_rsa.pub  storage01

ssh-copy-id -i /root/.ssh/id_rsa.pub  storage02

ssh-copy-id -i /root/.ssh/id_rsa.pub  storage03

2.2 配置ansible

mkdir /etc/ansible

vi /etc/ansible/hosts
[hosts]
storage01 ansible_host=10.0.0.10
storage02 ansible_host=10.0.0.11
storage03 ansible_host=10.0.0.12

# 测试可通信
ansible hosts -m ping

2.3 创建ansible初始文件

mkdir ceph

cd ceph

ansible-galaxy init ceph_ansible

2.4 当前主机做时间服务端

vim /etc/chrony/chrony.conf
server ntp6.aliyun.com iburst maxsources 2
allow all
local stratum 10
  • 重启生效
systemctl restart chronyd

3. 编写ansible剧本

  • 剧本文件
vim /root/ceph/ceph_ansible/tasks/main.yml
---
# tasks file for ceph_ansible
- name: cp hosts
  copy: src=hosts dest=/etc/

- name: update hostname storage01
  shell: hostnamectl set-hostname storage01
  when: ansible_hostname=="storage01"

- name: update hostname storage02
  shell: hostnamectl set-hostname storage02
  when: ansible_hostname=="storage02"

- name: update hostname storage03
  shell: hostnamectl set-hostname storage03
  when: ansible_hostname=="storage03"

- name: cp source.list
  copy: src=sources.list dest=/etc/apt/

- name: cp xyyhpkg
  copy: src=ceph_quincy.tar.gz dest=/opt/

- name: tar xf xyyhpkg
  shell: tar xf /opt/ceph_quincy.tar.gz -C /opt; apt clean all; apt update

- name: apt chrony
  shell: apt install -y chrony

- name: cp chrony storage02
  copy: src=chrony.conf dest=/etc/chrony/
  when: ansible_hostname=="storage02"

- name: cp chrony storage03
  copy: src=chrony.conf dest=/etc/chrony/
  when: ansible_hostname=="storage03"

- name: timezone update
  shell: timedatectl set-ntp true; timedatectl set-timezone Asia/Shanghai

- name: restart chrony
  shell: systemctl restart chronyd

- name: apt docker
  shell: apt install -y docker-ce

- name: apt cephadm
  shell: apt install -y cephadm
  when: ansible_hostname=="storage01"

- name: cp cephimage
  copy: src=cephadm_images_v17.tar dest=/root/

- name: load image
  shell: docker load -i /root/cephadm_images_v17.tar

- name: cp registry image
  copy: src=registry.tar dest=/root/
  when: ansible_hostname=="storage01"

- name: load registry
  shell: docker load  -i /root/registry.tar
  when: ansible_hostname=="storage01"

- name: start registry
  shell: docker run -d --name registry -p 5000:5000 --restart always 3a0f7b0a13ef
  when: ansible_hostname=="storage01"

- name: cp daemon.json
  copy: src=daemon.json dest=/etc/docker/

- name: restart docker
  shell: systemctl daemon-reload; systemctl restart docker

- name: cp xyyhimage
  copy: src=xyyhceph.tar dest=/root/

- name: ceph rmi images
  shell: docker rmi 0912465dcea5

- name: load xyyhimage update cephimages
  shell: docker load -i /root/xyyhceph.tar

- name: tag images
  shell: docker tag 335a74237f18 10.0.0.10:5000/ceph:v17
  when: ansible_hostname=="storage01"

- name: push image
  shell: docker push 10.0.0.10:5000/ceph:v17
  when: ansible_hostname=="storage01"

- name: create directory
  file:
    path: /etc/ceph
    state: directory

- name: init ceph-cluster
  shell: cephadm --image 10.0.0.10:5000/ceph:v17 bootstrap --mon-ip 10.0.0.10 --initial-dashboard-user admin --initial-dashboard-password 000000 --skip-pull
  when: ansible_hostname=="storage01"

- name: install ceph-comon
  shell: apt install -y ceph-common

- name: disable https dashboard
  shell: ceph config set mgr mgr/dashboard/ssl false
  when: ansible_hostname=="storage01"

- name: update dashboard port
  shell: ceph config set mgr mgr/dashboard/server_port 5050
  when: ansible_hostname=="storage01"

- name: restart dashboard module
  shell: ceph mgr module disable dashboard; ceph mgr module enable dashboard
  when: ansible_hostname=="storage01"

- name: copy-key
  shell: ssh-copy-id -f -i /etc/ceph/ceph.pub storage02; ssh-copy-id -f -i /etc/ceph/ceph.pub storage03
  when: ansible_hostname=="storage01"

- name: add cluster host
  shell: ceph orch host add storage02; ceph orch host add storage03
  when: ansible_hostname=="storage01"

- name: add device osd
  shell: ceph orch apply osd --all-available-devices
  when: ansible_hostname=="storage01"
  • 启动文件
vim /root/ceph/ceph_ansible.yaml
---

- hosts: hosts
  remote_user: root
  roles:
    - ceph_ansible

4. 执行剧本

4.1 提前准备剧本文件

cd ceph

cp /etc/hosts .

cp /etc/apt/sources.list .

mv ceph_quincy.tar.gz /root/ceph_ansible/

cp /etc/chrony/chrony.conf .
vim chrony.conf
pool storage01 iburst maxsources 2

cp cephadm_images_v17.tar .

cp registry.tar .

cat >> /etc/docker/daemon.json << EOF
{
"insecure-registries":["10.0.0.10:5000"]
}
EOF

cp xyyhceph.tar .
  • 验证
    • 检查是否有配置错误,如无语法错误,那么准备需要的相关文件
# 必须要在ansible上级目录下执行
ansible-playbook --syntax-check ceph_ansible.yaml
  • 执行
ansible-playbook mall.yaml

标签:storage01,shell,name,hostname,ceph,ansible,集群,自动化
From: https://www.cnblogs.com/wsxier/p/17045529.html

相关文章