ceph-opennebula-playbooks/ceph.sh

88 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# Install & configure Ceph (mon+mgr+osds)
# -e = stop on exception, -x = debug, -a = export all variables
set -e -x -a
# Include config
. ./load-config.sh
### Check host variables
if [ -z "$play_host" -o -z "$node_name" -o -z "$int_ip" ]; then
echo "play_host/node_name/int_ip not specified"
exit 1
fi
### Configure network
. ./network.sh
# Setup passwordless self-ssh for root
ssh root@$play_host <<EOF
set -e -x
if [ ! -f /root/.ssh/id_rsa.pub ]; then
ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -P ""
fi
> tmp$$
cat /root/.ssh/known_hosts >> tmp$$ || true
ssh-keyscan localhost >> tmp$$
ssh-keyscan $int_ip >> tmp$$
sort tmp$$ | uniq > /root/.ssh/known_hosts
rm tmp$$
> tmp$$
cat /root/.ssh/authorized_keys >> tmp$$ || true
cat /root/.ssh/id_rsa.pub >> tmp$$
sort tmp$$ | uniq > /root/.ssh/authorized_keys
rm tmp$$
EOF
### Install packages, deploy mon, mgr and osds
scp -r ceph-deploy root@$play_host:~/
cat ./ceph-deploy/ceph.conf | perl -pe "s/MON_IPS/$int_ips/" | ssh root@$play_host 'cat > ~/ceph-deploy/ceph.conf'
ssh root@$play_host <<EOF
set -e -x
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" install -y \
ceph ceph-mds ceph-deploy jq
cd ~/ceph-deploy
chmod 600 \$(find ~/ceph-deploy -type f)
cp ~/ceph-deploy/ceph.conf /etc/ceph/
ceph-deploy mon add $int_ip
ceph-deploy mgr create $node_name
cp ~/ceph-deploy/ceph.bootstrap-osd.keyring /var/lib/ceph/bootstrap-osd/ceph.keyring
chmod 600 /var/lib/ceph/bootstrap-osd/ceph.keyring
# Don't redeploy anything, just activate existing OSDs, then create new ones
vgchange -a y
ceph-volume lvm activate --all
# Select available drives larger than 1.5 TB
DRIVES=\$(ceph-volume inventory --format json | jq -r '.[] | select(.available == true and .sys_api.size >= 1500000000000) | .sys_api.path')
for DEV in \$DRIVES; do
SIZE=\$(blockdev --getsz \$DEV)
# Reserve 32 GB partition on each drive for emergency (value is in 512b sectors)
RESERVED_SIZE=67108864
OSD_SIZE=\$((SIZE-RESERVED_SIZE-2048))
RESERVED_START=\$((OSD_SIZE+2048))
PREFIX=\$(perl -e "\\\$a = '\$DEV'; \\\$a =~ s/(\d)\\\$/\\\$1p/; print \\\$a;")
echo "PREFIX=\$PREFIX"
sfdisk \$DEV <<EOD
label: gpt
\${PREFIX}1 : start=2048, size=\$OSD_SIZE, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
\${PREFIX}2 : start=\$RESERVED_START, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOD
ceph-volume lvm prepare --bluestore --data \${PREFIX}1
done
ceph-volume lvm activate --all
EOF