Memcache的安装
1.分别下载memcached 和libevent
Wget http://memcached.org/files/memcached-1.4.25.tar.gz
wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
2. 先安装libevent :
# tar zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure --prefix=/usr
# make
# make install
3.测试libevent 是否安装成功
ls -al /usr/lib |grep libevent
4.安装memcached ,同时需要安装中指定libevent 的安装位置:
# tar zxvf memcached-1.2.0.tar.gz
# cd memcached-1.2.0
# ./configure --with-libevent=/usr
# make
# make install
5. 测试是否成功安装memcached :
# ls -al /usr/local/bin/mem*
6.启动memcached
/usr/local/bin/memcached -d -m 10 -u memcache -p 11211 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache 使用的内存数量,单位是MB
-u是运行Memcache 的用户,我这里是root ,
-l是监听的服务器IP 地址
-p是设置Memcache 监听的端口,最好是1024 以上的端口,
-c选项是最大运行的并发连接数,默认是1024 ,按照你服务器的负载量来设定,
-P是设置保存Memcache 的pid 文件
测试:
#Telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
#set test 0 0 10
#test_value
STORED
#get test
VALUE test 0 10
test_value
END
#quit
Connection closed by foreign host.
7.关闭memcached
kill `cat /tmp/memcached.pid`
安装memcache 的php 扩展
1.下载memcache:
wget http://pecl.php.net/get/memcache-2.2.7.tgz
2.安装PHP 的memcache 扩展
tar vxzf memcache-2.2. 7.tgz
cd memcache-2.2. 7
/usr/local/php/bin/phpize (yum 安装的php 执行/usr/bin/phpize )
./configure – enable-memcache -- with-php-config=/usr/local/php/bin/php-config -- with-zlib-dir (yum 安装的php 执行 ./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir)
make
make install
若没有phpize 命令 yum install php-devel
3.上述安装完后会有类似这样的提示:
Installing shared extensions: /usr/lib64/php/modules/
4.修改/etc/php.ini
extension_dir = "/usr/lib64/php/modules/"
extension=memcache.so
5.重新启动apache ,启动memcached
service httpd restart
运行下面的php 文件,如果有输出 hello world!,表示环境搭建成功
<?php
$mem = new Memcache;
$mem->connect('127.0.0.1',11211);
$mem->set('test','hello world!',0,10);
$val = $mem->get('test');
echo $val;
?>
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com