|
Memcached linux安装说明,参照网上例子,网上内容基本是32位机子的(用 getconf LONG_BIT 来查看机子多少位)
下载libevent、memcached
wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
准备安装:需要先安装gcc,libevent
Code
#yum install gcc
#wget http://monkey.org/~provos/libevent-1.4.4-stable.tar.gz
#tar xvzf libevent-1.4.4-stable.tar.gz
#cd libevent-1.4.4-stable
#./configure -prefix=/usr/local/libevent
#make
#make install
编译安装:
./configure -prefix=/usr/local/memcached -build=i686-pc-linux-gnu -with-libevent=/usr/local/libevent make make install
启动:
$ /usr/local/memcached/bin/memcached -p 11211 -m 64m -d -u root
Code
使用memcached -h可以查看所有可用选项:
选项 说明-p 使用的TCP端口。默认为11211
-m 最大内存大小。默认为64M
-vv 用very vrebose模式启动,调试信息和错误输出到控制台
-d 作为daemon在后台启动
-u 运行Memcache的用户,默认不能用root启动,所以当前用户为root用户时,需要用-u参数来指定。
-l 监听的服务器的ip
-c 最大并发连接数,默认为1024
-P 指定pid文件
常见问题:
1. 编译memcached时出现下面错误:
./configure checking build system type… Invalid configuration `i686-pc-linux-’: machine `i686-pc-linux‘ not recognized configure: error: /bin/sh ./config.sub i686-pc-linux- failed
解决方法:
在./configure 时加入参数–build=i686-pc-linux-gnu
2.启动时找不到libevent库
memcached: error while loading shared libraries: libevent-1.3c.so.1: cannot open shared object file: No such file or directory
解决办法1:将libevent库所在路径加入LIBRARY_PATH,在/etc/profile中加入
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/libevent/lib 解决办法2:
ln -s /libevent安装路径/libevent/lib/libevent-1.3b.so.1 /usr/lib/libevent-1.3c.so.1 启动服务 :
./memcached -d -m 10 -u root -l 192.168.40.4 -p 12000 -c 256 -P /tmp/memcached.pid
启动脚本编写:
#/bin/sh
#memcached
mem_bin=/usr/local/memcached/bin
$mem_bin/memcached -d -u root -m 80 -l 192.168.26.26 -p 11211 -P memcached.pid
安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
2.安装PHP的memcache扩展
#tar vxzf memcache-2.2.1.tgz
#cd memcache-2.2.1
#/usr/local/php/bin/phpize
#./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
#make
#make install 3.上述安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/
4.把php.ini中的extension_dir = “./”修改为
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
5.添加一行来载入memcache扩展:extension=memcache.so
|
|
|
|
|
|
|