#!/bin/bash
CEPH_VERSION="nautilus"
MON_HOSTS=("ceph01" "ceph02" "ceph03")
OSD_DEVICES=("/dev/vdb" "/dev/vdc")
OSD_HOSTS=("ceph01" "ceph02" "ceph03")
# Các biến IP
MON_IPS=("192.168.54.59" "192.168.54.80" "192.168.54.86")
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum install epel-release -y
yum install python2 -y
pip2 install ceph-deploy
sed -i '25,30s/^/# /' /usr/lib/python2.7/site-packages/ceph_deploy/calamari.py
sed -i '57,61s/^/# /' /usr/lib/python2.7/site-packages/ceph_deploy/hosts/__init__.py
yum update -y
cat <<EOF> /etc/yum.repos.d/ceph.repo
[ceph]
name=Ceph packages for
baseurl=https://download.ceph.com/rpm-nautilus/el8/x86_64/
enabled=1
priority=2
gpgcheck=1
gpgkey=https://download.ceph.com/keys/release.asc
[ceph-noarch]
name=Ceph noarch packages
baseurl=https://download.ceph.com/rpm-nautilus/el8/noarch
enabled=1
priority=2
gpgcheck=1
gpgkey=https://download.ceph.com/keys/release.asc
[ceph-source]
name=Ceph source packages
baseurl=https://download.ceph.com/rpm-nautilus/el8/SRPMS
enabled=0
priority=2
gpgcheck=1
gpgkey=https://download.ceph.com/keys/release.asc
EOF
echo "update repo"
yum update -y
echo "install ceph"
yum install -y ceph
echo "install ceph success"
# Cấu hình file /etc/hosts
hosts_file="/etc/hosts"
hosts_content="127.0.0.1 `hostname` localhost"
for ((i=0; i<${#MON_HOSTS[@]}; i++)); do
hosts_content+="\n${MON_IPS[$i]} ${MON_HOSTS[$i]}"
done
echo -e "$hosts_content" > "$hosts_file"
###################################
#lvm zap
for device in "${OSD_DEVICES[@]}"; do
ceph-volume lvm zap "$device" --destroy
done
#ceph-deploy new
for ((i=0; i<${#MON_HOSTS[@]}; i++)); do
ceph-deploy new ${MON_HOSTS[$i]}
done
# Cấu hình file ceph.conf
cat << EOF >> ceph.conf
public network = 192.168.54.0/24
cluster network = 192.168.54.0/24
osd objectstore = bluestore
mon_allow_pool_delete = true
osd pool default size = 3
osd pool default min size = 1
EOF
# Tạo monitor
ceph-deploy mon create-initial
# Cấu hình quyền truy cập admin
#ceph-deploy new
for ((i=0; i<${#MON_HOSTS[@]}; i++)); do
ceph-deploy admin ${MON_HOSTS[$i]}
done
for ((i=0; i<${#MON_HOSTS[@]}; i++)); do
ssh root@"${MON_HOSTS[$i]}" 'sudo chmod +r /etc/ceph/ceph.client.admin.keyring'
done
# Thêm OSD
echo "Thêm OSD"
for ((i=0; i<${#MON_HOSTS[@]}; i++)); do
for ((j=0; j<${#OSD_DEVICES[@]}; j++)); do
ceph-deploy osd create --data "${OSD_DEVICES[$j]}" "${MON_HOSTS[$i]}"
done
done
# Tạo MGR
echo "Tạo MGR"
ceph-deploy mgr create ${MON_HOSTS[0]}
ceph mgr module enable dashboard --force
ceph config set mon auth_allow_insecure_global_id_reclaim false
echo "deploy success"