Skip to content

Instantly share code, notes, and snippets.

@psachin
Forked from briancline/00-readme.md
Created February 22, 2017 05:37
Show Gist options
  • Save psachin/6e236523a63770f2de2d57b6b4dfdb05 to your computer and use it in GitHub Desktop.
Save psachin/6e236523a63770f2de2d57b6b4dfdb05 to your computer and use it in GitHub Desktop.
Test Swift installation (multi-node)

These are based on updated instructions for the Swift multi-node setup guide.

Steps to install on Ubuntu 14.04, assuming at least two machines:

  1. Copy the below 3 scripts to each of your VMs (make sure to chmod +x each of them as well).
  2. Run 01-install-proxy-node.sh only on your proxy.
  3. Run 02-install-storage-node.sh only on each of your storage nodes, prefixing the command with NODE=1, where 1 is the number for that storage node (must start at 1 and increment). For instance: NODE=1 ./02-install-storage-node.sh on your first storage node, NODE=2 ./02-install-storage-node.sh on your second storage node, etc.
  4. For each of the exports provided to you by the storage node install script (STORAGE_N_IP and STORAGE_N_DISKS), copy and paste them into your shell on the proxy. Then, running set | grep -a '^STORAGE_' from your proxy should show you all the storage nodes' exports.
  5. On the proxy, run 03-build-rings.sh. It will show you all the nodes and disks it discovered from your environment, build the rings, and copy them to each of your storage nodes.
  6. On the proxy, run swift-init all start.
  7. On your storage nodes, run swift-init all start.
  8. On your proxy, interactively run as many commands from 04-basic-check.sh as you wish.
