xref: /spdk/scripts/ceph/start.sh (revision 407e88fd2ab020d753e33014cf759353a9901b51)
1#!/usr/bin/env bash
2# create mon
3
4set -x
5set -e
6
7script_dir=$(readlink -f $(dirname $0))
8
9base_dir=/var/tmp/ceph
10mon_ip=$1
11mon_dir=${base_dir}/mon.a/
12pid_dir=${base_dir}/pid
13ceph_conf=${base_dir}/ceph.conf
14mnt_dir=${base_dir}/mnt
15dev_backend=/dev/ceph
16image=/var/tmp/ceph_raw.img
17dev=/dev/loop200
18
19umount $dev || true
20losetup -d $dev_backend || true
21
22# partition osd
23if [ -d $base_dir ]; then
24	rm -rf $base_dir
25fi
26mkdir ${base_dir}
27cp ${script_dir}/ceph.conf $ceph_conf
28
29if [ ! -e $image ]; then
30        fallocate -l 4G $image
31fi
32
33mknod ${dev_backend} b 7 200 || true
34losetup ${dev_backend} ${image} || true
35
36PARTED="parted -s"
37SGDISK="sgdisk"
38
39echo "Partitioning ${dev}"
40${PARTED} ${dev} mktable gpt
41sleep 2
42
43${PARTED} ${dev} mkpart primary    0%    2GiB
44${PARTED} ${dev} mkpart primary   2GiB  100%
45
46partno=0
47echo "Setting name on ${dev}"
48${SGDISK} -c 1:osd-device-${partno}-journal ${dev}
49${SGDISK} -c 2:osd-device-${partno}-data ${dev}
50kpartx ${dev}
51
52# prep osds
53
54mnt_pt=${mnt_dir}/osd-device-0-data/
55mkdir -p ${mnt_pt}
56mkfs.xfs -f /dev/disk/by-partlabel/osd-device-0-data
57mount /dev/disk/by-partlabel/osd-device-0-data ${mnt_pt}
58echo -e "\tosd data = ${mnt_pt}" >> "$ceph_conf"
59echo -e "\tosd journal = /dev/disk/by-partlabel/osd-device-0-journal" >> "$ceph_conf"
60
61# add mon address
62echo -e "\t[mon.a]" >> "$ceph_conf"
63echo -e "\tmon addr = ${mon_ip}:12046" >> "$ceph_conf"
64
65# create mon
66rm -rf ${mon_dir}/*
67mkdir -p ${mon_dir}
68mkdir -p ${pid_dir}
69
70ceph-authtool --create-keyring --gen-key --name=mon. ${base_dir}/keyring --cap mon 'allow *'
71ceph-authtool --gen-key --name=client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *' ${base_dir}/keyring
72
73monmaptool --create --clobber --add a ${mon_ip}:12046 --print ${base_dir}/monmap
74
75sh -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}"
76
77cp ${base_dir}/keyring ${mon_dir}/keyring
78
79cp $ceph_conf /etc/ceph/ceph.conf
80
81cp ${base_dir}/keyring /etc/ceph/keyring
82
83ceph-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
84
85# create osd
86
87i=0
88
89mkdir -p ${mnt_dir}
90
91uuid=$(uuidgen)
92ceph -c ${ceph_conf} osd create ${uuid} $i
93ceph-osd -c ${ceph_conf} -i $i --mkfs --mkkey --osd-uuid ${uuid}
94ceph -c ${ceph_conf} osd crush add osd.${i} 1.0 host=$(hostname) root=default
95ceph -c ${ceph_conf} -i ${mnt_dir}/osd-device-${i}-data/keyring auth add osd.${i} osd "allow *" mon "allow profile osd" mgr "allow"
96
97# start osd
98pkill -9 ceph-osd || true
99sleep 2
100
101mkdir -p ${pid_dir}
102env -i TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=134217728 ceph-osd -c ${ceph_conf} -i 0 --pid-file=${pid_dir}/ceph-osd.0.pid
103