-
Notifications
You must be signed in to change notification settings - Fork 11
/
swift_on_raspberry_pi.sh
executable file
·378 lines (282 loc) · 8.34 KB
/
swift_on_raspberry_pi.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
# This annotated script sets up a limited deployment of OpenStack Swift
# onto a Raspberry Pi. It sets up a one-replica, one-server environment
# appropriate for external testing. It assumes there is a user called "pi"
# and that user has sudo access (this is the default on a Raspberry Pi).
set -e
# install requirements
# I assume you've already done an `apt-get update && apt-get upgrade`
sudo apt-get install python-software-properties curl gcc git memcached \
python-coverage python-dev python-nose python-setuptools \
python-simplejson python-xattr sqlite3 xfsprogs python-eventlet \
python-greenlet python-pastedeploy python-netifaces python-pip \
python-sphinx
sudo pip install mock tox dnspython
# build loopback drive
sudo mkdir -p /srv
sudo truncate -s 1GB /srv/swift-disk
sudo mkfs.xfs -f -i size=512 /srv/swift-disk
# update /etc/fstab
grep '/srv/swift-disk' /etc/fstab
if [ $? = 1 ]; then
sudo tee -a /etc/fstab >/dev/null <<EOF
/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,inode64,logbufs=8 0 0
EOF
fi
sudo mkdir -p /mnt/sdb1/1
sudo chown -R pi:pi /mnt/sdb1/1
sudo ln -fs /mnt/sdb1/1 /srv/1
sudo chown -R pi:pi /etc/swift /srv/1/ /var/run/swift
# update /etc/rc.local
grep 'su - pi /home/pi/bin/startmain' /etc/rc.local
if [ $? = 1 ]; then
sudo tee -a /etc/rc.local >/dev/null <<EOF
mkdir -p /var/cache/swift
chown pi:pi /var/cache/swift*
mkdir -p /var/run/swift
chown pi:pi /var/run/swift
su - pi /home/pi/bin/startmain
EOF
fi
sudo tee /etc/rsyncd.conf >/dev/null <<EOF
uid = pi
gid = pi
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = 127.0.0.1
[account6012]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/account6012.lock
[container6011]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/container6011.lock
[object6010]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/object6010.lock
EOF
sudo tee /etc/rsyslog.d/10-swift.conf >/dev/null <<EOF
# Uncomment the following to have a log containing all logs together
local1,local2,local3,local4,local5.* /var/log/swift/all.log
# Uncomment the following to have hourly proxy logs for stats processing
$template HourlyProxyLog,"/var/log/swift/hourly/%\$YEAR%%\$MONTH%%\$DAY%%\$HOUR%"
local1.*;local1.!notice ?HourlyProxyLog
local1.*;local1.!notice /var/log/swift/proxy.log
local1.notice /var/log/swift/proxy.error
local1.* ~
local2.*;local2.!notice /var/log/swift/storage1.log
local2.notice /var/log/swift/storage1.error
local2.* ~
EOF
sudo mkdir -p /var/log/swift/hourly
sudo chmod -R g+w /var/log/swift
set +e
cd && git clone git://github.com/openstack/python-swiftclient.git
set -e
cd ~/python-swiftclient; git pull origin master && sudo python ./setup.py develop
set +e
cd && git clone git://github.com/openstack/swift.git
set -e
cd ~/swift; git pull origin master && sudo python ./setup.py develop
cd && mkdir -p ~/bin
sudo mkdir -p /etc/swift
sudo chown pi:pi /etc/swift
cat >/etc/swift/proxy-server.conf <<EOF
[DEFAULT]
bind_port = 8080
user = pi
log_facility = LOG_LOCAL1
log_level = DEBUG
eventlet_debug = true
[pipeline:main]
pipeline = catch_errors healthcheck proxy-logging cache slo ratelimit tempurl formpost tempauth staticweb container-quotas account-quotas proxy-logging proxy-server
[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true
account_autocreate = true
[filter:tempauth]
use = egg:swift#tempauth
user_admin_admin = admin .admin .reseller_admin
user_test_tester = testing .admin
user_test2_tester2 = testing2 .admin
user_test4_tester4 = testing4 .admin
user_test_tester3 = testing3
user_demo_demo = demo .admin
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:cache]
use = egg:swift#memcache
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:ratelimit]
use = egg:swift#ratelimit
[filter:domain_remap]
use = egg:swift#domain_remap
[filter:cname_lookup]
# Note: this middleware requires python-dnspython
use = egg:swift#cname_lookup
[filter:staticweb]
use = egg:swift#staticweb
[filter:formpost]
use = egg:swift#formpost
[filter:list-endpoints]
use = egg:swift#list_endpoints
[filter:bulk]
use = egg:swift#bulk
[filter:container-quotas]
use = egg:swift#container_quotas
[filter:account-quotas]
use = egg:swift#account_quotas
[filter:slo]
use = egg:swift#slo
[filter:tempurl]
use = egg:swift#tempurl
[filter:formpost]
use = egg:swift#formpost
EOF
cat >/etc/swift/account-server.conf <<EOF
[DEFAULT]
devices = /srv/1/node/
bind_port = 6012
user = pi
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
log_level = DEBUG
mount_check = false
disable_fallocate = true
[pipeline:main]
pipeline = recon account-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
rsync_module = {replication_ip}::account{replication_port}
[account-auditor]
[account-reaper]
EOF
cat >/etc/swift/container-server.conf <<EOF
[DEFAULT]
devices = /srv/1/node/
bind_port = 6011
user = pi
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
log_level = DEBUG
mount_check = false
disable_fallocate = true
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
rsync_module = {replication_ip}::container{replication_port}
[container-updater]
[container-auditor]
[container-sync]
EOF
cat >/etc/swift/object-server.conf <<EOF
[DEFAULT]
devices = /srv/1/node/
bind_port = 6010
user = pi
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
log_level = DEBUG
mount_check = false
disable_fallocate = true
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
rsync_module = {replication_ip}::object{replication_port}
[object-updater]
[object-auditor]
EOF
# when setting up the hash_path_suffix, it is important to make it unique
# and keep it a secret
SUFF=`python -c 'import uuid; print uuid.uuid4().hex'`
cat <<EOF >/etc/swift/swift.conf
[swift-hash]
swift_hash_path_suffix = $SUFF
[swift-constraints]
#max_file_size = 5368709122
# Note: Since the Raspberry Pi has such limited storage space,
# the maximum size of a single object has been set to 500MB.
max_file_size = 524288000
#max_meta_name_length = 128
#max_meta_value_length = 256
#max_meta_count = 90
#max_meta_overall_size = 4096
#max_object_name_length = 1024
#container_listing_limit = 10000
#account_listing_limit = 10000
#max_account_name_length = 256
#max_container_name_length = 256
EOF
cat <<EOF >/home/pi/bin/remakerings
#!/bin/bash
cd /etc/swift
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder object.builder create 8 1 0
swift-ring-builder object.builder add r1z1-127.0.0.1:6010/d1 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 8 1 0
swift-ring-builder container.builder add r1z1-127.0.0.1:6011/d1 1
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 8 1 0
swift-ring-builder account.builder add r1z1-127.0.0.1:6012/d1 1
swift-ring-builder account.builder rebalance
EOF
cat <<EOF >/home/pi/bin/resetswift
#!/bin/bash
swift-init all stop
sudo umount /srv/swift-disk
sudo mkdir -p /srv
sudo truncate -s 1GB /srv/swift-disk
sudo mkfs.xfs -f -i size=512 /srv/swift-disk
sudo mount -a
sudo mkdir -p /mnt/sdb1/1
sudo chown -R pi:pi /mnt/sdb1/*
sudo rm -rf /var/log/swift
sudo mkdir -p /var/log/swift/hourly
sudo mkdir /var/cache/swift
sudo chown -R pi:pi /var/cache/swift
find /var/cache/swift* -type f -name *.recon -exec rm -f {} \;
sudo service rsyslog restart
sudo service memcached restart
EOF
cat <<EOF >/home/pi/bin/startmain
#!/bin/bash
if [ ! -d /var/run/swift ]; then
sudo mkdir -p /var/run/swift
sudo chown -R pi:pi /var/run/swift
fi
swift-init main start
EOF
chmod +x /home/pi/bin/*
cat <<EOF
===========================================
Install completed.
You can now call \`resetswift\` and \`startmain\` to clean everything and start
the Swift server processes.
To test, try the following:
export PIIP=<IP address of your Raspberry Pi>
curl -i -H "X-Auth-User: test:tester" -H "X-Auth-Key: testing" \\
http://\${PIIP}:8080/auth/v1.0/
EOF