#!/bin/bash
set -o errexit
## You can export the following in your environment to set these,
## otherwise they'll be defaulted to the values shown.
export SWIFT_VERSION=${SWIFT_VERSION:-1.12.0}
export PRIV_NET_PREFIX=${PRIV_NET_PREFIX:-"10\."}
export PRIV_IP=$(ip addr | grep "inet $PRIV_NET_PREFIX" | sed -e 's|/| |g' | awk '{print $2}')
export PROXY_1_IP=${PROXY_1_IP:-$PRIV_IP}
export HASH_PREFIX=${HASH_PREFIX:-$(od -t x8 -N 8 -A n </dev/urandom)}
export HASH_SUFFIX=${HASH_SUFFIX:-$(od -t x8 -N 8 -A n </dev/urandom)}
export PROXY_WORKERS=${PROXY_WORKERS:-8}
export PROXY_PORT=${PROXY_PORT:-80}
## Update system packages and install dependencies
export DEBIAN_FRONTEND=noninteractive
apt-get -q update
apt-get -q -y dist-upgrade
apt-get -q -y install \
vim nano openssh-server memcached git \
build-essential libffi-dev libxml2-dev libxslt1-dev python-dev \
python-swiftclient python-pip
apt-get -q -y autoremove
## Create system user and set permissions on Swift directories
useradd -s /usr/sbin/nologin swift
mkdir -p /etc/swift /var/cache/swift
## Install Swift
git clone git://github.com/openstack/swift
pushd swift
git checkout ${SWIFT_VERSION}
python setup.py install
popd
## Configure memcached
sed -i /etc/memcached.conf -e "s/-l 127.0.0.1/-l ${PRIV_IP}/"
service memcached restart
## Create proxy configuration
cat >/etc/swift/swift.conf <<EOF
[swift-hash]
# Unique hashes used for data placement that can never change (DO NOT LOSE)
swift_hash_path_prefix = $HASH_PREFIX
swift_hash_path_suffix = $HASH_SUFFIX
EOF
cat >/etc/swift/proxy-server.conf <<EOF
[DEFAULT]
# cert_file = /etc/swift/cert.crt
# key_file = /etc/swift/cert.key
bind_port = ${PROXY_PORT}
workers = ${PROXY_WORKERS}
user = swift
[pipeline:main]
pipeline = catch_errors gatekeeper healthcheck proxy-logging cache container_sync bulk tempurl slo ratelimit 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:proxy-logging]
use = egg:swift#proxy_logging
[filter:tempauth]
use = egg:swift#tempauth
user_system_root = testpass .admin http://${PRIV_IP}:${PROXY_PORT}/v1/AUTH_system
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:cache]
use = egg:swift#memcache
memcache_servers = ${PRIV_IP}:11211
[filter:bulk]
use = egg:swift#bulk
[filter:ratelimit]
use = egg:swift#ratelimit
[filter:formpost]
use = egg:swift#formpost
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:staticweb]
use = egg:swift#staticweb
[filter:tempurl]
use = egg:swift#tempurl
[filter:container-quotas]
use = egg:swift#container_quotas
[filter:slo]
use = egg:swift#slo
[filter:account-quotas]
use = egg:swift#account_quotas
[filter:gatekeeper]
use = egg:swift#gatekeeper
[filter:container_sync]
use = egg:swift#container_sync
EOF
# Set final permissions on everything
chown -R swift.swift /etc/swift /var/cache/swift
#!/bin/bash
set -o errexit
## Explicitly set your disk names by exporting them as SWIFT_DISKS prior to
## running this script, separating each with a space. You may also leave empty
## to automatically find all unmounted, non-swap block devices.
##
## This can either take the form of "xvdc xvdd xvde",
## or of "/dev/xvdc /dev/xvdd /dev/xvde".
export SWIFT_VERSION=${SWIFT_VERSION:-1.12.0}
export DISKS="${SWIFT_DISKS:-}"
export PRIV_NET_PREFIX=${PRIV_NET_PREFIX:-"10\."}
export PRIV_IP=$(ip addr | grep "inet $PRIV_NET_PREFIX" | sed -e 's|/| |g' | awk '{print $2}')
export HASH_PREFIX=${HASH_PREFIX:-}
export HASH_SUFFIX=${HASH_SUFFIX:-}
export RSYNC_MAX_CONN=${RSYNC_MAX_CONN:-4}
export SERVICE_WORKERS=${SERVICE_WORKERS:-4}
export NODE=${NODE:-1}
# if [ -z "${HASH_PREFIX}" ] || [ -z "${HASH_SUFFIX}" ]; then
# echo "Export HASH_PREFIX and HASH_SUFFIX prior to running this script." >&2
# echo "Ensure they match the values configured on your proxies." >&2
# exit 1
# fi
if [ -z "${DISKS}" ]; then
diskdevs="$(cat /proc/partitions | tail -n+2 | sort -k4 | grep -Ev '[0-9]$' | awk '{print $4}')"
for diskdev in $diskdevs; do
## Skip if mounted (OS or other)
mountcount=$(mount | grep -Ec "/dev/${diskdev}[0-9 ]" || true)
[ "$mountcount" -gt 0 ] && continue
## Skip if swap
parttypes="$(blkid -o value -s TYPE /dev/${diskdev}* || true)"
[[ "$parttypes" =~ "swap" ]] && continue
DISKS="${DISKS} ${diskdev}"
done
fi
echo "Swift version: ${SWIFT_VERSION}"
echo "Data disks: ${DISKS}"
## Update system packages and install dependencies
export DEBIAN_FRONTEND=noninteractive
apt-get -q update
apt-get -q -y dist-upgrade
apt-get -q -y install \
vim nano openssh-server gdisk xfsprogs git \
build-essential libffi-dev libxml2-dev libxslt1-dev python-dev \
python-swiftclient python-pip python-mysqldb
apt-get -q -y autoremove
## Create system user and set permissions on Swift directories
useradd -s /usr/sbin/nologin swift
mkdir -p /etc/swift /var/cache/swift /srv/node
chown -R swift.swift /etc/swift /var/cache/swift
## Wipe, partition, fstab, and mount each disk
for disk in $DISKS; do
[ "${disk:0:5}" = "/dev/" ] || disk="/dev/${disk}"
diskname=$(basename $disk)
disknum=$((${disknum:-0} + 1))
disklabel="d${disknum}"
## Destroy any existing partitions
sgdisk -Z ${disk}
sgdisk --clear ${disk}
## Don't need to create a partition, but here's how, if you really want to
# sgdisk -N 1 ${disk}
## Sets a label of dN, where N is the number
mkfs.xfs -f -i size=512 -L${disklabel} ${disk}
## Add label-based fstab entry
echo "LABEL=${disklabel} /srv/node/${disklabel} xfs noatime,nodiratime,logbufs=8,inode64 0 2" >> /etc/fstab
## Create mount point and mount it (all by label)
mkdir -p /srv/node/${disklabel}
mount /srv/node/${disklabel}
chown -R swift.swift /srv/node/${disklabel}
done
## Install Swift
git clone git://github.com/openstack/swift
pushd swift
git checkout ${SWIFT_VERSION}
python setup.py install
popd
## Configure rsyncd
sed -i /etc/default/rsync -e 's|RSYNC_ENABLE=false|RSYNC_ENABLE=true|'
cat >/etc/rsyncd.conf <<EOF
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = ${PRIV_IP}
[account]
max connections = ${RSYNC_MAX_CONN}
path = /srv/node/
read only = false
lock file = /var/lock/account.lock
[container]
max connections = ${RSYNC_MAX_CONN}
path = /srv/node/
read only = false
lock file = /var/lock/container.lock
[object]
max connections = ${RSYNC_MAX_CONN}
path = /srv/node/
read only = false
lock file = /var/lock/object.lock
# Don't use this in a production environment
[swift-config]
path = /etc/swift/
read only = false
lock file = /var/lock/swift-config.lock
EOF
## Configure cluster-wide Swift settings
# cat >/etc/swift/swift.conf <<EOF
# [swift-hash]
# # Unique hashes used for data placement that can never change (DO NOT LOSE)
# swift_hash_path_prefix = $HASH_PREFIX
# swift_hash_path_suffix = $HASH_SUFFIX
# EOF
## Configure Swift account-server
cat >/etc/swift/account-server.conf <<EOF
[DEFAULT]
bind_ip = ${PRIV_IP}
workers = ${SERVICE_WORKERS}
[pipeline:main]
pipeline = recon account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
[account-auditor]
[account-reaper]
[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift
EOF
## Configure Swift container server
cat >/etc/swift/container-server.conf <<EOF
[DEFAULT]
bind_ip = ${PRIV_IP}
workers = ${SERVICE_WORKERS}
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[container-replicator]
[container-updater]
[container-auditor]
[container-sync]
[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift
EOF
## Configure Swift object server
cat >/etc/swift/object-server.conf <<EOF
[DEFAULT]
bind_ip = ${PRIV_IP}
workers = ${SERVICE_WORKERS}
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
[object-updater]
[object-auditor]
[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift
EOF
## Add cron job for swift-recon (gathers async_pending stats for object server)
echo '*/5 * * * * swift /usr/local/bin/swift-recon-cron /etc/swift/object-server.conf' > /etc/cron.d/swift-recon
## Ensure all permissions are good
chown -R swift.swift /etc/swift
## Start services
service rsync restart
## Huzzah!
echo "------------------------------------------------------------"
echo "Installation complete. Export the following on your proxy for ring building:"
echo "export STORAGE_${NODE}_IP=${PRIV_IP}"
echo "export STORAGE_${NODE}_DISKS=""${DISKS}"""
echo ""
echo "After building and syncing your ring, start Swift via 'swift-init all start'."
#!/bin/bash
set -o errexit
## For each storage node you have, number each starting at 1,
## and export two variables for it. For instance:
## export STORAGE_1_IP="10.0.237.20"
## export STORAGE_1_DISKS="xvdc xvde xvdf"
STORAGE_NODES=""
NODE_COUNT=0
## Determine storage node IPs and total storage node count
while true; do
nodenum=$((${nodenum:-0} + 1))
eval ip=\$STORAGE_${nodenum}_IP
eval disks=\$STORAGE_${nodenum}_DISKS
if [ -z "$ip" ]; then
break
fi
if [ -z "$disks" ]; then
echo "No disks in STORAGE_${nodenum}_DISKS, exiting" >&2
exit 1
fi
STORAGE_NODES="${STORAGE_NODES} ${ip}"
NODE_COUNT=$((${NODE_COUNT:-0} + 1))
done
if [ -z "${STORAGE_NODES}" ] || [ "${NODE_COUNT}" -eq 0 ]; then
echo "No storage node IPs exported. Exiting." >&2
exit 1
fi
## Output discovered IPs and disks
echo "Storage nodes:"
for nodenum in $(seq 1 ${NODE_COUNT}); do
eval ip=\$STORAGE_${nodenum}_IP
eval disks=\$STORAGE_${nodenum}_DISKS
echo "- $ip"
for disk in $disks; do
echo " - ${disk}"
done
done
## Generate ring files
pushd /etc/swift
echo "Creating builder files..."
swift-ring-builder account.builder create 18 3 1
swift-ring-builder container.builder create 18 3 1
swift-ring-builder object.builder create 18 3 1
region=1
zone=1
weight=100
for nodenum in $(seq 1 ${NODE_COUNT}); do
eval ip=\$STORAGE_${nodenum}_IP
eval disks=\$STORAGE_${nodenum}_DISKS
disknum=0
for disk in $disks; do
disknum=$((${disknum:-0} + 1))
disklabel="d${disknum}"
swift-ring-builder account.builder add r${region}z${zone}-${ip}:6002/${disklabel} ${weight}
swift-ring-builder container.builder add r${region}z${zone}-${ip}:6001/${disklabel} ${weight}
swift-ring-builder object.builder add r${region}z${zone}-${ip}:6000/${disklabel} ${weight}
done
done
echo "Rebalancing rings..."
swift-ring-builder account.builder rebalance
swift-ring-builder container.builder rebalance
swift-ring-builder object.builder rebalance
swift-ring-builder account.builder
swift-ring-builder container.builder
swift-ring-builder object.builder
popd
## Copy rings, builder files, and swift.conf to each storage node
for node_ip in $STORAGE_NODES; do
# scp /etc/swift/*.gz /etc/swift/swift.conf $node_ip:/etc/swift/
rsync -av --no-owner --no-group /etc/swift/swift.conf /etc/swift/*.{gz,builder} ${node_ip}::swift-config
done
swift_url="http://localhost:80/auth/v1.0"
swift_user="system:root"
swift_pass="testpass"
# Show own account stats
swift -A $swift_url -U $swift_user -K $swift_pass stat
# Show cluster's supported capabilities
swift -A $swift_url -U $swift_user -K $swift_pass list logfiles --lh
# Create a container
swift -A $swift_url -U $swift_user -K $swift_pass post mycontainer
# Upload all /var/log contents into a container
swift -A $swift_url -U $swift_user -K $swift_pass upload logfiles /var/log/
# List containers
swift -A $swift_url -U $swift_user -K $swift_pass list
# List containers with details
swift -A $swift_url -U $swift_user -K $swift_pass list --lh
# List objects in logfiles container
swift -A $swift_url -U $swift_user -K $swift_pass list logfiles
# List objects in logfiles container with details
swift -A $swift_url -U $swift_user -K $swift_pass list logfiles --lh
# List objects in logfiles container with details
swift -A $swift_url -U $swift_user -K $swift_pass list logfiles --lh
# Upload only changed files to logfiles container
swift -A $swift_url -U $swift_user -K $swift_pass upload logfiles /var/log/ --changed
# Upload only differing files to logfiles container (by comparing local and remote md5 hashes)
swift -A $swift_url -U $swift_user -K $swift_pass upload logfiles /var/log/ --skip-identical
# Check object count and space usage for account
swift -A $swift_url -U $swift_user -K $swift_pass stat
# Delete container and its contents
swift -A $swift_url -U $swift_user -K $swift_pass delete logfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment