linux下安装memcache及memcache的php扩展
http://hellosa.blog.51cto.com/2698675/503371
一、构建memcached 服务器(memcached服务端程序的安装)
1)memcached用到了libevent这个库,用于Socket的处理
- wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz
- tar xzvf libevent-2.0.10-stable.tar.gz
- cd libevent-2.0.10-stable
- ./configure --prefix=/usr
- make && make install
验证libevent是否正确安装
- ls -al /usr/lib |grep libevent
- [root@test /]# ls -al /usr/lib |grep libevent
- lrwxrwxrwx 1 root root 21 Feb 28 19:27 libevent-2.0.so.5 -> libevent-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 943520 Feb 28 19:27 libevent-2.0.so.5.0.1
- -rw-r--r-- 1 root root 1532202 Feb 28 19:27 libevent.a
- lrwxrwxrwx 1 root root 26 Feb 28 19:27 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 554374 Feb 28 19:27 libevent_core-2.0.so.5.0.1
- -rw-r--r-- 1 root root 928010 Feb 28 19:27 libevent_core.a
- -rwxr-xr-x 1 root root 971 Feb 28 19:27 libevent_core.la
- lrwxrwxrwx 1 root root 26 Feb 28 19:27 libevent_core.so -> libevent_core-2.0.so.5.0.1
- lrwxrwxrwx 1 root root 27 Feb 28 19:27 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 410763 Feb 28 19:27 libevent_extra-2.0.so.5.0.1
- -rw-r--r-- 1 root root 604266 Feb 28 19:27 libevent_extra.a
- -rwxr-xr-x 1 root root 978 Feb 28 19:27 libevent_extra.la
- lrwxrwxrwx 1 root root 27 Feb 28 19:27 libevent_extra.so -> libevent_extra-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 936 Feb 28 19:27 libevent.la
- lrwxrwxrwx 1 root root 29 Feb 28 19:27 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 85731 Feb 28 19:27 libevent_openssl-2.0.so.5.0.1
- -rw-r--r-- 1 root root 120996 Feb 28 19:27 libevent_openssl.a
- -rwxr-xr-x 1 root root 1007 Feb 28 19:27 libevent_openssl.la
- lrwxrwxrwx 1 root root 29 Feb 28 19:27 libevent_openssl.so -> libevent_openssl-2.0.so.5.0.1
- lrwxrwxrwx 1 root root 30 Feb 28 19:27 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.0.1
- -rwxr-xr-x 1 root root 18094 Feb 28 19:27 libevent_pthreads-2.0.so.5.0.1
- -rw-r--r-- 1 root root 18678 Feb 28 19:27 libevent_pthreads.a
- -rwxr-xr-x 1 root root 999 Feb 28 19:27 libevent_pthreads.la
- lrwxrwxrwx 1 root root 30 Feb 28 19:27 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.0.1
- lrwxrwxrwx 1 root root 21 Feb 28 19:27 libevent.so -> libevent-2.0.so.5.0.1
2)安装memcached
- wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
- tar xzvf memcached-1.4.5.tar.gz
- cd memcached-1.4.5
- ./configure -–with-libevent=/usr
- make && make install
安装完成后,程序会将memcached 自动放到 /usr/local/bin/memcached
- [root@test /]# which memcached
- /usr/local/bin/memcached
3)安装PHP的memcache扩展
memcache 的项目下载地址
- http://pecl.php.net/package/memcache
安装code
- wget http://pecl.php.net/get/memcache-3.0.5.tgz
- tar xf memcache-3.0.5.tgz
- cd memcache-3.0.5
- /usr/local/php/bin/phpize //执行phpize扩展安装程序,假设phpzie的路径为/usr/local/php/bin/phpize,具体的路径得根据自己的环境修改。
- ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
- make && make install
安装完成后,提示
- Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
配置php.ini文件
修改extension_dir:
- extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
添加一行以便加载memcache扩展:extension=memcache.so
- extension=memcache.so
重启服务器即可
启动memcached 服务端程序:
- memcached -d -m 10 -u root -l localhost -p 11211 -c 256
各个参数的含义:
- -d选项是启动一个守护进程,
- -m是分配给Memcached使用的内存数量,单位是MB,
- -u是运行Memcache的用户,我这里是root,
- -l是监听的服务器IP地址,
- -p是设置Memcache监听的端口,最好是1024以上的端口,
- -c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定,
- -P是设置保存Memcache的pid文件
posted on 2013-01-08 17:56 zhanghw0354 阅读(159) 评论(0) 编辑 收藏 举报