iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 8
0
DevOps

30天完成本地部署 kubernetes系列 第 8

使用 Ceph 實現高可用的持久化儲存(3):部署高可用 Ceph mon cluster

  • 分享至 

  • xImage
  •  

Ceph 使用 Paxos 演算法決定多個 mons 中,那個作為主要 mon。因此,本次部署將部署 3 個 mon,可允許 1 個 mon 失敗,以此避免單點失敗問題。

部署步驟如下:

  1. 建立 ceph keyring
  2. 建立 ceph.conf
  3. 在各個主機上執行 mon daemon

以部署至 master1, worker1, worker2 主機為例:

#!/bin/bash

DOCKERIMAGE=ceph/daemon:v3.2.1-stable-3.2-luminous-debian-9-x86_64
NETWORK=10.13.13.0/24

MON1=master1
MON1IP=10.13.13.101

MON2=worker1
MON2IP=10.13.13.102

MON3=worker2
MON3IP=10.13.13.103

MONS=${MON1},${MON2},${MON3}
MONSIP=${MON1IP},${MON2IP},${MON3IP}

# Bootstrap Ceph by MON1

ssh ${MON1} "
        docker run -d --net=host \
                --restart=always \
                -v /etc/ceph:/etc/ceph \
                -v /var/log/ceph/:/var/log/ceph/ \
                -v /var/lib/ceph/mon:/var/lib/ceph/mon \
                -v /var/lib/ceph/bootstrap-mds:/var/lib/ceph/bootstrap-mds \
                -v /var/lib/ceph/bootstrap-osd:/var/lib/ceph/bootstrap-osd \
                -v /var/lib/ceph/bootstrap-rbd:/var/lib/ceph/bootstrap-rbd \
                -v /var/lib/ceph/bootstrap-rgw:/var/lib/ceph/bootstrap-rgw \
                -e MON_IP=${MON1IP} \
                -e CEPH_PUBLIC_NETWORK=$NETWORK \
                --name mon \
                ${DOCKERIMAGE} mon
        "

for ROLE in osd mds rbd rgw
do
        while ssh ${MON1} "sudo [ ! -f /var/lib/ceph/bootstrap-${ROLE}/ceph.keyring ]"
        do
                echo Waiting bootstrap-${ROLE}/ceph.keyring...
                sleep 1
        done
done


ssh ${MON1} "
        sudo sed -i -e 's/^mon initial members = .*/mon initial members = ${MONS}/' /etc/ceph/ceph.conf ;
        sudo sed -i -e 's/^mon host = .*/mon host = ${MONSIP}/' /etc/ceph/ceph.conf ;
        "

ssh ${MON1} "
        docker stop mon ; docker rm mon ;
        sudo rm -rf /var/lib/ceph/mon ;
        sudo mkdir -p ~/pack/ceph/etc ~/pack/ceph/var/lib/ceph ;
        sudo cp -rf /etc/ceph ~/pack/ceph/etc/ ;
        sudo cp -rf /var/lib/ceph/bootstrap-mds ~/pack/ceph/var/lib/ceph ;
        sudo cp -rf /var/lib/ceph/bootstrap-osd ~/pack/ceph/var/lib/ceph ;
        sudo cp -rf /var/lib/ceph/bootstrap-rbd ~/pack/ceph/var/lib/ceph ;
        sudo cp -rf /var/lib/ceph/bootstrap-rgw ~/pack/ceph/var/lib/ceph ;
        sudo chown -R 64045:64045 ~/pack/ceph/var/lib/ceph ;
        "

for MON in ${MON2} ${MON3}
do
        ssh ${MON} "sudo mkdir -p ~/pack/ceph"

        ssh ${MON1} "sudo tar -zcpf - -C ~/pack/ceph ." | ssh ${MON} "sudo tar zxpf - -C ~/pack/ceph"

        ssh ${MON} "
                sudo cp -rf ~/pack/ceph/etc/ceph /etc ;
                sudo cp -rf ~/pack/ceph/var/lib/ceph /var/lib ;
                sudo mkdir -p /var/log/ceph ;
                sudo chmod go-rwx /var/log/ceph /var/lib/ceph ;
                sudo chown 64045:64045 /var/log/ceph /var/lib/ceph ;
                sudo rm -rf ~/pack ;
                "
done

ssh ${MON1} "sudo rm -rf ~/pack"

for t in ${MON1},${MON1IP} ${MON2},${MON2IP} ${MON3},${MON3IP}
do
        IFS=","
        set -- $t
        MON=$1
        MONIP=$2

        ssh ${MON} "
                docker run -d --net=host \
                        --restart=always \
                        -v /etc/ceph:/etc/ceph \
                        -v /var/log/ceph/:/var/log/ceph/ \
                        -v /var/lib/ceph/mon:/var/lib/ceph/mon \
                        -v /var/lib/ceph/bootstrap-mds:/var/lib/ceph/bootstrap-mds \
                        -v /var/lib/ceph/bootstrap-osd:/var/lib/ceph/bootstrap-osd \
                        -v /var/lib/ceph/bootstrap-rbd:/var/lib/ceph/bootstrap-rbd \
                        -v /var/lib/ceph/bootstrap-rgw:/var/lib/ceph/bootstrap-rgw \
                        -e MON_IP=${MONIP} \
                        -e CEPH_PUBLIC_NETWORK=$NETWORK \
                        --name mon \
                        ${DOCKERIMAGE} mon
                "
done

ceph.conf 例:

[global]
fsid = 03893329-f6f6-45c7-a1fb-eeeaf8a5c445
mon initial members = master1,worker1,worker2
mon host = 10.13.13.101,10.13.13.102,10.13.13.103
public network = 10.13.13.0/24
cluster network = 10.13.13.0/24
osd journal size = 100
log file = /dev/null

部署結果,共 3 個 mon daemons:

$ ssh master1 docker exec mon ceph -s
  cluster:
    id:     03893329-f6f6-45c7-a1fb-eeeaf8a5c445
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum master1,worker2,worker1
    mgr: no daemons active
    osd: 0 osds: 0 up, 0 in

  data:
    pools:   0 pools, 0 pgs
    objects: 0 objects, 0B
    usage:   0B used, 0B / 0B avail
    pgs:

上一篇
使用 Ceph 實現高可用的持久化儲存(2):Ceph 部署環境及工具介紹
下一篇
使用 Ceph 實現高可用的持久化儲存(4):完成 Ceph/CephFS 部署
系列文
30天完成本地部署 kubernetes30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言