-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·304 lines (263 loc) · 9.12 KB
/
entrypoint.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/env bash
set -eux
set -o pipefail
ZONE="$(hostname -s | grep -oP '^[a-z]+[0-9]+')"
ZONE_GROUP="$(hostname -d | grep -oP '^[a-z0-9]+')"
REALM="$(hostname -d | grep -oP '^[a-z0-9]+')"
DOMAIN="$(hostname -d)"
##
# create ceph.conf
##
echo "create ceph.conf"
cat <<- EOF > /etc/ceph/ceph.conf
[global]
fsid = $(uuidgen)
mon_host = $(hostname -i)
auth_allow_insecure_global_id_reclaimi = false
mon_warn_on_pool_no_redundancy = false
mon_osd_down_out_interval = 60
mon_osd_report_timeout = 300
mon_osd_down_out_subtree_limit = host
mon_osd_reporter_subtree_level = rack
osd_scrub_auto_repair = true
osd_pool_default_size = 1
osd_pool_default_min_size = 1
osd_pool_default_pg_num = 1
osd_crush_chooseleaf_type = 0
osd_objectstore = memstore
EOF
##
# create mon
##
echo "create ceph mon"
ceph-authtool \
--create-keyring /tmp/ceph.mon.keyring \
--gen-key -n mon. \
--cap mon 'allow *'
ceph-authtool \
--create-keyring /etc/ceph/ceph.client.admin.keyring \
--gen-key -n client.admin \
--cap mon 'allow *' \
--cap osd 'allow *' \
--cap mds 'allow *' \
--cap mgr 'allow *'
ceph-authtool /tmp/ceph.mon.keyring \
--import-keyring /etc/ceph/ceph.client.admin.keyring
monmaptool \
--create \
--add "$(hostname -s)" "$(hostname -i)" \
--fsid "$(grep -oP '(?<=^fsid = )[0-9a-z-]*' /etc/ceph/ceph.conf)" \
--set-min-mon-release pacific \
--enable-all-features \
--clobber \
/tmp/monmap
mkdir -p "/var/lib/ceph/mon/ceph-$(hostname -s)"
rm -rf "/var/lib/ceph/mon/ceph-$(hostname -s)/*"
ceph-mon --mkfs -i "$(hostname -s)" --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring
chown -R ceph:ceph /var/lib/ceph/mon/
ceph-mon --cluster ceph --id "$(hostname -s)" --setuser ceph --setgroup ceph
ceph config set global auth_allow_insecure_global_id_reclaim false
##
# create mgr
##
echo "create ceph mgr"
mkdir -p "/var/lib/ceph/mgr/ceph-$(hostname -s)"
ceph auth get-or-create "mgr.$(hostname -s)" mon 'allow profile mgr' osd 'allow *' mds 'allow *' \
> "/var/lib/ceph/mgr/ceph-$(hostname -s)/keyring"
chown -R ceph:ceph /var/lib/ceph/mgr/
ceph-mgr --cluster ceph --id "$(hostname -s)" --setuser ceph --setgroup ceph
##
# crate osd
##
OSD=$(ceph osd create)
echo "create ceph osd.${OSD}"
mkdir -p "/osd/osd.${OSD}/data"
ceph auth get-or-create "osd.${OSD}" mon 'allow profile osd' mgr 'allow profile osd' osd 'allow *' \
> "/osd/osd.${OSD}/data/keyring"
ceph-osd -i "${OSD}" --mkfs --osd-data "/osd/osd.${OSD}/data"
chown -R ceph:ceph "/osd/osd.${OSD}/data"
ceph-osd -i "${OSD}" --osd-data "/osd/osd.${OSD}/data" --keyring "/osd/osd.${OSD}/data/keyring"
##
# create rgw
##
echo "create ceph rgw"
mkdir -p "/var/lib/ceph/radosgw/ceph-rgw.$(hostname -s)"
ceph auth get-or-create "client.rgw.$(hostname -s)" osd 'allow rwx' mon 'allow rw' \
-o "/var/lib/ceph/radosgw/ceph-rgw.$(hostname -s)/keyring"
touch "/var/lib/ceph/radosgw/ceph-rgw.$(hostname -s)/done"
chown -R ceph:ceph /var/lib/ceph/radosgw
if [ "${MAIN}" == "none" ]; then
echo "create admin-user"
radosgw-admin user create \
--uid=".admin" \
--display-name="admin" \
--system \
--key-type="s3" \
--access-key="${ACCESS_KEY}" \
--secret-key="${SECRET_KEY}"
ceph config set global rgw_enable_usage_log true
ceph config set global rgw_dns_name "$(hostname -s)"
radosgw --cluster ceph --rgw-zone "default" --name "client.rgw.$(hostname -s)" --setuser ceph --setgroup ceph
fi
if [ "${MAIN}" == "yes" ]; then
echo "create realm ${REALM}"
radosgw-admin realm create \
--rgw-realm="${REALM}" \
--default
echo "create zonegroup ${ZONE_GROUP}"
radosgw-admin zonegroup create \
--rgw-realm="${REALM}" \
--rgw-zonegroup="${ZONE_GROUP}" \
--endpoints="http://${DOMAIN}:7480" \
--master \
--default
radosgw-admin zonegroup get --rgw-zonegroup="${ZONE_GROUP}" | \
jq \
--arg domain "${DOMAIN}" \
--arg zone1 "dev1-${DOMAIN}" \
--arg zone2 "dev2-${DOMAIN}" \
'.hostnames |= [$domain, $zone1, $zone2]' | \
radosgw-admin zonegroup set --rgw-zonegroup="${ZONE_GROUP}" -i -
echo "create zone ${ZONE}"
radosgw-admin zone create \
--rgw-zonegroup="${ZONE_GROUP}" \
--rgw-zone="${ZONE}" \
--endpoints="http://${ZONE}-${DOMAIN}:7480" \
--master \
--default
echo "create placement PREMIUM"
radosgw-admin zonegroup placement add \
--rgw-zonegroup="${ZONE_GROUP}" \
--placement-id="default-placement" \
--storage-class="PREMIUM"
echo "create placement ARCHIVE"
radosgw-admin zonegroup placement add \
--rgw-zonegroup="${ZONE_GROUP}" \
--placement-id="default-placement" \
--storage-class="ARCHIVE"
echo "create synchronization-user"
radosgw-admin user create \
--uid=".synchronization" \
--display-name="synchronization-user" \
--system \
--key-type="s3" \
--access-key="${ACCESS_KEY}" \
--secret-key="${SECRET_KEY}"
echo "add synchronization-user to zone ${ZONE}"
radosgw-admin zone modify \
--rgw-zone="${ZONE}" \
--access-key="${ACCESS_KEY}" \
--secret-key="${SECRET_KEY}"
##
# disable the defaut sync of buckets between zones,
# but allow specific ones to replicate
##
radosgw-admin sync group create \
--group-id=group-main \
--status=allowed
radosgw-admin sync group flow create \
--group-id=group-main \
--flow-id=flow-main \
--flow-type=symmetrical \
--zones=dev1,dev2
radosgw-admin sync group pipe create \
--group-id=group-main \
--pipe-id=pipe-main \
--source-zones='*' \
--source-bucket='*' \
--dest-zones='*' \
--dest-bucket='*'
##
# enable mirroring for a specific bucket between zones
##
# radosgw-admin sync group create \
# --bucket=test1 \
# --group-id=group-test1 \
# --status=enabled
# radosgw-admin sync group pipe create \
# --bucket=test1 \
# --group-id=group-test1 \
# --pipe-id=pipe-test1 \
# --source-zones='*' \
# --source-bucket='*' \
# --dest-zones='*' \
# --dest-bucket='*'
echo "create objstorage-admin user"
radosgw-admin user create \
--uid=".objstorage-admin" \
--display-name=".objstorage-admin" \
--system \
--admin
radosgw-admin period update \
--commit
fi
if [ "${MAIN}" == "no" ]; then
echo "get realm http://${DOMAIN}:7480"
while ! radosgw-admin realm pull \
--url="http://${DOMAIN}:7480" \
--access-key="${ACCESS_KEY}" \
--secret="${SECRET_KEY}"; do sleep 0.5; done
echo "set default realm to ${ZONE_GROUP}"
radosgw-admin realm default \
--rgw-realm="${ZONE_GROUP}"
echo "create zone ${ZONE}"
radosgw-admin zone create \
--rgw-zonegroup="${ZONE_GROUP}" \
--rgw-zone="${ZONE}" \
--access-key="${ACCESS_KEY}" \
--secret-key="${SECRET_KEY}" \
--endpoints="http://${ZONE}-${DOMAIN}:7480" \
--default
fi
if [ "${MAIN}" == "yes" ] || [ "${MAIN}" == "no" ]; then
echo "create placement PREMIUM for ${ZONE}"
radosgw-admin zone placement add \
--rgw-zone="${ZONE}" \
--placement-id="default-placement" \
--storage-class="PREMIUM" \
--data-pool "${ZONE}.rgw.buckets.premium.data"
echo "create placement STANDARD for ${ZONE}"
radosgw-admin zone placement add \
--rgw-zone="${ZONE}" \
--placement-id="default-placement" \
--storage-class="STANDARD" \
--data-pool "${ZONE}.rgw.buckets.standard.data"
echo "create placement ARCIVE for ${ZONE}"
radosgw-admin zone placement add \
--rgw-zone="${ZONE}" \
--placement-id="default-placement" \
--storage-class="ARCHIVE" \
--data-pool "${ZONE}.rgw.buckets.archive.data" \
--compression lz4
radosgw-admin period update --commit
ceph config set global rgw_enable_usage_log true
radosgw --cluster ceph --rgw-zone "${ZONE}" --name "client.rgw.$(hostname -s)" --setuser ceph --setgroup ceph
fi
# Configure Cluster
ceph mgr module enable dashboard --force
ceph mgr module enable prometheus --force
ceph mgr module enable diskprediction_local --force
ceph mgr module enable stats --force
ceph mgr module disable nfs
ceph config set mgr mgr/dashboard/ssl false --force
ceph dashboard feature disable rbd cephfs nfs iscsi mirroring
echo "${MGR_PASSWORD}" | ceph dashboard ac-user-create "${MGR_USERNAME}" -i - administrator --force-password
echo "${ACCESS_KEY}" | ceph dashboard set-rgw-api-access-key -i -
echo "${SECRET_KEY}" | ceph dashboard set-rgw-api-secret-key -i -
ceph dashboard set-rgw-api-ssl-verify False
# Test API
curl -X 'POST' \
'http://127.0.0.1:8080/api/auth' \
-H 'accept: application/vnd.ceph.api.v1.0+json' \
-H 'Content-Type: application/json' \
-d "{
\"username\": \"${MGR_USERNAME}\",
\"password\": \"${MGR_PASSWORD}\"
}"
##
# log output in forground
##
while ! tail -F /var/log/ceph/ceph* ; do
sleep 0.1
done
echo "Container terminated ..."