日期:2014-05-16  浏览次数:20424 次

RHEL5.5下的memcachedb
由于CentOS5有一个memcached的安装包,如果要玩memcached,就直接找到memcached-1.4.5-1.el5.kb.i386.rpm下载安装了。

memcachedb麻烦一些,虽然有为opensuse弄好的包(memcachedb-1.0.4-2.1.i586),但由于RHEL5.5的C++库太老,没办法安装,只能从源代码编译起了。我的安装基本上基于一个很干净的RHEL5.5。

安装的过程可以参考http://www.auu.name/186/index.html。稍有不同的是,libevent这个包,RHEL5.5里的已经足够了,因此要做的就是编译安装db4.7和memcachedb1.2.1beta。注意,在装了前者之后,需要执行echo "/usr/local/BerkeleyDB.4.7/lib/" >> /etc/ld.so.conf.d/db4.7.ld.so.conf和ldconfig,才能让memcachedb找到新版的berkeley db。

RHEL5.5事实上也带db4的,不过版本较老,为4.3,memcachedb1.2.x不能够支持。当我install了4.7之后,发现这也不会有冲突。因为install的目标目录是/usr/local/BerkeleyDB.4.7/,而系统rpm包包含的db4有这些内容:

/lib/libdb-4.3.so
/usr/lib/libdb-4.3.so
/usr/lib/libdb_cxx-4.3.so
/usr/share/doc/db4-4.3.29
/usr/share/doc/db4-4.3.29/LICENSE
/usr/share/doc/db4-4.3.29/README


两者是可以共存的:-)

编译好了memcachedb,要弄一个/etc/init.d/memcachedb脚本,让service将memcachedb管理起来:

?
#! /bin/sh
#
# chkconfig: - 55 45
# description:	The memcachedb daemon is a network memory cache service backing by berkeley db.
# processname: memcachedb
# config: /etc/sysconfig/memcachedb
# pidfile: /var/run/memcachedb/memcachedb.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT=22222
USER=root
OPTIONS=""
DATADIR=/var/mcdb_data
PROCESSID=/var/run/memcachedb/memcachedb.pid
PROCESSIDDIR=`dirname $PROCESSID`
if [ -f /etc/sysconfig/memcachedb ];then
. /etc/sysconfig/memcachedb
fi
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcachedb"
start () {
echo -n $"Starting $prog: "
if [ ! -d $PROCESSIDDIR  ]; then
mkdir $PROCESSIDDIR -p
fi
# insure that /var/run/memcachedb has proper permissions
if [ "`stat -c %U $PROCESSIDDIR`" != "$USER" ]; then
chown $USER $PROCESSIDDIR
fi
daemon --pidfile $PROCESSID /usr/local/bin/memcachedb -d -p $PORT -r -u $USER -H $DATADIR -P $PROCESSID  $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcachedb
}
stop () {
echo -n $"Stopping $prog: "
killproc -p $PROCESSID /usr/local/bin/memcachedb
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcachedb
rm -f $PROCESSID
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status /usr/local/bin/memcachedb
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/memcachedb ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $?

同时提供在/etc/sysconfig/下的配置文件memcachedb

PORT="22222"

USER="root"

OPTIONS=""

DATADIR="/var/mcdb_data"

PROCESSID="/var/run/memcachedb/memcachedb.pid"


编译了一个32位的memcachedb RPM包,以供同好参考。