Skip to content

Instantly share code, notes, and snippets.

@tafaust
Last active February 15, 2025 18:59
Show Gist options
  • Select an option

  • Save tafaust/05d68f268da8b94bca52b1c0d55bb1b5 to your computer and use it in GitHub Desktop.

Select an option

Save tafaust/05d68f268da8b94bca52b1c0d55bb1b5 to your computer and use it in GitHub Desktop.

Revisions

  1. tafaust revised this gist Feb 15, 2025. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,35 @@ recover-cluster:
    echo "βœ… No failed OSDs detected."; \
    fi

    ## Recover a failed Ceph daemon
    recover-daemon:
    @echo "πŸ”§ Checking for failed Ceph daemons..."
    @FAILED_DAEMONS=$$(ceph health detail | grep 'CEPHADM_FAILED_DAEMON' | grep -oP 'daemon \S+ on \S+' | awk '{print $$2}'); \
    if [ -n "$$FAILED_DAEMONS" ]; then \
    for daemon in $$FAILED_DAEMONS; do \
    echo "πŸ”„ Attempting to recover $$daemon..."; \
    sudo ceph orch restart $$daemon || sudo ceph orch redeploy $$daemon; \
    echo "βœ… Recovery attempted for $$daemon."; \
    done; \
    else \
    echo "βœ… No failed daemons detected."; \
    fi

    ## Recover Ceph Dashboard (Restart MGR and Re-enable Dashboard)
    recover-dashboard:
    @echo "πŸ” Checking Ceph Manager and Dashboard..."
    @MGR_STATUS=$$(ceph mgr dump | grep "active_name"); \
    if [ -z "$$MGR_STATUS" ]; then \
    echo "⚠️ No active Ceph Manager detected! Restarting..."; \
    sudo ceph orch restart mgr; \
    fi
    @echo "πŸ”„ Restarting Ceph Dashboard..."
    sudo ceph mgr module disable dashboard || true
    sudo ceph mgr module enable dashboard
    @echo "βœ… Ceph Dashboard restarted successfully!"
    @echo "πŸ“Œ You can access it at:"
    @ceph mgr services | grep dashboard

    ## Enable Monitoring (Prometheus & Grafana)
    monitor-cluster:
    @echo "πŸ“Š Setting up monitoring..."
  2. tafaust revised this gist Feb 15, 2025. 1 changed file with 72 additions and 43 deletions.
    115 changes: 72 additions & 43 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,27 @@
    # --- Configuration ---
    MON_IP ?= 192.168.1.10 # Primary monitor node IP
    MON_IP ?= 192.168.0.2 # Primary monitor node IP
    POOL_NAME ?= $(shell sudo ceph osd pool ls | grep "cephfs.cephfs.data" || echo "default_pool")
    POOL_SIZE ?= 3
    OSD_DEVICES ?= /dev/sdb # Modify as per your system
    FS_NAME ?= cephfs
    CEPH_IMAGE ?= quay.io/ceph/ceph:v17
    CEPH_IMAGE ?= quay.io/ceph/ceph:v19.2.1

    # Cluster Nodes
    MON_NODES = mon1 mon2 mon3
    OSD_NODES = osd1 osd2 osd3
    MGR_NODES = mgr1
    MDS_NODES = mds1
    MGR_NODES = mgr1 mgr2
    MDS_NODES = mds1 mds2
    RGW_NODES = rgw1

    # SSH Credentials
    SSH_USER ?= ceph-admin

    # --- High-Level Targets ---

    .PHONY: setup-cluster expand-cluster recover-cluster monitor-cluster upgrade-cluster status clean glossary ceph-versions
    .PHONY: setup-cluster expand-cluster recover-cluster monitor-cluster upgrade-cluster status clean list-pools mount-cephfs

    ## Full Cluster Setup (One Command)
    setup-cluster: install bootstrap add-mon add-osd add-mgr add-mds create-pool enable-dashboard status
    setup-cluster: install bootstrap add-mon add-osd add-mgr add-mds add-rgw create-pool enable-dashboard status
    @echo "βœ… Ceph Cluster Setup Completed!"

    ## Expand the Cluster with New Storage Nodes
    @@ -68,43 +69,71 @@ clean:
    sudo cephadm rm-cluster --force --zap-osds
    @echo "βœ… Ceph Cluster Removed!"

    ## Display a Glossary of Ceph Terms
    glossary:
    @echo "πŸ“– Ceph Glossary:"
    @echo "-----------------------------------"
    @echo "πŸ”Ή MON (Monitor) - Tracks cluster state and quorum."
    @echo "πŸ”Ή OSD (Object Storage Daemon) - Stores and replicates data."
    @echo "πŸ”Ή MGR (Manager) - Provides monitoring and management tools."
    @echo "πŸ”Ή MDS (Metadata Server) - Supports CephFS (file storage)."
    @echo "πŸ”Ή RBD (RADOS Block Device) - Ceph's block storage solution."
    @echo "πŸ”Ή RGW (RADOS Gateway) - S3-compatible object storage."
    @echo "πŸ”Ή Erasure Coding - Data redundancy alternative to replication."
    @echo "πŸ”Ή Placement Group (PG) - Logical grouping of OSDs for data distribution."
    @echo "πŸ”Ή Quorum - Minimum required MONs to maintain cluster integrity."
    @echo "πŸ”Ή BlueStore - Default storage backend for Ceph OSDs."
    @echo "πŸ”Ή Ceph Dashboard - Web UI for monitoring and management."
    @echo "-----------------------------------"
    # --- Core Tasks ---

    ## Display Ceph Versions and End-of-Life Status
    ceph-versions:
    @echo "πŸ“Œ Fetching Ceph Versions and EOL Status..."
    @echo "-----------------------------------"
    @echo "Active Releases:"
    @echo "-----------------------------------"
    @echo "Name | Initial Release | Latest | EOL (Estimated)"
    @echo "---------|-----------------|---------|-----------------"
    @echo "Squid | 2024-09-26 | 19.2.1 | 2026-09-19"
    @echo "Reef | 2023-08-07 | 18.2.4 | 2025-08-01"
    @echo ""
    @echo "-----------------------------------"
    @echo "Archived Releases:"
    .PHONY: install bootstrap add-mon add-osd add-mgr add-mds add-rgw create-pool enable-dashboard

    install:
    @echo "πŸ“₯ Installing Ceph dependencies..."
    sudo apt update && sudo apt install -y ceph cephadm ceph-common

    bootstrap:
    @echo "πŸš€ Bootstrapping Ceph cluster..."
    sudo cephadm bootstrap --mon-ip $(MON_IP)

    add-mon:
    @echo "πŸ”— Adding Monitor nodes..."
    for node in $(MON_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mon"; \
    done

    add-osd:
    @echo "πŸ“¦ Adding OSD nodes..."
    for node in $(OSD_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply osd --all-available-devices"; \
    done

    add-mgr:
    @echo "πŸ› οΈ Adding Manager nodes..."
    for node in $(MGR_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mgr"; \
    done

    add-mds:
    @echo "πŸ“‚ Adding Metadata Servers..."
    for node in $(MDS_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply mds $(FS_NAME) --placement=1"; \
    done

    add-rgw:
    @echo "🌍 Adding RADOS Gateway (S3-Compatible Object Storage)..."
    for node in $(RGW_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply rgw rgw.$(shell hostname) --placement=1"; \
    done

    create-pool:
    @echo "πŸ’Ύ Creating Ceph Pool: $(POOL_NAME)..."
    sudo ceph osd pool create $(POOL_NAME) 128 128 replicated
    sudo ceph osd pool set $(POOL_NAME) size $(POOL_SIZE)

    enable-dashboard:
    @echo "🌍 Enabling Ceph Dashboard..."
    sudo ceph mgr module enable dashboard
    sudo ceph dashboard create-self-signed-cert

    ## List all Ceph Pools
    list-pools:
    @echo "πŸ“Œ Listing Ceph Pools..."
    @echo "-----------------------------------"
    @echo "Name | Initial Release | Latest | EOL"
    @echo "---------|-----------------|---------|-----------------"
    @echo "Quincy | 2022-04-19 | 17.2.8 | 2025-01-13"
    @echo "Pacific | 2021-03-31 | 16.2.15 | 2024-03-04"
    @echo "Octopus | 2020-03-23 | 15.2.17 | 2022-08-09"
    @echo "Nautilus | 2019-03-19 | 14.2.22 | 2021-06-30"
    @echo "Mimic | 2018-06-01 | 13.2.10 | 2020-07-22"
    @echo "Luminous | 2017-08-01 | 12.2.13 | 2020-03-01"
    @echo "Name | Data Protection | Application | PG Status"
    @echo "-------------------------|----------------|------------|-----------"
    @sudo ceph osd pool ls detail | awk '/pool/{printf "%-25s", $$2} /size/{printf "| Replication: x%s ", $$3} /application/{printf "| %s ", $$3} /pg_num/{printf "| %s\n", $$2}'
    @echo "-----------------------------------"

    ## Mount CephFS on a local directory
    mount-cephfs:
    @echo "πŸ“‚ Mounting CephFS..."
    sudo mkdir -p /mnt/cephfs
    sudo mount -t ceph :/ /mnt/cephfs -o name=admin,secret=$(shell sudo ceph auth get-key client.admin)
    @echo "βœ… CephFS Mounted at /mnt/cephfs"

  3. tafaust revised this gist Feb 15, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # --- Configuration ---
    MON_IP ?= 192.168.1.10 # Primary monitor node IP
    POOL_NAME ?= mypool
    POOL_NAME ?= $(shell sudo ceph osd pool ls | grep "cephfs.cephfs.data" || echo "default_pool")
    POOL_SIZE ?= 3
    OSD_DEVICES ?= /dev/sdb # Modify as per your system
    FS_NAME ?= cephfs
  4. tafaust revised this gist Feb 15, 2025. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -88,4 +88,23 @@ glossary:
    ## Display Ceph Versions and End-of-Life Status
    ceph-versions:
    @echo "πŸ“Œ Fetching Ceph Versions and EOL Status..."
    @curl -s https://docs.ceph.com/en/latest/releases/ | grep -E 'Releases|End-of-Life|EOL' | sed 's/<[^>]*>//g'
    @echo "-----------------------------------"
    @echo "Active Releases:"
    @echo "-----------------------------------"
    @echo "Name | Initial Release | Latest | EOL (Estimated)"
    @echo "---------|-----------------|---------|-----------------"
    @echo "Squid | 2024-09-26 | 19.2.1 | 2026-09-19"
    @echo "Reef | 2023-08-07 | 18.2.4 | 2025-08-01"
    @echo ""
    @echo "-----------------------------------"
    @echo "Archived Releases:"
    @echo "-----------------------------------"
    @echo "Name | Initial Release | Latest | EOL"
    @echo "---------|-----------------|---------|-----------------"
    @echo "Quincy | 2022-04-19 | 17.2.8 | 2025-01-13"
    @echo "Pacific | 2021-03-31 | 16.2.15 | 2024-03-04"
    @echo "Octopus | 2020-03-23 | 15.2.17 | 2022-08-09"
    @echo "Nautilus | 2019-03-19 | 14.2.22 | 2021-06-30"
    @echo "Mimic | 2018-06-01 | 13.2.10 | 2020-07-22"
    @echo "Luminous | 2017-08-01 | 12.2.13 | 2020-03-01"
    @echo "-----------------------------------"
  5. tafaust revised this gist Feb 15, 2025. 1 changed file with 22 additions and 46 deletions.
    68 changes: 22 additions & 46 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ SSH_USER ?= ceph-admin

    # --- High-Level Targets ---

    .PHONY: setup-cluster expand-cluster recover-cluster monitor-cluster upgrade-cluster status clean
    .PHONY: setup-cluster expand-cluster recover-cluster monitor-cluster upgrade-cluster status clean glossary ceph-versions

    ## Full Cluster Setup (One Command)
    setup-cluster: install bootstrap add-mon add-osd add-mgr add-mds create-pool enable-dashboard status
    @@ -68,48 +68,24 @@ clean:
    sudo cephadm rm-cluster --force --zap-osds
    @echo "βœ… Ceph Cluster Removed!"

    # --- Core Tasks ---

    .PHONY: install bootstrap add-mon add-osd add-mgr add-mds create-pool enable-dashboard

    install:
    @echo "πŸ“₯ Installing Ceph dependencies..."
    sudo apt update && sudo apt install -y ceph cephadm ceph-common

    bootstrap:
    @echo "πŸš€ Bootstrapping Ceph cluster..."
    sudo cephadm bootstrap --mon-ip $(MON_IP)

    add-mon:
    @echo "πŸ”— Adding Monitor nodes..."
    for node in $(MON_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mon"; \
    done

    add-osd:
    @echo "πŸ“¦ Adding OSD nodes..."
    for node in $(OSD_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply osd --all-available-devices"; \
    done

    add-mgr:
    @echo "πŸ› οΈ Adding Manager nodes..."
    for node in $(MGR_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mgr"; \
    done

    add-mds:
    @echo "πŸ“‚ Adding Metadata Servers..."
    for node in $(MDS_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply mds $(FS_NAME) --placement=1"; \
    done

    create-pool:
    @echo "πŸ’Ύ Creating Ceph Pool: $(POOL_NAME)..."
    sudo ceph osd pool create $(POOL_NAME) 128 128 replicated
    sudo ceph osd pool set $(POOL_NAME) size $(POOL_SIZE)

    enable-dashboard:
    @echo "🌍 Enabling Ceph Dashboard..."
    sudo ceph mgr module enable dashboard
    sudo ceph dashboard create-self-signed-cert
    ## Display a Glossary of Ceph Terms
    glossary:
    @echo "πŸ“– Ceph Glossary:"
    @echo "-----------------------------------"
    @echo "πŸ”Ή MON (Monitor) - Tracks cluster state and quorum."
    @echo "πŸ”Ή OSD (Object Storage Daemon) - Stores and replicates data."
    @echo "πŸ”Ή MGR (Manager) - Provides monitoring and management tools."
    @echo "πŸ”Ή MDS (Metadata Server) - Supports CephFS (file storage)."
    @echo "πŸ”Ή RBD (RADOS Block Device) - Ceph's block storage solution."
    @echo "πŸ”Ή RGW (RADOS Gateway) - S3-compatible object storage."
    @echo "πŸ”Ή Erasure Coding - Data redundancy alternative to replication."
    @echo "πŸ”Ή Placement Group (PG) - Logical grouping of OSDs for data distribution."
    @echo "πŸ”Ή Quorum - Minimum required MONs to maintain cluster integrity."
    @echo "πŸ”Ή BlueStore - Default storage backend for Ceph OSDs."
    @echo "πŸ”Ή Ceph Dashboard - Web UI for monitoring and management."
    @echo "-----------------------------------"

    ## Display Ceph Versions and End-of-Life Status
    ceph-versions:
    @echo "πŸ“Œ Fetching Ceph Versions and EOL Status..."
    @curl -s https://docs.ceph.com/en/latest/releases/ | grep -E 'Releases|End-of-Life|EOL' | sed 's/<[^>]*>//g'
  6. tafaust created this gist Feb 15, 2025.
    115 changes: 115 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    # --- Configuration ---
    MON_IP ?= 192.168.1.10 # Primary monitor node IP
    POOL_NAME ?= mypool
    POOL_SIZE ?= 3
    OSD_DEVICES ?= /dev/sdb # Modify as per your system
    FS_NAME ?= cephfs
    CEPH_IMAGE ?= quay.io/ceph/ceph:v17

    # Cluster Nodes
    MON_NODES = mon1 mon2 mon3
    OSD_NODES = osd1 osd2 osd3
    MGR_NODES = mgr1
    MDS_NODES = mds1

    # SSH Credentials
    SSH_USER ?= ceph-admin

    # --- High-Level Targets ---

    .PHONY: setup-cluster expand-cluster recover-cluster monitor-cluster upgrade-cluster status clean

    ## Full Cluster Setup (One Command)
    setup-cluster: install bootstrap add-mon add-osd add-mgr add-mds create-pool enable-dashboard status
    @echo "βœ… Ceph Cluster Setup Completed!"

    ## Expand the Cluster with New Storage Nodes
    expand-cluster: add-osd
    @echo "βœ… Ceph Cluster Expanded!"

    ## Detect and Recover Failed OSDs
    recover-cluster:
    @echo "πŸ” Checking for failed OSDs..."
    @FAILED_OSDS=$$(sudo ceph health detail | grep -oP 'osd.\d+' | grep -oP '\d+'); \
    if [ -n "$$FAILED_OSDS" ]; then \
    for osd in $$FAILED_OSDS; do \
    echo "πŸ”„ Replacing OSD $$osd"; \
    sudo ceph osd out $$osd; \
    sudo ceph osd purge $$osd --yes-i-really-mean-it; \
    sudo ceph orch apply osd --all-available-devices; \
    done; \
    echo "βœ… OSD Recovery Completed!"; \
    else \
    echo "βœ… No failed OSDs detected."; \
    fi

    ## Enable Monitoring (Prometheus & Grafana)
    monitor-cluster:
    @echo "πŸ“Š Setting up monitoring..."
    sudo ceph mgr module enable prometheus
    sudo ceph mgr module enable dashboard
    sudo ceph dashboard create-self-signed-cert
    @echo "βœ… Monitoring enabled! Access Grafana via the Ceph dashboard."

    ## Upgrade the Ceph Cluster
    upgrade-cluster:
    @echo "⬆️ Upgrading Ceph to $(CEPH_IMAGE)..."
    sudo ceph orch upgrade start --image $(CEPH_IMAGE)
    @echo "βœ… Ceph upgrade initiated!"

    ## Check Cluster Status
    status:
    @echo "πŸ” Checking Ceph Cluster Status..."
    sudo ceph status

    ## Clean up (Reset Cluster)
    clean:
    @echo "πŸ—‘οΈ WARNING: This will remove all Ceph data!"
    sudo cephadm rm-cluster --force --zap-osds
    @echo "βœ… Ceph Cluster Removed!"

    # --- Core Tasks ---

    .PHONY: install bootstrap add-mon add-osd add-mgr add-mds create-pool enable-dashboard

    install:
    @echo "πŸ“₯ Installing Ceph dependencies..."
    sudo apt update && sudo apt install -y ceph cephadm ceph-common

    bootstrap:
    @echo "πŸš€ Bootstrapping Ceph cluster..."
    sudo cephadm bootstrap --mon-ip $(MON_IP)

    add-mon:
    @echo "πŸ”— Adding Monitor nodes..."
    for node in $(MON_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mon"; \
    done

    add-osd:
    @echo "πŸ“¦ Adding OSD nodes..."
    for node in $(OSD_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply osd --all-available-devices"; \
    done

    add-mgr:
    @echo "πŸ› οΈ Adding Manager nodes..."
    for node in $(MGR_NODES); do \
    ssh $(SSH_USER)@$$node "sudo cephadm add mgr"; \
    done

    add-mds:
    @echo "πŸ“‚ Adding Metadata Servers..."
    for node in $(MDS_NODES); do \
    ssh $(SSH_USER)@$$node "sudo ceph orch apply mds $(FS_NAME) --placement=1"; \
    done

    create-pool:
    @echo "πŸ’Ύ Creating Ceph Pool: $(POOL_NAME)..."
    sudo ceph osd pool create $(POOL_NAME) 128 128 replicated
    sudo ceph osd pool set $(POOL_NAME) size $(POOL_SIZE)

    enable-dashboard:
    @echo "🌍 Enabling Ceph Dashboard..."
    sudo ceph mgr module enable dashboard
    sudo ceph dashboard create-self-signed-cert