ddxiami

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2415|回复: 0

[web服务] memcached-1.4.15编译安装

[复制链接]
发表于 2013-5-22 16:28:26 | 显示全部楼层 |阅读模式
#基于PHP的基础环境已配置
#安装libevent
tar zxvf libevent-1.4.14-stable.tar.gz
cd libevent-1.4.14-stable
./configure --prefix=/usr
make && make install

#针对64位系统
ln -s /usr/lib64/libevent-1.4.so.1 /usr/lib64/

#安装memcached,同时需要安装中指定libevent的安装位置
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --with-libevent=/usr
make && make install

#建立memcache守护进程
vi /etc/init.d/memcache
==========================================================================
#!/bin/sh
#
# Startup script for the server of memcached
#
# processname: memcached
# pidfile: /etc/memcached/memcached.pid
# logfile: /etc/memcached/memcached_log.txt
# memcached_home: /etc/memcached
# chkconfig: 35 21 79
# description: Start and stop memcached Service

# Source function library
. /etc/rc.d/init.d/functions

RETVAL=0

prog="memcached"
basedir=/usr/local
cmd=${basedir}/bin/memcached
pidfile="$basedir/${prog}.pid"
#logfile="$basedir/memcached_log.txt"

# 设置memcached启动参数
ipaddr="127.0.0.1"               # 绑定侦听的IP地址
port="12000"                    # 服务端口
username="root"                 # 运行程序的用户身份
max_memory=512                   # default: 64M | 最大使用内存
max_simul_conn=30000             # default: 1024 | 最大同时连接数
#maxcon=51200
#growth_factor=1.3              # default: 1.25 | 块大小增长因子
#thread_num=6                   # default: 4
#verbose="-vv"                  # 查看详细启动信息
#bind_protocol=binary           # ascii, binary, or auto (default)

start() {
    echo -n $"Starting service: $prog"
    $cmd -d -m $max_memory -u $username -l $ipaddr -p $port -c $max_simul_conn -P $pidfile
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}

stop() {
    echo -n $"Stopping service: $prog  "
    run_user=`whoami`
        pidlist=`ps -ef | grep $run_user | grep memcached | grep -v grep | awk '{print($2)}'`
        for pid in $pidlist
        do
#           echo "pid=$pid"
            kill -9 $pid
            if [ $? -ne 0 ]; then
                return 1
            fi
        done
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    reload)
        reload
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
        fi
        ;;
    status)
        status memcached
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL
==========================================================================

#设置成开机启动
chmod +x /etc/init.d/memcache
chkconfig --level 3 memcache on

#设置成开机启动
cat $cur_dir/memcache > /etc/init.d/memcache
chmod +x /etc/init.d/memcache
chkconfig --level 3 memcache on

#重启memcache服务
service memcache restart

#安装Memcache的PHP扩展
tar vxzf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
make && make install

#修改php.ini文件,添加memcache.so
cat >> /usr/local/php/etc/php.ini << "EOF"

[memcached]
extension=memcache.so
EOF

#重启php-fpm
service php-fpm restart


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|技术文档库 ( 闽ICP备15017263号-2 )|网站地图

GMT+8, 2025-5-18 22:17 , Processed in 0.034449 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表