2017-07-19 23:22:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# 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
|
2018-02-27 16:51:48 +00:00
|
|
|
mon_dir=${base_dir}/mon.a/
|
|
|
|
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-07-19 23:22:38 +00:00
|
|
|
dev_backend=/dev/ceph
|
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
|
|
|
|
|
|
|
umount $dev || true
|
|
|
|
losetup -d $dev_backend || true
|
|
|
|
|
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
|
|
|
|
fallocate -l 10G $image
|
|
|
|
fi
|
|
|
|
|
|
|
|
mknod ${dev_backend} b 7 200 || true
|
|
|
|
losetup ${dev_backend} ${image} || true
|
|
|
|
|
|
|
|
PARTED="parted -s"
|
|
|
|
SGDISK="sgdisk"
|
|
|
|
|
|
|
|
echo "Partitioning ${dev}"
|
|
|
|
${PARTED} ${dev} mktable gpt
|
|
|
|
sleep 2
|
|
|
|
${PARTED} ${dev} mkpart primary 0% 5GiB
|
|
|
|
${PARTED} ${dev} mkpart primary 5GiB 100%
|
|
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
|
|
|
# prep osds
|
|
|
|
|
|
|
|
mnt_pt=${mnt_dir}/osd-device-0-data/
|
|
|
|
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}
|
|
|
|
echo -e "\tosd data = ${mnt_pt}" >> "$ceph_conf"
|
|
|
|
echo -e "\tosd journal = /dev/disk/by-partlabel/osd-device-0-journal" >> "$ceph_conf"
|
|
|
|
|
2018-04-16 13:12:23 +00:00
|
|
|
# add mon address
|
|
|
|
echo -e "\t[mon.a]" >> "$ceph_conf"
|
|
|
|
echo -e "\tmon addr = ${mon_ip}:12046" >> "$ceph_conf"
|
2017-07-19 23:22:38 +00:00
|
|
|
|
|
|
|
# create mon
|
|
|
|
rm -rf ${mon_dir}/*
|
|
|
|
mkdir -p ${mon_dir}
|
|
|
|
mkdir -p ${pid_dir}
|
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
ceph-authtool --create-keyring --gen-key --name=mon. ${base_dir}/keyring --cap mon 'allow *'
|
|
|
|
ceph-authtool --gen-key --name=client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *' ${base_dir}/keyring
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2018-02-27 16:51:48 +00:00
|
|
|
monmaptool --create --clobber --add a ${mon_ip}:12046 --print ${base_dir}/monmap
|
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
|
|
|
|
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
|
2017-07-19 23:22:38 +00:00
|
|
|
|
2018-02-27 16:51:48 +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
|
|
|
|
|
|
|
# create osd
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
mkdir -p ${mnt_dir}
|
|
|
|
|
|
|
|
uuid=`uuidgen`
|
|
|
|
ceph -c ${ceph_conf} osd create ${uuid} $i
|
|
|
|
ceph-osd -c ${ceph_conf} -i $i --mkfs --mkkey --osd-uuid ${uuid}
|
|
|
|
ceph -c ${ceph_conf} osd crush add osd.${i} 1.0 host=`hostname` root=default
|
|
|
|
ceph -c ${ceph_conf} -i ${mnt_dir}/osd-device-${i}-data/keyring auth add osd.${i} osd "allow *" mon "allow profile osd" mgr "allow"
|
|
|
|
|
|
|
|
# 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
|