Peter Stachowski 55d8598d20 Install Redis 3.2.6 by compilation
The version of Redis installed by the current elements
uses a ppa that is stalled at 3.0.7.  This seems to
have some issues that are fixed in later versions.

The recommended method of installing Redis is to compile
the code yourself, so the elements have been changed
to do this.

The version was bumped to 3.2.6 (latest stable) however
the Redis cluster tests were not reenabled as there still
seems to be an issue with them.

New config options were added to the template; these
may need to be updated to make sure all the new ones
are there.

Change-Id: I1a604b15ade815cdb51c5484d4285e504508a6c4
Partial-Bug: 1652964
2017-02-16 17:10:06 +00:00

115 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
# CONTEXT: GUEST during CONSTRUCTION as ROOT
# PURPOSE: Install controller base required packages
set -ex
export DEBIAN_FRONTEND=noninteractive
cat > "/etc/sysctl.d/10-redis-performance.conf" << _EOF_
# See 'http://redis.io/topics/admin' for best practices.
# Make sure to set the Linux kernel overcommit memory setting to 1.
vm.overcommit_memory=1
# Linux kernel will silently truncate 'tcp-backlog' to the value of
# '/proc/sys/net/core/somaxconn' so make sure to raise both the value of
# 'somaxconn' and 'tcp_max_syn_backlog' in order to get the desired effect.
net.ipv4.tcp_max_syn_backlog=1024
net.core.somaxconn=1024
_EOF_
cat > "/etc/rc.local" << _EOF_
# Make sure to disable Linux kernel feature transparent huge pages,
# it will affect greatly both memory usage and latency in a negative way.
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
_EOF_
# Install Redis from scratch
ARCH_SAV=$ARCH
unset ARCH
apt-get update
apt-get --allow-unauthenticated install -y build-essential tcl curl
cd /tmp
REDIS_VERSION=3.2.6
REDIS_NAME=redis-$REDIS_VERSION
REDIS_ARCHIVE=$REDIS_NAME.tar.gz
curl -O http://download.redis.io/releases/$REDIS_ARCHIVE
tar xzvf $REDIS_ARCHIVE
cd $REDIS_NAME
make distclean
make
make install
export ARCH=$ARCH_SAV
adduser --system --group --no-create-home redis
# Create the data dir
REDIS_DATA_DIR=/var/lib/redis
REDIS_LOG_DIR=/var/log/redis
REDIS_LOG=$REDIS_LOG_DIR/redis.log
REDIS_RUN_DIR=/var/run/redis
REDIS_PID=$REDIS_RUN_DIR/redis-server.pid
mkdir -p $REDIS_DATA_DIR
chown redis:redis $REDIS_DATA_DIR
chmod 770 $REDIS_DATA_DIR
mkdir -p $REDIS_LOG_DIR
chown redis:redis $REDIS_LOG_DIR
chmod 775 $REDIS_LOG_DIR
mkdir -p $REDIS_RUN_DIR
chown redis:redis $REDIS_RUN_DIR
# Set up a proper conf file to start
REDIS_CONF_NAME=redis.conf
REDIS_CONF_DIR=/etc/redis
REDIS_CONF=$REDIS_CONF_DIR/$REDIS_CONF_NAME
mkdir $REDIS_CONF_DIR
cp /tmp/$REDIS_NAME/$REDIS_CONF_NAME $REDIS_CONF_DIR
chown redis:redis $REDIS_CONF
sed -i "s#dir .*#dir $REDIS_DATA_DIR#" $REDIS_CONF
sed -i "s#pidfile .*#pidfile $REDIS_PID#" $REDIS_CONF
sed -i "s#logfile .*#logfile $REDIS_LOG#" $REDIS_CONF
sed -i "s/supervised no/supervised systemd/" $REDIS_CONF
sed -i "s/daemonize no/daemonize yes/" $REDIS_CONF
sed -i "s/protected-mode yes/protected-mode no/" $REDIS_CONF
cat > "/etc/systemd/system/redis-server.service" << _EOF_
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
Type=forking
PIDFile=$REDIS_PID
User=redis
Group=redis
Environment=statedir=$REDIS_RUN_DIR
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p \${statedir}
ExecStartPre=/bin/chown -R redis:redis \${statedir}
ExecStart=/usr/local/bin/redis-server $REDIS_CONF
ExecReload=/bin/kill -USR2 \$MAINPID
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
_EOF_
cat > "/etc/default/redis-server" << _EOF_
# Call ulimit -n with this argument prior to invoking Redis itself.
# This may be required for high-concurrency environments. Redis itself cannot
# alter its limits as it is not being run as root.
ULIMIT=65536
_EOF_
# Install Python driver for Redis ('redis-py').
pip2 install redis