-
Notifications
You must be signed in to change notification settings - Fork 11
/
ceph_create_pool_image.sh
43 lines (36 loc) · 1.29 KB
/
ceph_create_pool_image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Author Dario Clavijo 2018
# GPLv3
set -x
# set variables
POOL=$1
IMG=$2
SIZE=$3
PAGES=$4
USER=$5
LDEV=$6 # example rbd0
FS=$7 # example "mkfs.ext4 -j"
MONITOR="172.16.1.1 172.16.2.2"
ceph auth del client.$USER
ceph osd pool delete $POOL $IMG --yes-i-really-really-mean-it
# define pool,image and rbd mapping
ceph osd pool create $POOL $PAGES
rbd pool init $POOL
rbd create --size $SIZE $POOL/$IMG
# define user permissions
ceph auth get-or-create client.$USER mon "allow r" osd "allow class-read object_prefix rbd_children, allow rwx pool=$POOL"
KEY=$(ceph auth get-or-create client.$USER | tail -n 1 | awk '{ print $3 }')
# disable incompatible features
rbd feature disable $POOL/$IMG fast-diff
rbd feature disable $POOL/$IMG deep-flatten
rbd feature disable $POOL/$IMG object-map
# create the deploy.sh for the client.
echo "#!/bin/bash" > deploy_$USER.sh
echo "echo deploying ceph..." >> deploy_$USER.sh
echo "sudo apt-get install ceph-common -y" >> deploy_$USER.sh
echo "sudo modprobe rbd" >> deploy_$USER.sh
echo "sudo echo '$MONITOR name=$USER,secret=$KEY $POOL $IMG' | sudo tee /sys/bus/rbd/add" >> deploy_$USER.sh
echo "sudo $FS /dev/$LDEV" >> deploy_$USER.sh
echo "sudo mkdir /media/$LDEV" >> deploy_$USER.sh
echo "sudo mount /dev/$LDEV /media/$LDEV" >> deploy_$USER.sh
chmod u+x deploy_$USER.sh