memcache+php扩展模块的安装

安装memcache
1、安装libevent
[root@localhost libevent-2.0.19-stable]#tar -zxvf libevent-2.0.19-stable.tar.gz
cd libevent-2.0.19-stable
[root@localhost libevent-2.0.19-stable]# ./configure --prefix=/usr
[root@localhost libevent-2.0.19-stable]#make
[root@localhost libevent-2.0.19-stable]#make install

2、测试libevent是否安装成功
[root@localhost libevent-2.0.19-stable]# ls /usr/lib |grep libevent
libevent-2.0.so.5
libevent-2.0.so.5.1.7
libevent.a
libevent_core-2.0.so.5
libevent_core-2.0.so.5.1.7
libevent_core.a
libevent_core.la
libevent_core.so
libevent_extra-2.0.so.5
libevent_extra-2.0.so.5.1.7
libevent_extra.a
libevent_extra.la
libevent_extra.so
libevent.la
libevent_openssl-2.0.so.5
libevent_openssl-2.0.so.5.1.7
libevent_openssl.a
libevent_openssl.la
libevent_openssl.so
libevent_pthreads-2.0.so.5
libevent_pthreads-2.0.so.5.1.7
libevent_pthreads.a
libevent_pthreads.la
libevent_pthreads.so
libevent.so

3、安装memcache
[root@localhost mem]# tar -zxvf memcached-1.2.2.tar.gz
[root@localhost mem]# cd memcached-1.2.2
[root@localhost memcached-1.2.2]# ./configure --with-libevent=/usr
[root@localhost memcached-1.2.2]# make
make  all-recursive
make[1]: Entering directory `/home/mem/memcached-1.2.2'
Making all in doc
make[2]: Entering directory `/home/mem/memcached-1.2.2/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/mem/memcached-1.2.2/doc'
make[2]: Entering directory `/home/mem/memcached-1.2.2'
if gcc -DHAVE_CONFIG_H -I. -I. -I.  -DNDEBUG -I/usr/include   -g -O2 -MT memcached-memcached.o -MD -MP -MF ".deps/memcached-memcached.Tpo" \
          -c -o memcached-memcached.o `test -f 'memcached.c' || echo './'`memcached.c; \
        then mv -f ".deps/memcached-memcached.Tpo" ".deps/memcached-memcached.Po"; \
        else rm -f ".deps/memcached-memcached.Tpo"; exit 1; \
        fi
memcached.c: In function ‘add_iov’:
memcached.c:582: error: ‘IOV_MAX’ undeclared (first use in this function)
memcached.c:582: error: (Each undeclared identifier is reported only once
memcached.c:582: error: for each function it appears in.)
make[2]: *** [memcached-memcached.o] Error 1
make[2]: Leaving directory `/home/mem/memcached-1.2.2'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/mem/memcached-1.2.2'
make: *** [all] Error 2

(make 时出错了)

-------------
解决方案:
[root@localhost memcached-1.2.2]# vim memcached.c

修改如下几行
56 /* FreeBSD 4.x doesn't have IOV_MAX exposed. */
  57 #ifndef IOV_MAX
  58 #if defined(__FreeBSD__)
  59 # define IOV_MAX 1024
  60 #endif
  61 #endif
改成
56 /* FreeBSD 4.x doesn't have IOV_MAX exposed. */
  57 #ifndef IOV_MAX
  58 /*#if defined(__FreeBSD__)*/
  59 # define IOV_MAX 1024
  60 /*#endif*/
------------
再次编译
[root@localhost memcached-1.2.2]# make
[root@localhost memcached-1.2.2]# make install

安装完成后会把memcached放到 /usr/local/bin/memcached

4、测试是否成功安装memcached:
[root@localhost memcached-1.2.2]# ls /usr/local/bin/mem*
/usr/local/bin/memcached  /usr/local/bin/memcached-debug


---------------------------------------------------

安装memcache的php扩展

安装libmemcached
[root@localhost mem]# tar -zxvf libmemcached-0.40.tar.gz
[root@localhost mem]# cd libmemcached-0.40
[root@localhost mem]# ./configure
[root@localhost mem]# make
[root@localhost mem]# make install

由于是64位cpu 32位的操作系统 memcached版本1.4.5
出现以下相关错误:
clients/ms_conn.o: In function `ms_get_udp_request_id':
/tmp/libmemcached-0.49/clients/ms_conn.c:194: undefined reference to `__sync_fetch_and_add_4'
clients/ms_conn.o: In function `ms_reconn_socks':
/tmp/libmemcached-0.49/clients/ms_conn.c:1051: undefined reference to `__sync_fetch_and_add_4'
clients/ms_conn.o: In function `ms_reconn':
/tmp/libmemcached-0.49/clients/ms_conn.c:919: undefined reference to `__sync_fetch_and_add_4'
/tmp/libmemcached-0.49/clients/ms_conn.c:956: undefined reference to `__sync_fetch_and_add_4'
clients/ms_thread.o: In function `ms_setup_thread':
/tmp/libmemcached-0.49/clients/ms_thread.c:225: undefined reference to `__sync_fetch_and_add_4'
clients/ms_thread.o:/tmp/libmemcached-0.49/clients/ms_thread.c:208: more undefined references to `__sync_fetch_and_add_4' follow
collect2: ld returned 1 exit status
make[2]: *** [clients/memslap] 错误 1
make[2]: Leaving directory `/tmp/libmemcached-0.49'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/tmp/libmemcached-0.49'
make: *** [all] 错误 2

修改相关参数编译
[root@niutian365 tmp]# ./configure --prefix=/usr/local/libmemcached --with-memcached --disable-64bit CFLAGS="-O3 -march=i686"
[root@niutian365 tmp]# make
[root@niutian365 tmp]# make install


先安装php,再安装扩展包
[root@localhost mem]# tar -zxvf memcache-1.5.tgz
[root@localhost mem]# cd memcache-1.5
[root@localhost mem]#/usr/local/php/bin/phpize
[root@localhost memcache-1.5]# ./configure --enable-memcache --with-php-config=/home/web/php/bin/php-config --with-zlib-dir
[root@localhost memcache-1.5]#make
[root@localhost memcache-1.5]#make test
[root@localhost memcache-1.5]#make install


运行/usr/local/webserver/php/bin/phpize时出现:
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
根据网上的解决办法是:

# cd /usr/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install


安装完成后提示:
[root@localhost memcache-1.5]# make install
Installing shared extensions:     /home/web/php/lib/php/extensions/no-debug-non-zts-20090626/

修改php.ini
然后修改php.ini
    把extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
并添加一行 extension=memcache.so

---------------
5、测试:
启动memcache
/usr/local/bin/memcached -d -m 10 -u root -l 10.103.20.135 -p 11211 -c 256 -P /tmp/memcached.pid

---
/usr/local/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

如果报这个错误就

把/usr/local/lib 加入到/etc/ld.so.conf下
然后执行 ldconfig

---

测试代码:
<?php
$memcache = new Memcache;
$memcache->connect('10.103.20.135',11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值