ocs是类memcache的一个阿里云产品,底层是tair兼容memcache协议
本文介绍一下centos5.8下如何通过yum快速安装高版本的gcc等依赖模块,使之符合ocs的要求(ubuntu点这里~)
首先配置一下阿里云的源,由于阿里巴巴的ABTN优势,阿里云的镜像源是国内最好的多线BGP源没有之一
02 |
[root@ test yum.repos.d] |
03 |
2014-01-11 00:43:49 (179 MB/s) - `/etc/yum.repos.d/CentOS-Base.repo' saved [2436/2436] |
04 |
[root@ test yum.repos.d] |
06 |
name=Extra Packages for Enterprise 5 - $basearch |
07 |
baseurl=http://mirrors.aliyun.com/epel/5/$basearch |
09 |
failovermethod=priority |
12 |
gpgkey= file :///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5 |
15 |
name=Extra Packages for Enterprise 5 - $basearch - Debug |
16 |
baseurl=http://mirrors.aliyun.com/epel/5/$basearch/debug |
18 |
failovermethod=priority |
20 |
gpgkey= file :///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5 |
24 |
name=Extra Packages for Enterprise 5 - $basearch - Source |
25 |
baseurl=http://mirrors.aliyun.com/epel/5/SRPMS |
27 |
failovermethod=priority |
29 |
gpgkey= file :///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5 |
31 |
[root@ test yum.repos.d] |
卸载自带的低版本gcc,并安装gcc4.4(OCS要求4.2以上)
安装php5.3 (ocs要求php版本高于等于5.3),以及其它必须的依赖组件
安装libmemcache
1 |
wget http://launchpad.net/libmemcached/1.0/1.0.2/+download/libmemcached-1.0.2. tar .gz |
2 |
tar -zxvf libmemcached-1.0.2. tar .gz |
4 |
/configure --prefix=/usr/ local /libmemcached |
5 |
make && make install && make clean |
安装zlib和memcache
1 |
yum install zlib-devel -y |
2 |
wget http://pecl.php.net/get/memcached-2.0.0.tgz |
3 |
tar -zxvf memcached-2.0.0.tgz |
6 |
./configure --with-libmemcached- dir =/usr/ local /libmemcached -- enable -memcached-sasl |
然后修改Php.ini,加载memcache的扩展
extension=memcached.so
至此已经配置完毕了
通过以下命令测试一下memcache是否配置成功,或者配置phpinfo页面查看下
1 |
[root@ test memcached-2.0.0] |
4 |
[root@ test memcached-2.0.0] |
5 |
[root@ test memcached-2.0.0] |
至此你的服务器已经可以支持阿里云的OCS了,测试demo~
01 |
[root@test html]# vim / var /www/html/ocs.php |
03 |
$connect = new Memcached; |
04 |
$connect ->setOption(Memcached::OPT_COMPRESSION, false); |
05 |
$connect ->setOption(Memcached::OPT_BINARY_PROTOCOL, true); |
06 |
$connect ->addServer( '7d9cfd3014aa11e3.m.cnhzalicm10pub001.ocs.aliyuncs.com' , 11211); |
07 |
$connect ->setSaslAuthData( '7d9cfd3014aa11e3' , '*******' ); |
08 |
for ( $i =0; $i <10; $i ++){ $connect ->set( "$i" , "world" ); |
09 |
echo "key" . $i . "is:" , $connect ->get( "$i" ). "<br>" ; |
访问测试:
(责任编辑:IT) |