Install Memcached on cPanel server (CentOS)

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Install Memcached on cPanel server (CentOS)

Postby lik » Sat Jul 09, 2011 1:25 am

Memcached - high-performance memory object caching system. It requires LibEvent:
Code: Select all
mkdir ~/memcached
cd ~/memcached
wget "http://monkey.org/~provos/libevent-2.0.12-stable.tar.gz"
tar xvfz libevent-2.0.12-stable.tar.gz
cd libevent-2.0.12-stable
./configure && make && make install

Now we are ready to install Memcached:
Code: Select all
cd ~/memcached
wget "http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz"
tar xvfz memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --with-lib-event=/usr/local/ && make && make install

Configure dynamic linker run time bindings for LibEvent:
Code: Select all
echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent.conf
ldconfig

Create init script for Memcached:
Code: Select all
touch /etc/init.d/memcached
chmod +x /etc/init.d/memcached

Code: Select all
#!/bin/bash
#
# Init file for memcached
#
# Written by Dag Wieërs <dag@wieers.com>
#
# chkconfig: - 80 12
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached
# config: /etc/memcached.conf

source /etc/rc.d/init.d/functions

### Default variables
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="128"
OPTIONS="-l 127.0.0.1"
SYSCONFIG="/etc/sysconfig/memcached"

### Read configuration                                                                                                                                                                                     
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"                                                                                                                                                                 
                                                                                                                                                                                                           
RETVAL=0                                                                                                                                                                                                   
prog="memcached"                                                                                                                                                                                           
desc="Distributed memory caching"                                                                                                                                                                         
                                                                                                                                                                                                           
start() {                                                                                                                                                                                                 
        echo -n $"Starting $desc ($prog): "                                                                                                                                                               
        daemon /usr/local/bin/$prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS                                                                                                               
        RETVAL=$?                                                                                                                                                                                         
        echo                                                                                                                                                                                               
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog                                                                                                                                                 
        return $RETVAL                                                                                                                                                                                     
}                                                                                                                                                                                                         
                                                                                                                                                                                                           
stop() {                                                                                                                                                                                                   
        echo -n $"Shutting down $desc ($prog): "                                                                                                                                                           
        killproc $prog                                                                                                                                                                                     
        RETVAL=$?                                                                                                                                                                                         
        echo                                                                                                                                                                                               
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog                                                                                                                                                 
        return $RETVAL                                                                                                                                                                                     
}

restart() {
        stop
        start
}

reload() {
        echo -n $"Reloading $desc ($prog): "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  reload)
        reload
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL

And configuration file (RH-way) with the following content:
Code: Select all
touch /etc/sysconfig/memcached

Code: Select all
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="128"
OPTIONS="-l 127.0.0.1"

Register Memcached as service and enable it:
Code: Select all
chkconfig --add memcached
chkconfig memcached on

Start Memcached daemon:
Code: Select all
service memcached start

Check Memcached stats (if no issues during the service start are noticed):
Code: Select all
echo stats | nc 127.0.0.1 11211
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific

 


  • Related topics
    Replies
    Views
    Last post
cron