memcached高缓存搭建

memcached高缓存搭建
搭建服务端和客户端,让服务端去链接客户端
web客户端:192.168.247.161
服务端:192.168.247.160

[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
[root@client ~]# 
[root@nginx ~]# hostnamectl set-hostname server
[root@nginx ~]# su
[root@server ~]# 

搭建服务端
部署libevent 事件通知库

[root@server ~]# mkdir /abc
mkdir: cannot create directory ‘/abc’: File exists
[root@server ~]# mount.cifs //192.168.254.10/linuxs /abc
Password for root@//192.168.254.10/linuxs:  
[root@server ~]# cd /abc
[root@server abc]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
[root@server abc]# tar zxvf memcached-1.5.6.tar.gz -C /opt
[root@server abc]# cd /opt
[root@server opt]# ls
data  libevent-2.1.8-stable  memcached-1.5.6  nginx-1.12.2  rh
[root@server opt]# cd libevent-2.1.8-stable/
[root@server libevent-2.1.8-stable]# yum install gcc gcc-c++ make -y
[root@server libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent
[root@server libevent-2.1.8-stable]# make && make install

libevent安装完毕,接下来安装memcached

[root@server libevent-2.1.8-stable]# cd /opt/memcached-1.5.6/
[root@server memcached-1.5.6]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[root@server memcached-1.5.6]# make && make install
[root@server memcached-1.5.6]# ln -s /usr/local/memcached/bin/* /usr/local/bin/

命令注释:

  • -d 指定守护进程
  • -m 32m 指定缓存32兆
  • -p 11211 指定端口
  • -u root 指定用户管理
    [root@server memcached-1.5.6]# memcached -d -m 32m -p 11211 -u root
    [root@server memcached-1.5.6]# netstat -natp | grep memc
    tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      115996/memcached    
    tcp6       0      0 :::11211                :::*                    LISTEN      115996/memcached    
    [root@server memcached-1.5.6]# systemctl stop firewalld
    [root@server memcached-1.5.6]# setenforce 0

    先在本地连接这个缓存数据库,看看是否可以正常连接

    [root@server memcached-1.5.6]# yum install telnet -y
    [root@server memcached-1.5.6]# telnet 127.0.0.1 11211
    Trying 127.0.0.1...
    Connected to 127.0.0.1.
    Escape character is '^]'.

    add 添加
    键值名称 username
    0 代表不设置序列号
    0 无时间要求,不设置过期时间
    7 字节长度,接下来如果输入的字节长度不符合要求,就会报错

    add username 0 0 7
    1234567
    STORED
    add users 0 0 7
    123
    STORED
    ERROR

    查看输入的键值

    get username
    VALUE username 0 7
    1234567
    END

    value 后面的1 是更新因子,如果更新一次,就会自加一

    gets username
    VALUE username 0 7 1
    1234567
    END
    set username 0 0 8
    12345678
    STORED
    gets username
    VALUE username 0 8 3
    12345678
    END

    replace 是更新的意思,如果当前的键值名称不存在,就会更新失败
    set 也是更新的意思,如果当前的键值名称不存在,会新建一个键值

    replace school 0 0 2
    NOT_STORED
    get school
    END
    replace username 0 0 9
    123456789
    STORED
    gets username
    VALUE username 0 9 4
    123456789
    END

    cas 更新,依据更新因子进行更新,相同则更新

    cas username 0 0 7 4
    1234567
    STORED
    gets username
    VALUE username 0 7 5
    1234567
    END
    cas username 0 0 8 2
    12345678
    EXISTS
    gets username
    VALUE username 0 7 5
    1234567
    END

    键值后追加数据

    append username 0 0 4
    appe
    STORED
    get username
    VALUE username 0 11
    1234567appe
    END

    键值前追加数据

    prepend username 0 0 5
    prepe
    STORED
    get username
    VALUE username 0 16
    prepe1234567appe
    END

    删除键值

    delete username
    DELETED
    get username
    END

    stats 显示状态信息
    清除所有缓存数据 flush_all

    flush_all
    OK
    get users
    END

    退出:quit

    quit
    Connection closed by foreign host.
    [root@server memcached-1.5.6]# 

    下一步安装客户端,安装客户端首先要部署LAMP架构环境,LAMP架构部署详细过程可查看博客:https://blog.51cto.com/14557905/2458323

LAMP安装完毕,接下来安装memcacahe客户端

[root@client abc]# yum install autoconf -y
[root@client htdocs]# cd /abc
[root@client abc]# tar zxvf memcache-2.2.7.tgz -C /opt
[root@client abc]# cd /opt
[root@client opt]# ls
httpd-2.4.29  memcache-2.2.7  mysql-5.6.26  package.xml  php-5.6.11  rh
[root@client opt]# cd memcache-2.2.7/
[root@client memcache-2.2.7]# ls
config9.m4  example.php                 memcache.php        memcache_standard_hash.c
config.m4   memcache.c                  memcache_queue.c    php_memcache.h
config.w32  memcache_consistent_hash.c  memcache_queue.h    README
CREDITS     memcache.dsp                memcache_session.c
[root@client memcache-2.2.7]# 
[root@client memcache-2.2.7]# /usr/local/php5/bin/phpize
[root@client memcache-2.2.7]# ls
acinclude.m4    config.sub    Makefile.global             memcache_standard_hash.c
aclocal.m4      configure     memcache.c                  missing
autom4te.cache  configure.in  memcache_consistent_hash.c  mkinstalldirs
build           config.w32    memcache.dsp                php_memcache.h
config9.m4      CREDITS       memcache.php                README
config.guess    example.php   memcache_queue.c            run-tests.php
config.h.in     install-sh    memcache_queue.h
config.m4       ltmain.sh     memcache_session.c
[root@client memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config
[root@client memcache-2.2.7]# make && make install
[root@client memcache-2.2.7]# vim /usr/local/php5/php.ini 
 736 ; extension_dir = "ext"
 737 extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"      #增加
 738 extension = memcache.so    #增加

在web客户端去检测服务端是否可以连接

[root@client memcache-2.2.7]# cd /usr/local/httpd/htdocs/
[root@client htdocs]# ls
index.php
[root@client htdocs]# vim gsy.php
<?php
$memcache = new Memcache();
$memcache->connect('192.168.247.160',11211);
$memcache->set('key','Memcache test Successfull',0,60);
$result = $memcache->get('key');
unset($memcache);
echo $result;
?>
[root@client htdocs]# service httpd restart

接下来就可以在浏览器上查看了

原文地址:https://blog.51cto.com/14557905/2480791

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


前言设计一个缓存系统,不得不要考虑的问题就是:缓存穿透、缓存击穿与失效时的雪崩效应。缓存穿透缓存穿透是指查询一个一定不存在的数据,由于缓存是不命中时被动写的,并且出于容错考虑,如果从存储层查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到存储层去查询,失
在192.168.80.100要联网关闭防火墙及SElinuxsystemctlstopfirewalld//关闭防火墙setenforce0//关闭监控memcached服务器:上传源码包和插件包:yuminstalllrz*-y把memcached-1.5.6.tar.gzlibevent-2.1.8-stable.tar.gz软件包拉入
Redis与Memcache对比:1.Memcache是一个分布式的内存对象缓存系统而redis是可以实现持久存储2.Memcache是一个LRU的缓存redis支持更多的数据类型3.Memcache是多线程的redis是单线程的4.二者性能几乎不相上下,实际上redis会受到硬盘持久化的影响,但是性能仍然保持在与Memcache不相上下,
安装Mencache:关闭防火墙及SElinuxsystemctl  stop  firewalldsetenforce  0memcached服务器:上传源码包和插件包:yum install  lrz*  -ymemcached-1.5.9.tar.gzlibevent-2.1.8-stable.tar.gz解压tarxfmemcached-1.5.6.tar.gz-C/optarxflibevent-2.1.8-stabl
#安装php的yaf模块,参考https://www.cnblogs.com/shifu204/p/6743578.htmlhttps://www.cnblogs.com/jiqing9006/p/9646872.htmlCentOS用phpize安装PHP扩展出现Can'tfindPHPheadersin/usr/include/php原因:https://wangzq-phper.iteye.com/blog/2297792#php的memcache的
win10下安装配置apache、php、mysql、redis、memcache资源官网下载亲测可用。名称版本下载地址网盘提取码apache2.4.38-x64下载地址33h4mysql5.5.62下载地址zicrphp7.1.26-ts-x64下载地址6ar6redis4.0.2.3-x64下载地址bnpkmemcache1.4.
使用理由:就是为了频繁查询数据库。并且数据有多!那么存到memcached内存就能够避免数据库的不断被訪问,从而提速一、安装memcachememcached在windows7上的安装问题 如今安装包:http://download.csdn.net/detail/qq1355541448/7587663或者 http://www.jb51.net/softs/448
https://www.cnblogs.com/xrq730/p/4948707.htmlMemCache是什么理解memcached的内存存储机制SlabAllocator内存分配机制Memcached默认情况下采用了名为SlabAllocator的机制分配、管理内存。0.之前内存分配的弊端在该机制出现以前,内存的分配是通过对所有记录简单地进行malloc和
 转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10923221.html 一:Memcache是什么,为什么要用它 二:Memcache指令有哪些 三:Memcache使用实例 四:Memcache深入解读
memcache讲解和在.net中初使用2017年10月17日22:51:36 等待临界 阅读数:503  前言传统数据库面临的问题数据库死锁磁盘IO正文了解memcache原理基本命令memcache与memcachedmemcache的适用范围memcache的客户端和服务端memcache与redis异同
前言设计一个缓存系统,不得不要考虑的问题就是:缓存穿透、缓存击穿与失效时的雪崩效应。缓存穿透缓存穿透是指查询一个一定不存在的数据,由于缓存是不命中时被动写的,并且出于容错考虑,如果从存储层查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到存储层去查询,失
一、概念讲解1.memcache是一个高性能的分布式的内存对象缓存系统,用于动态web应用以减轻数据库负担2.memcache通过在内存里维护一个统一的巨大的hash表,来存储经常被读写的一些数组与文件,从而极大的提高网站的运行效率。3.memcache是一种内存缓存技术,是一种缓存手段,要看情况
前戏Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象减少读取数据库的次数,从而减小数据库的压力,提高动态,数据库网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程是用C编写的,但是客户端可以用任
一.配置环境1.安装jdk和tomcat并将其放至/usr/local目录下[root@server1~]#ls[root@server1~]#tarzxfjdk-7u79-linux-x64.tar.gz-C/usr/local[root@server1~]#tarzxfapache-tomcat-7.0.37.tar.gz-C/usr/local2.为了升级的时候只升级软链接,所以对jdk和tom
一、    缓存系统静态web页面:1、在静态Web程序中,客户端使用Web浏览器(IE、FireFox等)经过网络(Network)连接到服务器上,使用HTTP协议发起一个请求(Request),告诉服务器我现在需要得到哪个页面,所有的请求交给Web服务器,之后WEB服务器根据用户的需要,从文件系统(存放了所有静态页面
session//php文件中ini_set("session.save_handler","memcache");ini_set("session.save_path","tcp://127.0.0.1:11211");session_start();$_SESSION['TEST']='AreyouOK?';echosession_id();不建议在php.
废话少说,直接上代码<?php//实例化memcache类$mem=newmemcache();//连接memcache$mem->connect('localhost','11211');/**判断缓存中是否有数据如果有,就读取,没有,在查询时候,就把查询的数据存入memcache中*///获取缓存数据$
一、概念1、什么是memcacheMemcached是一个自由开源的,高性能,分布式内存对象缓存系统Memcached是以LiveJournal旗下DangaInteractive公司的BradFitzpatric为首开发的一款软件。现在已成为mixi、hatena、Facebook、Vox、LiveJournal等众多服务中提高Web应用扩展性的重要
关于Redis和Memcache在应用中,都可以实现缓存的功能,但是,具体使用情况需要根据具体业务场景,尤其是对缓存数据有特性要求时,需要选择对应的缓存机制。共同点:都是基于内存的数据库,可用作缓存机制区别:1、关于数据类型:Memcache只支持简单的Key/Value数据结构;Redis支持的数据结构相
ThedefaultcachegroupisloadedbasedontheCache::$defaultsetting.Itissettothefiledriverasstandard,howeverthiscanbechangedwithinthe/application/boostrap.phpfile//ChangethedefaultcachedrivertomemcacheCache::$default='me