Linux下安装memcached

http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
http://pecl.php.net/get/memcache-2.2.5.tgz
需要先安装好LMAP环境,详情请见
http://hi.baidu.com/hx10/blog/item/51fe0efaa16c729a59ee9016.html
tar -zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure -prefix=/usr/local/libevent/
make && make install
测试libevent是否安装成功
ls -al /usr/lib | grep libevent
lrwxrwxrwx   1 root root       21 Jun 23 09:22 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
-rwxr-xr-x   1 root root   104804 Dec 16  2009 libevent-1.4.so.2.1.3
lrwxrwxrwx   1 root root       26 Jun 23 09:22 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3
-rwxr-xr-x   1 root root    34820 Dec 16  2009 libevent_core-1.4.so.2.1.3
lrwxrwxrwx   1 root root       27 Jun 23 09:22 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3
-rwxr-xr-x   1 root root    84180 Dec 16  2009 libevent_extra-1.4.so.2.1.3
说明安装成功。
tar -zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure -with-libevent=/usr/local/libevent/
make && make install
测试是否成功安装memcached
ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 202049 Jun 24 10:21 /usr/local/bin/memcached
安装Memcache的PHP扩展
tar -zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025

./configure -enable-memcache -with-php-config=/usr/bin/php-config -with-zlib-dir
make && make install
上述安装完后会有类似这样的提示
Installing shared extensions:     /usr/lib/php/modules/
修改/etc/php.ini
extension_dir = "/usr/lib/php/modules"
确定这里是这个路径
同时添加一行
extension=memcache.so
启动Memcache的服务器端
/usr/local/bin/memcached -d -m 10 -u root -l 10.80.11.207 -p 12000 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.22.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
如果要结束Memcache进程
 kill cat /tmp/memcached.pid`
 
最后,重启apache,service httpd restart
vim /var/www/html/index.php
<?php
$mem = new Memcache;
$mem->connect("10.80.11.207", 12000 );
$mem->set('key','This is a test!', 0,60);
$val = $mem->get('key');
echo $val;
?>
如果有输出This is a test!,就表示环境搭建成功

你可能感兴趣的:(linux,职场,memcached,休闲)