forked from OpenStackCookbook/OpenStackCookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swift.sh
372 lines (289 loc) · 9.07 KB
/
swift.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
# swift.sh
source /vagrant/common.sh
sudo apt-get -y install python-software-properties
sudo add-apt-repository -y ppa:ubuntu-cloud-archive/havana-staging
# The routeable IP of the node is on our eth1 interface
MY_IP=$(ifconfig eth1 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
swift_install() {
# Install some packages:
sudo apt-get -y install swift swift-proxy swift-account swift-container swift-object memcached xfsprogs curl python-webob
sudo service ntp restart
# Create signing directory & Set owner to swift
mkdir /var/swift-signing
chown -R swift /var/swift-signing
# Create cache directory & set owner to swift
mkdir -p /var/cache/swift
chown -R swift:swift /var/cache/swift
}
swift_configure(){
# Create a loopback filesystem
sudo mkdir /mnt/swift
dd if=/dev/zero of=/mnt/swift/swift-volume bs=1 count=0 seek=2G
mkfs.xfs -i size=1024 /mnt/swift/swift-volume
sudo mkdir /mnt/swift_backend
echo '/mnt/swift/swift-volume /mnt/swift_backend xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0' >> /etc/fstab
sudo mount -a
#cd /mnt/swift_backend
#sudo mkdir node{1..4}
#sudo chown swift.swift /mnt/swift_backend/*
#for i in {1..4}; do sudo ln -s /mnt/swift_backend/node$i /srv/node$i; done;
#sudo mkdir -p /etc/swift/i{account-server,container-server,object-server}
#/srv/node1/device /srv/node2/device /srv/node3/device /srv/node4/device
#sudo mkdir /run/swift
# Setup our directory structure
sudo mkdir /mnt/swift_backend/{1..4}
sudo chown swift:swift /mnt/swift_backend/*
sudo ln -s /mnt/swift_backend/{1..4} /srv
sudo mkdir -p /etc/swift/{object-server,container-server,account-server}
for S in {1..4}; do sudo mkdir -p /srv/${S}/node/sdb${S}; done
sudo mkdir -p /var/run/swift
sudo chown -R swift:swift /etc/swift /srv/{1..4}/
mkdir -p /var/run/swift
chown swift:swift /var/run/swift
# Setup rsync
sudo cat > /etc/rsyncd.conf <<EOF
uid = swift
gid = swift
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
[account6022]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/account6022.lock
[account6032]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/account6032.lock
[account6042]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/account6042.lock
[container6011]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/container6011.lock
[container6021]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/container6021.lock
[container6031]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/container6031.lock
[container6041]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/container6041.lock
[object6010]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/object6010.lock
[object6020]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/object6020.lock
[object6030]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/object6030.lock
[object6040]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/object6040.lock
EOF
sudo sed -i 's/=false/=true/' /etc/default/rsync
sudo service rsync start
# Setup /etc/swift/swift.conf
SWIFT_HASH=`< /dev/urandom tr -dc A-Za-z0-9_ | head -c16; echo`
sudo cat > /etc/swift/swift.conf <<EOF
[swift-hash]
# Random unique string used on all nodes
swift_hash_path_suffix=$SWIFT_HASH
EOF
# Configure the Swift Proxy Server
sudo cat > /etc/swift/proxy-server.conf <<EOF
[DEFAULT]
bind_port = 8080
user = swift
swift_dir = /etc/swift
log_level = DEBUG
[pipeline:main]
# Order of execution of modules defined below
pipeline = catch_errors healthcheck cache authtoken keystone proxy-server
[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true
account_autocreate = true
set log_name = swift-proxy
set log_facility = LOG_LOCAL0
set log_level = INFO
set access_log_name = swift-proxy
set access_log_facility = SYSLOG
set access_log_level = INFO
set log_headers = True
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:cache]
use = egg:swift#memcache
set log_name = cache
[filter:authtoken]
paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
auth_protocol = http
auth_host = $KEYSTONE_ENDPOINT
auth_port = 35357
auth_token = admin
service_protocol = http
service_host = $KEYSTONE_ENDPOINT
service_port = 5000
admin_token = admin
admin_tenant_name = service
admin_user = swift
admin_password = swift
delay_auth_decision = 0
signing_dir = /var/swift-signing
[filter:keystone]
use = egg:swift#keystoneauth
operator_roles = admin, Member
#reseller_prefix = AUTH_
EOF
# Setup Account Server
sudo cat > /etc/swift/account-server/1.conf <<EOF
[DEFAULT]
devices = /srv/1/node
mount_check = false
bind_port = 6012
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
vm_test_mode = yes
[account-auditor]
[account-reaper]
EOF
cd /etc/swift/account-server
sed -e "s/srv\/1/srv\/2/" -e "s/601/602/" -e "s/LOG_LOCAL2/LOG_LOCAL3/" 1.conf | sudo tee -a 2.conf
sed -e "s/srv\/1/srv\/3/" -e "s/601/603/" -e "s/LOG_LOCAL2/LOG_LOCAL4/" 1.conf | sudo tee -a 3.conf
sed -e "s/srv\/1/srv\/4/" -e "s/601/604/" -e "s/LOG_LOCAL2/LOG_LOCAL5/" 1.conf | sudo tee -a 4.conf
# Container Server config
sudo cat > /etc/swift/container-server/1.conf <<EOF
[DEFAULT]
devices = /srv/1/node
mount_check = false
bind_port = 6011
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = container-server
[app:container-server]
use = egg:swift#container
[account-replicator]
vm_test_mode = yes
[account-updater]
[account-auditor]
[account-sync]
[container-sync]
[container-auditor]
[container-replicator]
[container-updater]
EOF
cd /etc/swift/container-server
sed -e "s/srv\/1/srv\/2/" -e "s/601/602/" -e "s/LOG_LOCAL2/LOG_LOCAL3/" 1.conf | sudo tee -a 2.conf
sed -e "s/srv\/1/srv\/3/" -e "s/601/603/" -e "s/LOG_LOCAL2/LOG_LOCAL4/" 1.conf | sudo tee -a 3.conf
sed -e "s/srv\/1/srv\/4/" -e "s/601/604/" -e "s/LOG_LOCAL2/LOG_LOCAL5/" 1.conf | sudo tee -a 4.conf
echo "[container-sync]" >> /etc/swift/container-server.conf
# Object Server config
sudo cat > /etc/swift/object-server/1.conf <<EOF
[DEFAULT]
devices = /srv/1/node
mount_check = false
bind_port = 6010
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
vm_test_mode = yes
[object-updater]
[object-auditor]
EOF
cd /etc/swift/object-server
sed -e "s/srv\/1/srv\/2/" -e "s/601/602/" -e "s/LOG_LOCAL2/LOG_LOCAL3/" 1.conf | sudo tee -a 2.conf
sed -e "s/srv\/1/srv\/3/" -e "s/601/603/" -e "s/LOG_LOCAL2/LOG_LOCAL4/" 1.conf | sudo tee -a 3.conf
sed -e "s/srv\/1/srv\/4/" -e "s/601/604/" -e "s/LOG_LOCAL2/LOG_LOCAL5/" 1.conf | sudo tee -a 4.conf
# Build (or rebuild) the rings
echo "This step takes a while"
sudo cp /vagrant/remakerings.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/remakerings.sh
sudo /usr/local/bin/remakerings.sh
export ENDPOINT=172.16.0.200
export SERVICE_TOKEN=ADMIN
export SERVICE_ENDPOINT=http://${ENDPOINT}:35357/v2.0
# Swift Proxy Address
export SWIFT_PROXY_SERVER=$MY_IP
# Configure the OpenStack Storage Endpoint
keystone --token $SERVICE_TOKEN --endpoint $SERVICE_ENDPOINT service-create --name swift --type object-store --description 'OpenStack Storage Service'
# Service Endpoint URLs
ID=$(keystone service-list | awk '/\ swift\ / {print $2}')
PUBLIC_URL="http://$SWIFT_PROXY_SERVER:8080/v1/AUTH_\$(tenant_id)s"
ADMIN_URL="http://$SWIFT_PROXY_SERVER:8080/v1/"
INTERNAL_URL="http://$SWIFT_PROXY_SERVER:8080/v1/AUTH_\$(tenant_id)s"
keystone endpoint-create --region regionOne --service_id $ID --publicurl $PUBLIC_URL --adminurl $ADMIN_URL --internalurl $INTERNAL_URL
# Get the service tenant ID
SERVICE_TENANT_ID=$(keystone tenant-list | awk '/\ service\ / {print $2}')
# Create the swift user
keystone user-create --name swift --pass swift --tenant_id $SERVICE_TENANT_ID --email swift@localhost --enabled true
# Get the swift user id
USER_ID=$(keystone user-list | awk '/\ swift\ / {print $2}')
# Get the admin role id
ROLE_ID=$(keystone role-list | awk '/\ admin\ / {print $2}')
# Assign the swift user admin role in service tenant
keystone user-role-add --user $USER_ID --role $ROLE_ID --tenant_id $SERVICE_TENANT_ID
# Create .swiftrc
sudo tee /root/.swiftrc >/dev/null <<EOF
export OS_USERNAME=swift
export OS_PASSWORD=swift
export OS_TENANT_NAME=service
export OS_AUTH_URL=http://${ENDPOINT}:5000/v2.0/
EOF
# Create dispersion.conf
sudo tee /etc/swift/dispersion.conf >/dev/null <<EOF
[dispersion]
auth_url = http://${ENDPOINT}:5000/v2.0/
auth_user = cookbook:admin
auth_key = openstack
EOF
sudo chown -L -R swift.swift /etc/swift /srv/{1..4} /run/swift
}
swift_restart(){
# Start the Swift services
sudo swift-init all restart
sudo service swift-proxy restart
}
# Main
swift_install
swift_configure
swift_restart