What is Memcache
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Installing memcache on CentOS desktop.
We need the following three package to be installed prior to this installation.
1. libevent (http://libevent.org/)
2. memcached (http://code.google.com/p/memcached/downloads/list)
3. libmemcached (https://launchpad.net/libmemcached/+download)
Let’ start the installation,
I used to keep install copy under “/home/installation” folder
[liju@mail ~]#tar -zxvf libevent-2.0.21-stable.tar.gz
[liju@mail ~]#cd libevent-2.0.21-stable
[liju@mail ~]# You may need to install additional system packages
[liju@mail ~]#yum install gcc make gcc-c++ php-devel
[liju@mail ~]#sh configure
[liju@mail ~]#make && make install
[liju@mail ~]#cd .. $$ tar -zxvf memcached-1.4.15.tar.gz
[liju@mail ~]#cd memcached-1.4.15
[liju@mail ~]#sh configure
[liju@mail ~]#make && make install
[liju@mail ~]#cd .. && tar -zxvf libmemcached-1.0.17.tar.gz
[liju@mail ~]#cd libmemcached-1.0.17
[liju@mail ~]#make && make install
[liju@mail ~]#echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent-x86_64.conf
[liju@mail ~]#starting memecache Daemon
[liju@mail ~]#ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
[liju@mail ~]# memcached -d -u nobody -m 5120 127.0.0.1 -p 11211
[liju@mail ~]#netstat -nlp | grep ":11211"
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 3493/memcached
tcp 0 0 :::11211 :::* LISTEN 3493/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 3493/memcached
udp 0 0 :::11211 :::* 3493/memcached
Installing memcache Php module
We can install memcache module using pecl package manager easily. Pls ensure that phpize command-line utility has installed.
-
Pls note you can not work memcache and apc together.
So disable APC before installing Memcache.
# Verify the active php.ini file and sometime you may see memcache.ini placed in [liju@mail ~]#php.d config folder.
[liju@mail ~]#php --ini
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
[liju@mail ~]#php -m | grep "memcache"
memcache
[liju@mail ~]#service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
You php config will lokk like this below,
Sometimes you might hit the following error when you start the memcached service dameon
memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
Cause : Memcache looking for libeven libraries at default location(/usr/lib) which would work on 32 bit but not on 62 bit where libraries are stored in “/usr/lib64”
Solution : Set a symbolic link of libevent library into 64 bit OS library path.
Memcache startup script
You may take a copy from the below line or grab it easily from here
Copy this script under “/etc/init.d/memcached”,set 755 permission and added to system startup service.
root@cpanel01 [/etc/init.d]# chmod 755 /etc/init.d/memcached
root@cpanel01 [/etc/init.d]# chkconfig --add memcached
root@cpanel01 [/etc/init.d]# chkconfig memcached on
Startup script is showing below,
#
# memcached This shell script takes care of starting and stopping
# standalone memcached.
#
# chkconfig: - 80 12
# description: memcached is a high-performance, distributed memory
# object caching system, generic in nature, but
# intended for use in speeding up dynamic web
# applications by alleviating database load.
# processname: memcached
# config: /etc/memcached.conf
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/memcached
DAEMONBOOTSTRAP=/usr/local/bin/start-memcached
DAEMONCONF=/etc/memcached.conf
NAME=memcached
DESC=memcached
PIDFILE=/var/run/$NAME.pid
[ -x $DAEMON ] || exit 0
[ -x $DAEMONBOOTSTRAP ] || exit 0
RETVAL=0
start() {
echo -n $"Starting $DESC: "
$DAEMON $DAEMONBOOTSTRAP -d -u nobody -m 5120 127.0.0.1 -p 11211
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $PIDFILE
echo
return $RETVAL
}
stop() {
echo -n $"Shutting down $DESC: "
killproc $NAME
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $PIDFILE
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
Cheers 🙂
Leave a Reply