This script will automatically install memcached on Debian, and set it to start at system boot.
1) Create install_memcached.sh
vi install_memcached.sh
2) Copy & paste the script into your editor:
PHP Code:
#!/bin/bash
#
# Download and install libevent and memcached from source on Debian Etch or
# Debian Lenny.
#
# Assumptions
# - libevent and memcached have not been installed from apt repositories
# - memcached is not already running
# - it is ok to clobber scripts at
# /etc/memcached.conf
# /etc/init.d/memcached
# /usr/share/memcached/scripts/start-memcached
#
# Author : Scott Barr
# Date : 14 Dec 2009
#
sudo apt-get install sysv-rc-conf
cd /usr/local/src/
# See http://www.monkey.org/~provos/libevent/ for versions
LIBEVENT_VERSION="libevent-1.4.13-stable"
# See http://memcached.org/ for latest version.
# File is assumed to reside at http://memcached.googlecode.com/files/memcached-${MEMCACHED_VERSION}.tar.gz
MEMCACHED_VERSION="1.4.5"
# where libevent will be installed
LIBEVENT_PREFIX="/opt/${LIBEVENT_VERSION}"
# get the major version of libevent
LIBEVENT_MAJOR_VERSION=`echo $LIBEVENT_VERSION | cut -d\. -f 1,2 | cut -d\- -f 2`
# where memcached will be installed
MEMCACHED_PREFIX="/opt/memcached-${MEMCACHED_VERSION}"
# download, configure and install libevent
wget http://www.monkey.org/~provos/${LIBEVENT_VERSION}.tar.gz
tar -zxf ${LIBEVENT_VERSION}.tar.gz
cd ${LIBEVENT_VERSION}
sudo mkdir /opt/${LIBEVENT_VERSION}
./configure --prefix=${LIBEVENT_PREFIX}
make
sudo make install
sudo ln -s /opt/${LIBEVENT_VERSION}/lib/libevent-${LIBEVENT_MAJOR_VERSION}.so.2 /usr/lib/libevent-${LIBEVENT_MAJOR_VERSION}.so.2
cd ..
# download configure and install memcached
wget http://memcached.googlecode.com/files/memcached-${MEMCACHED_VERSION}.tar.gz
tar -zxf memcached-${MEMCACHED_VERSION}.tar.gz
cd memcached-${MEMCACHED_VERSION}
./configure --prefix=${MEMCACHED_PREFIX} --with-libevent=${LIBEVENT_PREFIX}
make
sudo make install
sudo ln -s /opt/memcached-${MEMCACHED_VERSION}/bin/memcached /usr/local/bin/memcached
cd ..
# download and install memcached config files
wget http://github.com/havoc/memcached/raw/master/start-memcached --no-check-certificate
sudo mkdir -p /usr/share/memcached/scripts
sudo mv start-memcached /usr/share/memcached/scripts/
sudo chmod o+x /usr/share/memcached/scripts/start-memcached
wget http://github.com/havoc/memcached/raw/master/memcached --no-check-certificate
sudo mv memcached /etc/init.d/memcached
sudo chmod o+x /etc/init.d/memcached
wget http://github.com/havoc/memcached/raw/master/memcached.conf --no-check-certificate
sudo mv memcached.conf /etc/memcached.conf
sudo /etc/init.d/memcached start
sudo sysv-rc-conf --level 2345 memcached on
3) Run the script!
chmod +x install_memcached.sh sudo ./install_memcached.sh
4) PROFIT!!! Memcached will automatically start at system boot. You can tweak the settings as needed in /etc/memcached.conf. By default memcached will use 512MB of memory, change as needed.
(I did not write this script, the original script found here:
here. The only difference is the conf file the installer downloads.)