Tuesday, February 14, 2012

how to install memcached

Install  memcached

Cách 1: Cài và chạy bằng tay 

Here's a quick recipe for installing memcached on EC2 Amazon Linux AMI 1.0.

yum install gcc libevent libevent-devel
cd /usr/local/src
wget http://memcached.org/latest
tar -xf memcached-*.tar.gz
cd memcached-*
make && make install
Memcached will be installed to /usr/local/bin. Let's make sure everything went well by running memcached:

/usr/local/bin/memcached -u root -d
 Then we'll make sure it's running
ps aux | grep memcached
netstat -anp | grep 11211
And finally kill it.
pkill memcached


Cách 2: Cài và chạy service

Going all out - building a memcached rpm

If you're installing memcached on multiple machines then having an RPM handy is preferred. Make sure to run this as the ec2-user and not root.
cd ~
sudo yum install gcc libevent libevent-devel rpm-build perl-Test-Base
echo "%_topdir /home/ec2-user/rpmbuild" >> ~/.rpmmacros
mkdir -p /home/ec2-user/rpmbuild/{SPECS,BUILD,SRPMS,RPMS,SOURCES}
wget http://memcached.org/latest
rpmbuild -ta memcached-*.tar.gz

The RPM will be created in ~/rpmbuild/RPMS/x86_64/ or ~/rpmbuild/RPMS/i386/ depending on whether you chose a 32 or 64 bit AMI. Copy the rpm to your home directory and run the command below to install memcached to /usr/bin/memcache

sudo yum localinstall memcached-*.rpm --nogpgcheck

The beauty of this approach is that you can now do the following to start or stop memcached

service memcached status
service memcached start
service memcached stop
And finally you can enable memcached at startup with this simple command:
chkconfig memcached on

Install  php-pecl-memcache

#if apt-get, rpm, or yum doesn't work
cd /usr/src/
wget http://pecl.php.net/get/memcache-2.2.4.tgz
tar -zxvf memcached-2.2.4.tgz
cd memcached-2.2.4
phpize && ./configure --enable-memcache && make
cp modules/memcache.so /usr/lib/php/modules/

# Note: packaged extension modules are now loaded via the .ini files
# found in the directory php.ini
php -i | grep php.ini

vi /etc/sysconfig/memcached
 PORT=”11211″                #define on which port to urn
USER=”nobody”           #same as apache user
MAXCONN=”1024″     #maximum number of connections allowed
CACHESIZE=”64″         #memory used for caching
OPTIONS=”"                   #use for any custom options
add php.ini
restart service https
/etc/init.d/httpd restart

Note: Neu bi loi can install cac goi
yum install php-devel
yum install zlib-devel
yum install zlib zlib-devel
Check memcache
php -i | grep memcache

[root@dedi94125 ~]# more testmemcach.php
$memcache = new Memcache;
$memcache->connect('', 11211);

[root@dedi94125 ~]# php testmemcach.php
Memcache Object
    [connection] => Resource id #5

[root@dedi94125 ~]# 

No comments: