|
#!/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'." |