Centos 下编译安装Memcache

网友投稿 697 2023-03-15

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

Centos 下编译安装Memcache

安装环境说明:

操作系统:Centos 6.5 -64bit

安装路径:/usr/local/memcached

开始编译memcached

安装编译需要的扩展包

yum install libevent libevent-devel

yum install libevent libevent-devel

开始编译memcached

tar -zxvf memcached-1.4.21.tar.gzcd memcached-1.4.21./configure --prefix=/usr/local/memcachedmakemake install

tar -zxvf memcached-1.4.21.tar.gzcd memcached-1.4.21./configure --prefix=/usr/local/memcachedmakemake install

安装PHP memcache 扩展包

tar -zxvf memcache-2.2.7.tgzcd memcache-2.2.7/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config make make install# 安装成功后会输出这个地址,这是php扩展模块文件夹/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ 

tar -zxvf memcache-2.2.7.tgzcd memcache-2.2.7/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config make make install# 安装成功后会输出这个地址,这是php扩展模块文件夹/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

创建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 - for other linux#. /etc/rc.d/init.d/functions# Source function library - for suse linux. /lib/lsb/init-functionsip="192.168.25.129"             # 绑定侦听的IP地址port="11211"                    # 服务端口username="root"                 # 运行程序的用户身份max_memory=64                   # default: 64M | 最大使用内存max_connection=1024             # default: 1024 | 最大同时连接数if [ -f /etc/sysconfig/memcached ];then  . /etc/sysconfig/memcachedfi# Check that networking is up.if [ "$NETWORKING" = "no" ]then  exit 0fiRETVAL=0prog="memcached"pidfile=/tmp/memcached.pidbasedir=/usr/local/memcachedcmd=${basedir}/bin/memcachedstart () {  echo -n $"Starting service:$prog "  chown $username $basedir  $cmd -d -p $port -u $username  -m $max_memory -c $max_connection -P $pidfile $OPTIONS  RETVAL=$?  echo  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached  return $retval}stop() {    echo -n $"Stopping service: $prog  "    current_user=$(whoami)    pidlist=$(ps -ef | grep $current_user | grep memcached | grep -v grep | awk '{print $2}')    for pid in $pidlist ; do        kill -9 $pid        if [ $? -ne 0 ]; then           return 1        fi    done    RETVAL=$?    echo    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/memcached}restart () {  stop  start}# See how we were called.case "$1" in  start)  start  ;;  stop)  stop  ;;  status)  status memcached  ;;  restart|reload)  restart  ;;  condrestart)  [ -f /var/lock/subsys/memcached ] && restart || :  ;;  *)  echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"  exit 1esacexit $?

#! /bin/sh## chkconfig: - 55 45# description: The memcached daemon is a network memory cache service.# processname: memcached# config: /etc/sysconfig/memcached# Source function library - for other linux#. /etc/rc.d/init.d/functions# Source function library - for suse linux. /lib/lsb/init-functionsip="192.168.25.129" # 绑定侦听的IP地址port="11211" # 服务端口username="root" # 运行程序的用户身份max_memory=64 # default: 64M | 最大使用内存max_connection=1024 # default: 1024 | 最大同时连接数if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcachedfi# Check that networking is up.if [ "$NETWORKING" = "no" ]then exit 0fiRETVAL=0prog="memcached"pidfile=/tmp/memcached.pidbasedir=/usr/local/memcachedcmd=${basedir}/bin/memcachedstart () { echo -n $"Starting service:$prog " chown $username $basedir $cmd -d -p $port -u $username -m $max_memory -c $max_connection -P $pidfile $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached return $retval}stop() { echo -n $"Stopping service: $prog " current_user=$(whoami) pidlist=$(ps -ef | grep $current_user | grep memcached | grep -v grep | awk '{print $2}') for pid in $pidlist ; do kill -9 $pid if [ $? -ne 0 ]; then return 1 fi done RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/memcached}restart () { stop start}# See how we were called.case "$1" in start) start ;; stop) stop ;; status) status memcached ;; restart|reload) restart ;; condrestart) [ -f /var/lock/subsys/memcached ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" exit 1esacexit $?

脚本配置

# 将此脚本cp到/etc/init.d目录下并改名为memcached,然后增加执行权限cp memcached /etc/init.d/memcachedchmod a+x /etc/init.d/memcached

# 将此脚本cp到/etc/init.d目录下并改名为memcached,然后增加执行权限cp memcached /etc/init.d/memcachedchmod a+x /etc/init.d/memcached

配置开启自启动

chkconfig --add memcached              # 增加开启启动chkconfig --level 2345 memcached on    # 设置启动级别

chkconfig --add memcached # 增加开启启动chkconfig --level 2345 memcached on # 设置启动级别

测试启动,停止,重启memcached

# 服务启动,停止service memcached startservice memcached stop# init.d目录启动,停止/etc/init.d/memcached start/etc/init.d/memcached stop

# 服务启动,停止service memcached startservice memcached stop# init.d目录启动,停止/etc/init.d/memcached start/etc/init.d/memcached stop

配置PHP支持memcached

编辑php.ini文件

vim /usr/local/php/etc/php.ini# 修改以下内容extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"# 增加扩展到phpextension = memcache.so

vim /usr/local/php/etc/php.ini# 修改以下内容extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"# 增加扩展到phpextension = memcache.so

重新启动php-fpm

/etc/init.d/php-fpm restart

/etc/init.d/php-fpm restart

在php测试下是否成功

<?php $memcache = new Memcache (); $memcache->connect('192.168.25.129', 11211);$memcache->set('key', 'test');echo $memcache->get('key');

connect('192.168.25.129', 11211);$memcache->set('key', 'test');echo $memcache->get('key');

结果截图( 成功输出了缓存值 ):

总结

到这里我们memcache缓存就编译安装完成了,memcache是很强大的缓存系统,加油吧...

上一篇:xcache 源码包编译安装
下一篇:aiops智能运维挑战赛(智能运维aiops厂商排名)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~