Last active
August 17, 2017 22:33
-
-
Save heiths/a2e32e10b5876ea7fb412aa1305f5778 to your computer and use it in GitHub Desktop.
Swift all in one (SAIO) installer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Make sure we’re running with root permissions. | |
if [ ${USER} != root ]; then | |
echo Please run this script using sudo | |
exit | |
fi | |
# Make ubuntu is > 16.10 | |
if [ ${USER} != root ]; then | |
echo Please run this script using sudo | |
exit | |
fi | |
# SETUP OPTIONS | |
# sdb should be the default for the second drive. If not, set it here. | |
read -p "Which drive should swift use? Existing data will be lost! [default 'sdb']: " SWIFTDRIVE | |
SWIFTDRIVE=${SWIFTDRIVE:-'sdb'} | |
echo "Swiftdrive: $SWIFTDRIVE" | |
# Setup the Code root | |
read -p "Where do you want to put the source code? [default '/h']: " CODEROOT | |
CODEROOT=${CODEROOT:-'/h'} | |
echo "installing to $CODEROOT" | |
# ---------------------------------------------------------- | |
sudo mkdir -p $CODEROOT | |
sudo chown ${SUDO_USER}:${SUDO_USER} $CODEROOT | |
## Install required system packages | |
sudo apt-get update | |
sudo apt -y --force-yes install curl gcc memcached rsync sqlite3 xfsprogs \ | |
git-core libffi-dev python-setuptools \ | |
liberasurecode-dev libssl-dev libjerasure-dev libxss1 \ | |
build-essential autoconf automake libtool | |
## Install required python packages | |
sudo apt -y --force-yes install python-coverage python-dev python-nose \ | |
python-xattr python-eventlet \ | |
python-greenlet python-pastedeploy \ | |
python-netifaces python-pip python-dnspython \ | |
python-mock python-pyeclib | |
# Setup mount points | |
sudo mkdir -p /mnt/${SWIFTDRIVE}1 | |
# Partition the swift drive | |
printf "o\nn\np\n1\n\n\nw" | sudo fdisk /dev/${SWIFTDRIVE} | |
export DPART=${SWIFTDRIVE}1 | |
# Format the Partition | |
sudo mkfs.xfs /dev/${SWIFTDRIVE}1 | |
# Add Partition to fstab so it mounts on boot | |
echo "/dev/${SWIFTDRIVE}1 /mnt/${DPART} xfs noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab | |
# Mount from fstab | |
sudo mount -a | |
# Create the individualized links | |
sudo mkdir /mnt/${DPART}/1 /mnt/${DPART}/2 /mnt/${DPART}/3 /mnt/${DPART}/4 | |
sudo chown ${SUDO_USER}:${SUDO_USER} /mnt/${DPART}/* | |
sudo mkdir /srv | |
for x in {1..4}; do sudo ln -s /mnt/${DPART}/$x /srv/$x; done | |
sudo mkdir -p /srv/1/node/${DPART}${SWIFTDRIVE} /srv/1/node/${SWIFTDRIVE}5 \ | |
/srv/2/node/${SWIFTDRIVE}2 /srv/2/node/${SWIFTDRIVE}6 \ | |
/srv/3/node/${SWIFTDRIVE}3 /srv/3/node/${SWIFTDRIVE}7 \ | |
/srv/4/node/${SWIFTDRIVE}4 /srv/4/node/${SWIFTDRIVE}8 \ | |
/var/run/swift | |
sudo chown -R ${SUDO_USER}:${SUDO_USER} /var/run/swift | |
# **Make sure to include the trailing slash after /srv/$x/** | |
for x in {1..4}; do sudo chown -R ${SUDO_USER}:${SUDO_USER} /srv/$x/; done | |
cat <<EOF > $CODEROOT/bin/rebuild-swift-cache.sh | |
#!/bin/bash | |
mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4 | |
chown ${SUDO_USER}:${SUDO_USER} /var/cache/swift* | |
mkdir -p /var/run/swift | |
chown ${SUDO_USER}:${SUDO_USER} /var/run/swift | |
EOF | |
chmod 744 $CODEROOT/bin/rebuild-swift-cache.sh | |
sudo $CODEROOT/bin/rebuild-swift-cache.sh | |
# Add to systemd | |
cat <<EOF > /etc/systemd/system/rebuild-swift-cache.service | |
[Unit] | |
After=network.target | |
[Service] | |
ExecStart=/h/bin/rebuild-swift-cache.sh | |
[Install] | |
WantedBy=default.target | |
EOF | |
sudo -H pip install -U pip uwsgi | |
# Install dev version of swiftly to support "unsecure" mode | |
sudo -H pip install git+https://github.com/gholt/swiftly.git | |
# Install and enable a systemd service for rebuilding cache | |
sudo systemctl enable swift-cache-rebuilder.service | |
sudo systemctl daemon-reload | |
cd $CODEROOT | |
git clone https://github.com/openstack/python-swiftclient.git | |
cd $CODEROOT/python-swiftclient; sudo python setup.py develop; cd - | |
git clone https://github.com/openstack/swift.git | |
cd $CODEROOT/swift | |
sudo -H pip install -r requirements.txt; sudo python setup.py develop | |
sudo -H pip install -r test-requirements.txt | |
cd - | |
# Create /etc/rsyncd.conf | |
sudo cp $CODEROOT/swift/doc/saio/rsyncd.conf /etc/ | |
sudo sed -i "s/<your-user-name>/${SUDO_USER}/" /etc/rsyncd.conf | |
# Enable rsync | |
sudo sed -i "s/RSYNC_ENABLE=false/RSYNC_ENABLE=true/" /etc/default/rsync | |
sudo service rsync restart | |
# Setup logging | |
sudo cp $CODEROOT/swift/doc/saio/rsyslog.d/10-swift.conf /etc/rsyslog.d/ | |
sudo sed -i 's/\$PrivDropToGroup syslog/\$PrivDropToGroup adm/' /etc/rsyslog.conf | |
sudo echo "local1,local2,local3,local4,local5.* /var/log/swift/all.log" >> /etc/rsyslog.d/10-swift.conf | |
sudo mkdir -p /var/log/swift | |
sudo chown -R syslog.adm /var/log/swift | |
sudo chmod -R g+w /var/log/swift | |
sudo service rsyslog restart | |
## Configuring each node | |
# Populate the /etc/swift directory | |
sudo rm -rf /etc/swift | |
cd $CODEROOT/swift/doc; sudo cp -r saio/swift /etc/swift; cd - | |
sudo chown -R ${SUDO_USER}:${SUDO_USER} /etc/swift | |
# Update <your-user-name> references in the Swift config files: | |
find /etc/swift/ -name \*.conf | xargs sed -i "s/<your-user-name>/${SUDO_USER}/" | |
# Setting up scripts for running Swift | |
mkdir -p $CODEROOT/bin | |
cd $CODEROOT/swift/doc; cp saio/bin/* $CODEROOT/bin; cd - | |
chmod +x $CODEROOT/bin/* | |
# Install the sample configuration file for running tests: | |
cp $CODEROOT/swift/test/sample.conf /etc/swift/test.conf | |
sudo chown -R ${SUDO_USER}:${SUDO_USER} ~/ | |
echo "export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf" >> $HOME/.bashrc | |
echo "export PATH=${PATH}:${CODEROOT}/bin:${CODEROOT}/.npm-global/bin:/usr/local/go/bin:${CODEROOT}/go/bin" >> $HOME/.bashrc | |
# Construct the initial rings using the provided script: | |
$CODEROOT/bin/remakerings | |
sudo chown -R ${SUDO_USER}:${SUDO_USER} /etc/swift | |
sudo chown -R ${SUDO_USER}:${SUDO_USER} $CODEROOT | |
# ------------------------------------------------------------------ | |
# Install and setup Go (for hummingbird) | |
wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz | |
sudo tar -C /usr/local -xzf go1.8.linux-amd64.tar.gz | |
rm go1.8.linux-amd64.tar.gz | |
echo "export GOROOT=/usr/local/go" >> ~/.bashrc | |
echo "export GOPATH=${CODEROOT}/go" >> ~/.bashrc | |
mkdir -p $CODEROOT/go/src/github.com/openstack | |
#mkdir -p mkdir -p $GOPATH/src/github.com/openstack | |
ln -s ${CODEROOT}/swift $GOPATH/src/github.com/openstack/swift | |
cd ${CODEROOT}/go/src/github.com/openstack/swift | |
git checkout feature/hummingbird | |
cd go | |
make get test all | |
export GOROOT=/usr/local/go | |
export GOPATH=${CODEROOT}/go | |
sudo GOPATH=$GOPATH GOROOT=$GOROOT PATH=$PATH:$GOROOT/bin make develop | |
# -------------------------------------------------------------------- | |
# Give a few suggestions on what to do next | |
echo "" | |
echo -e "Setup Complete\nSource your .bashrc\n. ~/.bashrc" | |
. ${HOME}/.bashrc | |
echo "" | |
echo "start services with:" | |
echo "startmain and/or startrest" | |
echo "" | |
echo "Run functional tests:" | |
echo "$CODEROOT/swift/.functests" | |
echo "" | |
echo "Get an X-Storage-Url & X-Auth-Token" | |
echo "curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0" | |
echo "" | |
echo "Check python-swiftclient package works" | |
echo "swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat" | |
echo "" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment