centos7安装memcached及配置等

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是否自启动成功

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值