2017-07-19 23:22:38 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2017 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2017-07-19 23:22:38 +00:00
|
|
|
# create mon
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
script_dir=$(readlink -f $(dirname $0))
|
|
|
|
|
|
|
|
base_dir=/var/tmp/ceph
|
2018-04-16 13:12:23 +00:00
|
|
|
mon_ip=$1
|
2019-10-10 16:01:45 +00:00
|
|
|
mon_dir=${base_dir}/mon.a
|
2018-02-27 16:51:48 +00:00
|
|
|
pid_dir=${base_dir}/pid
|
2017-07-19 23:22:38 +00:00
|
|
|
ceph_conf=${base_dir}/ceph.conf
|
2018-02-27 16:51:48 +00:00
|
|
|
mnt_dir=${base_dir}/mnt
|
2017-08-10 23:57:06 +00:00
|
|
|
image=/var/tmp/ceph_raw.img
|
2017-07-19 23:22:38 +00:00
|
|
|
dev=/dev/loop200
|
2018-04-05 16:21:38 +00:00
|
|
|
|
2021-03-26 11:30:53 +00:00
|
|
|
modprobe loop
|
2019-10-28 14:15:04 +00:00
|
|
|
umount ${dev}p2 || true
|
2019-11-12 11:52:53 +00:00
|
|
|
losetup -d $dev || true
|
2018-04-05 16:21:38 +00:00
|
|
|
|
2017-07-19 23:22:38 +00:00
|
|
|
# partition osd
|
2018-02-28 16:50:42 +00:00
|
|
|
if [ -d $base_dir ]; then
|
|
|
|
rm -rf $base_dir
|
|
|
|
fi
|
2018-02-27 16:51:48 +00:00
|
|
|
mkdir ${base_dir}
|
|
|
|
cp ${script_dir}/ceph.conf $ceph_conf
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
if [ ! -e $image ]; then
|
2020-05-07 11:27:06 +00:00
|
|
|
fallocate -l 4G $image
|
2017-07-19 23:22:38 +00:00
|
|
|
fi
|
|
|
|
|
2019-11-12 11:52:53 +00:00
|
|
|
mknod ${dev} b 7 200 || true
|
|
|
|
losetup ${dev} ${image} || true
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
PARTED="parted -s"
|
|
|
|
SGDISK="sgdisk"
|
|
|
|
|
|
|
|
echo "Partitioning ${dev}"
|
|
|
|
${PARTED} ${dev} mktable gpt
|
|
|
|
sleep 2
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
${PARTED} ${dev} mkpart primary 0% 2GiB
|
|
|
|
${PARTED} ${dev} mkpart primary 2GiB 100%
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
partno=0
|
|
|
|
echo "Setting name on ${dev}"
|
|
|
|
${SGDISK} -c 1:osd-device-${partno}-journal ${dev}
|
|
|
|
${SGDISK} -c 2:osd-device-${partno}-data ${dev}
|
|
|
|
kpartx ${dev}
|
|
|
|
|
2019-11-12 10:28:18 +00:00
|
|
|
# later versions of ceph-12 have a lot of changes, to compatible with the new
|
|
|
|
# version of ceph-deploy.
|
|
|
|
ceph_version=$(ceph -v | awk '{print $3}')
|
|
|
|
ceph_maj=${ceph_version%%.*}
|
|
|
|
if [ $ceph_maj -gt 12 ]; then
|
|
|
|
update_config=true
|
|
|
|
rm -f /var/log/ceph/ceph-mon.a.log || true
|
|
|
|
set_min_mon_release="--set-min-mon-release 14"
|
|
|
|
ceph_osd_extra_config="--check-needs-journal --no-mon-config"
|
|
|
|
else
|
|
|
|
update_config=false
|
|
|
|
set_min_mon_release=""
|
|
|
|
ceph_osd_extra_config=""
|
|
|
|
fi
|
|
|
|
|
2017-07-19 23:22:38 +00:00
|
|
|
# prep osds
|
|
|
|
|
2019-10-10 16:01:45 +00:00
|
|
|
mnt_pt=${mnt_dir}/osd-device-0-data
|
2017-07-19 23:22:38 +00:00
|
|
|
mkdir -p ${mnt_pt}
|
|
|
|
mkfs.xfs -f /dev/disk/by-partlabel/osd-device-0-data
|
|
|
|
mount /dev/disk/by-partlabel/osd-device-0-data ${mnt_pt}
|
2019-11-18 11:32:48 +00:00
|
|
|
cat << EOL >> $ceph_conf
|
|
|
|
osd data = ${mnt_pt}
|
|
|
|
osd journal = /dev/disk/by-partlabel/osd-device-0-journal
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2018-04-16 13:12:23 +00:00
|
|
|
# add mon address
|
2019-11-18 11:32:48 +00:00
|
|
|
[mon.a]
|
|
|
|
mon addr = ${mon_ip}:12046
|
|
|
|
EOL
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
# create mon
|
2019-10-16 08:43:49 +00:00
|
|
|
rm -rf "${mon_dir:?}/"*
|
2017-07-19 23:22:38 +00:00
|
|
|
mkdir -p ${mon_dir}
|
|
|
|
mkdir -p ${pid_dir}
|
2019-10-22 05:18:40 +00:00
|
|
|
rm -f /etc/ceph/ceph.client.admin.keyring
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
ceph-authtool --create-keyring --gen-key --name=mon. ${base_dir}/keyring --cap mon 'allow *'
|
2019-10-10 16:01:45 +00:00
|
|
|
ceph-authtool --gen-key --name=client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *' ${base_dir}/keyring
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2019-11-12 10:28:18 +00:00
|
|
|
monmaptool --create --clobber --add a ${mon_ip}:12046 --print ${base_dir}/monmap $set_min_mon_release
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
sh -c "ulimit -c unlimited && exec ceph-mon --mkfs -c ${ceph_conf} -i a --monmap=${base_dir}/monmap --keyring=${base_dir}/keyring --mon-data=${mon_dir}"
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
if [ $update_config = true ]; then
|
2019-11-12 10:28:18 +00:00
|
|
|
sed -i 's/mon addr = /mon addr = v2:/g' $ceph_conf
|
|
|
|
fi
|
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
cp ${base_dir}/keyring ${mon_dir}/keyring
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
cp $ceph_conf /etc/ceph/ceph.conf
|
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
cp ${base_dir}/keyring /etc/ceph/keyring
|
2019-10-22 05:18:40 +00:00
|
|
|
cp ${base_dir}/keyring /etc/ceph/ceph.client.admin.keyring
|
|
|
|
chmod a+r /etc/ceph/ceph.client.admin.keyring
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2019-07-03 15:12:39 +00:00
|
|
|
ceph-run sh -c "ulimit -n 16384 && ulimit -c unlimited && exec ceph-mon -c ${ceph_conf} -i a --keyring=${base_dir}/keyring --pid-file=${base_dir}/pid/root@$(hostname).pid --mon-data=${mon_dir}" || true
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2019-11-12 10:28:18 +00:00
|
|
|
# after ceph-mon creation, ceph -s should work.
|
2020-05-07 11:27:06 +00:00
|
|
|
if [ $update_config = true ]; then
|
|
|
|
# start to get whole log.
|
2019-11-12 10:28:18 +00:00
|
|
|
ceph-conf --name mon.a --show-config-value log_file
|
|
|
|
|
|
|
|
# add fsid to ceph config file.
|
2020-05-07 11:27:06 +00:00
|
|
|
fsid=$(ceph -s | grep id | awk '{print $2}')
|
|
|
|
sed -i 's/perf = true/perf = true\n\tfsid = '$fsid' \n/g' $ceph_conf
|
2019-11-12 10:28:18 +00:00
|
|
|
|
|
|
|
# unify the filesystem with the old versions.
|
|
|
|
sed -i 's/perf = true/perf = true\n\tosd objectstore = filestore\n/g' $ceph_conf
|
|
|
|
cat ${ceph_conf}
|
|
|
|
fi
|
|
|
|
|
2017-07-19 23:22:38 +00:00
|
|
|
# create osd
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
mkdir -p ${mnt_dir}
|
|
|
|
|
2019-07-03 15:12:39 +00:00
|
|
|
uuid=$(uuidgen)
|
2017-07-19 23:22:38 +00:00
|
|
|
ceph -c ${ceph_conf} osd create ${uuid} $i
|
2019-11-12 10:28:18 +00:00
|
|
|
ceph-osd -c ${ceph_conf} -i $i --mkfs --mkkey --osd-uuid ${uuid} ${ceph_osd_extra_config}
|
2019-07-03 15:12:39 +00:00
|
|
|
ceph -c ${ceph_conf} osd crush add osd.${i} 1.0 host=$(hostname) root=default
|
2019-10-09 14:29:03 +00:00
|
|
|
ceph -c ${ceph_conf} -i ${mnt_dir}/osd-device-${i}-data/keyring auth add osd.${i} osd "allow *" mon "allow profile osd" mgr "allow *"
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2022-12-22 17:04:09 +00:00
|
|
|
class_dir=/$(ceph -c "$ceph_conf" config get osd osd_class_dir)
|
|
|
|
[[ -e $class_dir ]]
|
|
|
|
ceph -c "$ceph_conf" config set osd osd_class_dir "$class_dir"
|
|
|
|
|
2017-07-19 23:22:38 +00:00
|
|
|
# start osd
|
|
|
|
pkill -9 ceph-osd || true
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
mkdir -p ${pid_dir}
|
|
|
|
env -i TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=134217728 ceph-osd -c ${ceph_conf} -i 0 --pid-file=${pid_dir}/ceph-osd.0.pid
|