10ce9b8aaSSeth Howell#!/usr/bin/env bash 2eb53c232Spaul luse# SPDX-License-Identifier: BSD-3-Clause 3eb53c232Spaul luse# Copyright (C) 2017 Intel Corporation 4eb53c232Spaul luse# All rights reserved. 5eb53c232Spaul luse# 60ce9b8aaSSeth Howell# create mon 70ce9b8aaSSeth Howell 80ce9b8aaSSeth Howellset -x 90ce9b8aaSSeth Howellset -e 100ce9b8aaSSeth Howell 11ad14da9eSDaniel Verkampscript_dir=$(readlink -f $(dirname $0)) 12ad14da9eSDaniel Verkamp 13ad14da9eSDaniel Verkampbase_dir=/var/tmp/ceph 140629b01dSTomasz Zawadzkimon_ip=$1 15912ddafeSyidong0635mon_dir=${base_dir}/mon.a 16ad14da9eSDaniel Verkamppid_dir=${base_dir}/pid 170ce9b8aaSSeth Howellceph_conf=${base_dir}/ceph.conf 18ad14da9eSDaniel Verkampmnt_dir=${base_dir}/mnt 19bdd5ba09SDaniel Verkampimage=/var/tmp/ceph_raw.img 200ce9b8aaSSeth Howelldev=/dev/loop200 21dad47452SDaniel Verkamp 22f88416a1SKarol Lateckimodprobe loop 23b577d892SZiye Yangumount ${dev}p2 || true 242df77053SZiye Yanglosetup -d $dev || true 25dad47452SDaniel Verkamp 260ce9b8aaSSeth Howell# partition osd 277cf455c8SSeth Howellif [ -d $base_dir ]; then 287cf455c8SSeth Howell rm -rf $base_dir 297cf455c8SSeth Howellfi 30ad14da9eSDaniel Verkampmkdir ${base_dir} 31ad14da9eSDaniel Verkampcp ${script_dir}/ceph.conf $ceph_conf 320ce9b8aaSSeth Howell 330ce9b8aaSSeth Howellif [ ! -e $image ]; then 342cc2bbe6Syidong0635 fallocate -l 4G $image 350ce9b8aaSSeth Howellfi 360ce9b8aaSSeth Howell 372df77053SZiye Yangmknod ${dev} b 7 200 || true 382df77053SZiye Yanglosetup ${dev} ${image} || true 390ce9b8aaSSeth Howell 400ce9b8aaSSeth HowellPARTED="parted -s" 410ce9b8aaSSeth HowellSGDISK="sgdisk" 420ce9b8aaSSeth Howell 430ce9b8aaSSeth Howellecho "Partitioning ${dev}" 440ce9b8aaSSeth Howell${PARTED} ${dev} mktable gpt 450ce9b8aaSSeth Howellsleep 2 460ce9b8aaSSeth Howell 472cc2bbe6Syidong0635${PARTED} ${dev} mkpart primary 0% 2GiB 482cc2bbe6Syidong0635${PARTED} ${dev} mkpart primary 2GiB 100% 490ce9b8aaSSeth Howell 500ce9b8aaSSeth Howellpartno=0 510ce9b8aaSSeth Howellecho "Setting name on ${dev}" 520ce9b8aaSSeth Howell${SGDISK} -c 1:osd-device-${partno}-journal ${dev} 530ce9b8aaSSeth Howell${SGDISK} -c 2:osd-device-${partno}-data ${dev} 540ce9b8aaSSeth Howellkpartx ${dev} 550ce9b8aaSSeth Howell 5665cb0a10Sdongx.yi# later versions of ceph-12 have a lot of changes, to compatible with the new 5765cb0a10Sdongx.yi# version of ceph-deploy. 5865cb0a10Sdongx.yiceph_version=$(ceph -v | awk '{print $3}') 5965cb0a10Sdongx.yiceph_maj=${ceph_version%%.*} 6065cb0a10Sdongx.yiif [ $ceph_maj -gt 12 ]; then 6165cb0a10Sdongx.yi update_config=true 6265cb0a10Sdongx.yi rm -f /var/log/ceph/ceph-mon.a.log || true 6365cb0a10Sdongx.yi set_min_mon_release="--set-min-mon-release 14" 6465cb0a10Sdongx.yi ceph_osd_extra_config="--check-needs-journal --no-mon-config" 6565cb0a10Sdongx.yielse 6665cb0a10Sdongx.yi update_config=false 6765cb0a10Sdongx.yi set_min_mon_release="" 6865cb0a10Sdongx.yi ceph_osd_extra_config="" 6965cb0a10Sdongx.yifi 7065cb0a10Sdongx.yi 710ce9b8aaSSeth Howell# prep osds 720ce9b8aaSSeth Howell 73912ddafeSyidong0635mnt_pt=${mnt_dir}/osd-device-0-data 740ce9b8aaSSeth Howellmkdir -p ${mnt_pt} 750ce9b8aaSSeth Howellmkfs.xfs -f /dev/disk/by-partlabel/osd-device-0-data 760ce9b8aaSSeth Howellmount /dev/disk/by-partlabel/osd-device-0-data ${mnt_pt} 7702925187SMaciej Wawrykcat << EOL >> $ceph_conf 7802925187SMaciej Wawrykosd data = ${mnt_pt} 7902925187SMaciej Wawrykosd journal = /dev/disk/by-partlabel/osd-device-0-journal 800ce9b8aaSSeth Howell 810629b01dSTomasz Zawadzki# add mon address 8202925187SMaciej Wawryk[mon.a] 8302925187SMaciej Wawrykmon addr = ${mon_ip}:12046 8402925187SMaciej WawrykEOL 850ce9b8aaSSeth Howell 860ce9b8aaSSeth Howell# create mon 87f3b3fa77SMaciej Wawrykrm -rf "${mon_dir:?}/"* 880ce9b8aaSSeth Howellmkdir -p ${mon_dir} 890ce9b8aaSSeth Howellmkdir -p ${pid_dir} 907d60b02cSZiye Yangrm -f /etc/ceph/ceph.client.admin.keyring 910ce9b8aaSSeth Howell 92ad14da9eSDaniel Verkampceph-authtool --create-keyring --gen-key --name=mon. ${base_dir}/keyring --cap mon 'allow *' 93912ddafeSyidong0635ceph-authtool --gen-key --name=client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *' ${base_dir}/keyring 940ce9b8aaSSeth Howell 9565cb0a10Sdongx.yimonmaptool --create --clobber --add a ${mon_ip}:12046 --print ${base_dir}/monmap $set_min_mon_release 960ce9b8aaSSeth Howell 97ad14da9eSDaniel Verkampsh -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}" 980ce9b8aaSSeth Howell 9965cb0a10Sdongx.yiif [ $update_config = true ]; then 10065cb0a10Sdongx.yi sed -i 's/mon addr = /mon addr = v2:/g' $ceph_conf 10165cb0a10Sdongx.yifi 10265cb0a10Sdongx.yi 103ad14da9eSDaniel Verkampcp ${base_dir}/keyring ${mon_dir}/keyring 1040ce9b8aaSSeth Howell 1050ce9b8aaSSeth Howellcp $ceph_conf /etc/ceph/ceph.conf 1060ce9b8aaSSeth Howell 107ad14da9eSDaniel Verkampcp ${base_dir}/keyring /etc/ceph/keyring 1087d60b02cSZiye Yangcp ${base_dir}/keyring /etc/ceph/ceph.client.admin.keyring 1097d60b02cSZiye Yangchmod a+r /etc/ceph/ceph.client.admin.keyring 1100ce9b8aaSSeth Howell 111cf090c6cSKarol Lateckiceph-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 1120ce9b8aaSSeth Howell 11365cb0a10Sdongx.yi# after ceph-mon creation, ceph -s should work. 11465cb0a10Sdongx.yiif [ $update_config = true ]; then 11565cb0a10Sdongx.yi # start to get whole log. 11665cb0a10Sdongx.yi ceph-conf --name mon.a --show-config-value log_file 11765cb0a10Sdongx.yi 11865cb0a10Sdongx.yi # add fsid to ceph config file. 11965cb0a10Sdongx.yi fsid=$(ceph -s | grep id | awk '{print $2}') 12065cb0a10Sdongx.yi sed -i 's/perf = true/perf = true\n\tfsid = '$fsid' \n/g' $ceph_conf 12165cb0a10Sdongx.yi 122*88ae3f28SMichal Berger # filestore backend got deprecated in the Reef release and is no longer supported 123*88ae3f28SMichal Berger if ((ceph_maj < 18)); then 12465cb0a10Sdongx.yi # unify the filesystem with the old versions. 12565cb0a10Sdongx.yi sed -i 's/perf = true/perf = true\n\tosd objectstore = filestore\n/g' $ceph_conf 126*88ae3f28SMichal Berger fi 12765cb0a10Sdongx.yi cat ${ceph_conf} 12865cb0a10Sdongx.yifi 12965cb0a10Sdongx.yi 1300ce9b8aaSSeth Howell# create osd 1310ce9b8aaSSeth Howell 1320ce9b8aaSSeth Howelli=0 1330ce9b8aaSSeth Howell 1340ce9b8aaSSeth Howellmkdir -p ${mnt_dir} 1350ce9b8aaSSeth Howell 136cf090c6cSKarol Lateckiuuid=$(uuidgen) 1370ce9b8aaSSeth Howellceph -c ${ceph_conf} osd create ${uuid} $i 13865cb0a10Sdongx.yiceph-osd -c ${ceph_conf} -i $i --mkfs --mkkey --osd-uuid ${uuid} ${ceph_osd_extra_config} 139cf090c6cSKarol Lateckiceph -c ${ceph_conf} osd crush add osd.${i} 1.0 host=$(hostname) root=default 140ee8299caSMaciej Wawrykceph -c ${ceph_conf} -i ${mnt_dir}/osd-device-${i}-data/keyring auth add osd.${i} osd "allow *" mon "allow profile osd" mgr "allow *" 1410ce9b8aaSSeth Howell 142633e832cSMichal Bergerclass_dir=/$(ceph -c "$ceph_conf" config get osd osd_class_dir) 143633e832cSMichal Berger[[ -e $class_dir ]] 144633e832cSMichal Bergerceph -c "$ceph_conf" config set osd osd_class_dir "$class_dir" 145633e832cSMichal Berger 1460ce9b8aaSSeth Howell# start osd 1470ce9b8aaSSeth Howellpkill -9 ceph-osd || true 1480ce9b8aaSSeth Howellsleep 2 1490ce9b8aaSSeth Howell 1500ce9b8aaSSeth Howellmkdir -p ${pid_dir} 1510ce9b8aaSSeth Howellenv -i TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=134217728 ceph-osd -c ${ceph_conf} -i 0 --pid-file=${pid_dir}/ceph-osd.0.pid 152