linux下配置使用memcache功能,比win下稍微复杂一点,主要包括:安装libevent函数库、安装memcached、配置php扩展。
一、安装libevent函数库
libevent各版本地址:http://libevent.org/old-releases.html
在此我安装当前最稳定版本:libevent-2.0.21
1.下载:#wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
2.解压:#tar -zxvf libevent-2.0.21-stable.tar.gz
3 配置及编译安装:
#cd ibevent-2.0.21-stable
#./configure --prefix=/usr/local/libevent-2.0.21-stable
#make
#make install
- (我安装到了/usr/local/libevent-2.0.21-stable/下)
4.检查是否安装成功:
#ls -al /usr/local/libevent-2.0.21-stable/lib | grep libevent
二、安装memcached
memcached各版本下载地址:https://github.com/memcached/memcached/wiki/ReleaseNotes
在此我安装当前最稳定版本: memcache-1.5.9
1.下载:#wget http://memcached.org/files/memcached-
1.5.9.tar.gz
2.解压:#tar -zxvf memcached-
1.5.9.tar.gz
3. 配置及编译安装:
#cd memcached-1.4.32
#./configure -with-libevent=/usr/local/libevent-2.0.21-stable/ --prefix=/usr/local/memcached-1.5.9
#make
#make install
(同样安装到了/usr/local/memcached-1.5.9/下)
4.查看是否安装成功:
5.安装成功后启动一下看安装是否成功
# /usr/local/memcached-1.5.9/bin/memcached -d -m 1028 -p 11211 -u root
# ps -ef|grep memcached
6、配置开机自启动
# vim /etc/init.d/memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# Source function library.
. /etc/rc.d/init.d/functions
PORT=11211
USER=nobody
MAXCONN=1024
CACHESIZE=64
OPTIONS=""
if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi
# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
chown $USER /usr/local/java/memcached-1.5.9
daemon /usr/local/java/memcached-1.5.9/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /usr/local/java/memcached-1.5.9/memcached.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /usr/local/java/memcached-1.5.9/memcached.pid
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload)
restart
;;
condrestart)
[ -f /usr/local/java/memcached-1.5.9 ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
exit 1
esac
exit $?
并通过chmod命令赋予权限执行命令:chmod 755 /etc/init.d/memcached
将memcached加入系统服务
执行命令:
# chkconfig --add memcached
# chkconfig memcached on
启动memcached服务
执行命令:
# service memcached start
通过命令 ps -ef|grep memcached 查看memcached服务是否启动成功,如果没有成功,检查脚本里的memcached目录是否正确,或者memcached是否安装完整。
reboot重启linux ,然后再用ps命令查看memcached是否自启动成功