本文共 5803 字,大约阅读时间需要 19 分钟。
Memcached时一台开源的高性能分布式内存对象缓存系统,他将所有的数据都存储在内存中,因为在内存中会同意维护一张巨大而Hash表,所以支持任意存储类型的数据
1.1安装Libevent
Libevent是一款跨平台的事件处理接口的封装,可以兼容多个操作系统的事件访问。Memcached的安装依赖于Libevent,因此需要先完成Libevent的安装。
挂载源代码包
[root@localhost ~]# mount.cifs //192.168.32.1/gongxiang /abc/Password for root@//192.168.32.1/gongxiang: [root@localhost ~]# cd /abc/[root@localhost abc]# lsall_locales-1.4.18-20090526.tar.gz magent-0.5.tar.gzapachenk memcache-2.2.7.tgzapache.sh memcached-1.5.6.tar.gzapr-1.4.6.tar.gz mongodb-linux-x86_64-rhel70-4.0.0.tgzapr-1.5.0.tar.gz mysqlapr-util-1.4.1.tar.gz mysql-5.5.24.tar.gzapr-util-1.5.4.tar.gz nginx-1.15.0.tar.gzawstats-7.0.zip nginx-1.2.8.tar.gzawstats-7.6.tar.gz nginx-1.6.0.tar.gzdage.jpg openssl-1.0.1c.tar.gzdage.jpg.jpg pcre-8.39.tar.gzdesktop.ini phpDiscuz_X2.5_SC_UTF8.zip php-5.4.5.tar.bz2dnf-dnf-1.1.7-1.tar.gz pxe.sh.txtepel-release-latest-7.noarch.rpm Red Hat Enterprise 6.5 x86_64.isogame.jpg rhel-server-7.3-x86_64-dvd.isogd-2.0.35.tar.gz sarg-2.3.7.tar.gzhping-2.0.0-1.rc3.2.el6.rf.i686.rpm shell.sh.txthttpd-2.4.2.tar.gz snmpd.conf.txthttpd-2.4.33.tar.gz squid-4.1.tar.gzinotify-tools-3.14.tar.gz squirrelmail-webmail-1.4.22.tar.gzjohn-1.8.0.tar.gz xy.jpgjohn,mimapojie ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gzlibevent-2.1.8-stable.tar.gz ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gzLNMP
[root@localhost ~] tar xf libevent-2.1.8-stable.tar.gz -C /opt/[root@localhost libevent-2.1.8-stable] ./configure -prefix/-s/loca//ibeve[root@localhost libevent-2.1.8-stable] make && make install
1.2安装Memccached
采用源代码的方式进行Memcached的编译安装,安装时指定Libevent的安装路径[root@localhost ~] tar xf memcached-1.5.6.tar.gz -C /opt/[root@localhost libevent-2.1.8-stable]# cd /opt/memcached-1.5.6/[root@localhost memcached-1.5.6]# ./configure \> --prefix=/usr/local/memcached \> --with-libevent=/usr/local/libevent/[root@localhost ~] make && make install#将Memcached自带的命令建立一个软连接让系统能够识别[root@localhost memcached-1.5.6] ln -s /usr/local/memcached/bin/* /usr/local/bin/#其中启动Memcached时,-d选项的作用是以守护进程的方式运行Memcached服务;-m是为Memcached分配为32MB的内存,应根据企业需要进行调整: -u 指定运行的用户账号[root@localhost memcached-1.5.6] memcached -d -m 32m -p 11211 -u root
查看端口进程有没有开启
[root@localhost memcached-1.5.6] netstat -ntap | grep memctcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 21394/memcached tcp6 0 0 :::11211 :::* LISTEN 21394/memcached #关闭防火墙[root@localhost ~] systemctl stop firewalld.service[root@localhost ~] setenforce 0
2.1 Memcached API客户端
为了使得程序可以直接调用Memcached库和接口,
可以使用Memcached扩展组件将Memcached添加为PHP的一个模块。此扩展使用了Libmemcached库提供的API与Memcached服务端进行交互安装autoconf
[root@localhost ~]# yum install autoconf -y
解压Memcache安装包
[root@localhost ~]# tar zxvf /abc/memcache-2.2.7.tgz -C /opt/package.xmlmemcache-2.2.7/config.m4memcache-2.2.7/config9.m4memcache-2.2.7/config.w32memcache-2.2.7/CREDITSmemcache-2.2.7/example.phpmemcache-2.2.7/memcache.cmemcache-2.2.7/memcache_queue.cmemcache-2.2.7/memcache_session.cmemcache-2.2.7/memcache_standard_hash.cmemcache-2.2.7/memcache_consistent_hash.cmemcache-2.2.7/memcache.dspmemcache-2.2.7/php_memcache.hmemcache-2.2.7/memcache_queue.hmemcache-2.2.7/READMEmemcache-2.2.7/memcache.php#进入Memcache文件[root@localhost ~] cd /opt/memcache-2.2.7/#我们想编译安装的话要用到configure但是Memcache客户端文件里面没有configure配置文件所以就要用到php里面的configure配置模块[root@localhost memcache-2.2.7] lsacinclude.m4 config.h.in CREDITS memcache_consistent_hash.c memcache_standard_hash.caclocal.m4 config.m4 example.php memcache.dsp missingautom4te.cache config.sub install-sh memcache.php mkinstalldirsbuild configure ltmain.sh memcache_queue.c php_memcache.hconfig9.m4 configure.in Makefile.global memcache_queue.h README#直接运行php里面bin文件里面phpize配置[root@localhost memcache-2.2.7]# /usr/local/php/bin/phpize Configuring for:PHP Api Version: 20121113Zend Module Api No: 20121212Zend Extension Api No: 220121212[root@localhost memcache-2.2.7]# lsacinclude.m4 config.h.in CREDITS memcache_consistent_hash.c memcache_standard_hash.caclocal.m4 config.m4 example.php memcache.dsp missingautom4te.cache config.sub install-sh memcache.php mkinstalldirsbuild configure ltmain.sh memcache_queue.c php_memcache.hconfig9.m4 configure.in Makefile.global memcache_queue.h READMEconfig.guess config.w32 memcache.c memcache_session.c run-tests.php#再编译运行configure[root@localhost memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config[root@localhost memcache-2.2.7]# make && make installInstalling shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/#make install运行后会有一段路径显示出来如上记住如上的路径
进入php底下php.ini配置文件,搜索并修改下面一行,再新增一行(如果没有就在解压包下执行cp php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/)
图
用客户端连接测试
vi /usr/local/httpd/htdocs/index.php //编写测试页面,测试memcached工作是否正常 connect('192.168.175.128',11211);$memcache->set('key','Memcache test Successfull!',0,60);$result = $memcache->get('key');unset($memcache);echo $result;?>
//输入客户端地址测试是否成功
转载于:https://blog.51cto.com/13645280/2152415