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-* ./configure make && make install
/usr/local/bin/memcached -u root -d
netstat -anp | grep 11211ps aux | grep memcached
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
And finally you can enable memcached at startup with this simple command:service memcached status service memcached start service memcached stop
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 urnadd php.ini
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
extension="memcache.so"restart service https
/etc/init.d/httpd restart
Note: Neu bi loi can install cac goi
yum install php-develCheck memcache
yum install zlib-devel
yum install zlib zlib-devel
php -i | grep memcache
[root@dedi94125 ~]# more testmemcach.php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
print_r($memcache);
?>
[root@dedi94125 ~]# php testmemcach.php
Memcache Object
(
[connection] => Resource id #5
)
[root@dedi94125 ~]#
0 comments:
Post a Comment