Memcache sẽ sử dụng RAM để cache, nên tốc độ truy xuất sẽ nhanh hơn, nhưng bạn sẽ tốn 1 lượng RAM đáng kể, mình thì sử dụng 1GB RAM cho memcache.
Step # 1: Turn on EPEL Repo
Type the following command to enable EPEL repo which carries required memcache packages.
rpm -Uvh http://download.fedora.redhat.com/pu...5-3.noarch.rpm
1. Cài đặt gói memcached:
Code:
yum install memcached (neu bao loi thi fix a.)
a. Step # 1: Turn on EPEL Repo
Type the following command to enable EPEL repo which carries required memcache packages.
rpm -Uvh http://download.fedora.redhat.com/pu...5-3.noarch.rpm
Neu link bi loi thi lay link
rpm -Uvh http://dl.fedoraproject.org/pub/epel...5-4.noarch.rpm
roi chay lai yum install memcached
http://www.cyberciti.biz/faq/rhel-fe...ng-system-rpm/
http://www.cyberciti.biz/faq/howto-i...fedora-centos/
2. Cấu hình memcached:
Code:
nano -w /etc/sysconfig/memcached
hoặc
Code:
vi /etc/sysconfig/memcached
Thêm vào đoạn code sau, trong đó CACHESIZE là số RAM bạn muốn memcached sử dụng (1024 = 1GB).
Code:
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="1024"
OPTIONS=""
3. Khởi động memcached:
+ Khởi động memcached khi server khởi động.
Code:
chkconfig memcached on
+ Chạy memcached:
Code:
/etc/init.d/memcached start
hoặc
Code:
service memcached start
+ Kiểm tra memcached đã chạy chưa?
Code:
/etc/init.d/memcached status
Sau khi thực hiện lệnh trên thì nó sẽ hiển thị đại loại như sau (chứng tỏ service đã chạy rùi)
Code:
memcached (pid 6475) is running…
4. Cài đặt PHP extension (neu cai memcached.so thi lam theo bước 7)
Để bạn có thể sử dụng memcached với PHP thì bạn cần cài đặt gói memcache này.
+ Download phiên bản mới + ổn định (stable) của memcache từ trang PECL.
Code:
cd /usr/src
wget http://pecl.php.net/get/memcache-2.2.6.tgz
tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
phpize
./configure // den buoc nay neu bao loi thieu zlip thi cai yum install zlib-devel roi lam lai tu buoc 4 la ok.
make
make install
+ Sau đó, console sẽ thông báo cho bạn đường dẫn của file memcache.so. Ví dụ với PHP 5.2 thì đường dẫn là:
Code:
/usr/local/lib/php/extensions/no-debug-non-zts-20060613/
+ Bạn cần cấu hình extension_dir trong file php.ini với đường dẫn này:
++ để biết đường dẫn file php.ini ở đâu:
Code:
php -i | grep php.ini
kết quả có thể là:
Code:
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
++ Mở file php.ini:
Code:
vi /usr/local/lib/php.ini
++ Tìm đến extension_dir và cập nhật lại folder cài đặt memcache.so
Code:
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
++ Thêm đoạn này vào cuối của mục Dynamic Extensions trong file php.ini :
Code:
extension = memcache.so
5. Khởi động lại Apache
/etc/init.d/httpd restart
6. Kiểm tra memcached đã hoạt động chưa?
Code:
php -i | grep memcache
Kết quả sẽ đại loại:
Code:
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user sqlite memcache
PWD => /usr/src/memcache-2.2.6
_SERVER["PWD"] => /usr/src/memcache-2.2.6
_ENV["PWD"] => /usr/src/memcache-2.2.6
Done !
(neu cai memcache cho dso sau chuyen tu dso sang suphp phai cai lai memcache khi cai van bao loi )
php -v
PHP Warning: PHP Startup: memcache: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20131226
These options need to match
thi phai bang perl nhu muc 7 la
/usr/local/php5/bin/pecl install memcache (php5: thay the phien ban php tuong ung tren server dang cai neu la php 5.6 thi lenh la )
/usr/local/php56/bin/pecl install memcache
7. cài đặt memcached.so (memcached.so cache nhanh hon memcache.so thuong)
1. wget http://monkey.org/~provos/libevent-2.0.10-stable.tar.gz
2. tar -xvf libevent-2.0.10-stable.tar.gz
3. cd libevent-2.0.10-stable
4. ./configure;make;make install;
Then, get Memcached from http://memcached.org
1. wget http://memcached.googlecode.com/file...d-1.4.5.tar.gz
2. gunzip memcached-1.4.5.tar.gz
3. tar -xvf memcached-1.4.5.tar
4. cd memcached-1.4.5
5. ./configure;make;make install;
For me, I got an error below when try to run memcached :
1. memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
So, I did steps below :
1. ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
Once you're done with that, try run
1. memcached -d -u nobody -m 1024 127.0.0.1 -p 11211
This is not done yet, you need to let PHP knows to be able to use memcached.
1. wget http://launchpad.net/libmemcached/1....ed-0.48.tar.gz
2. tar xvfz libmemcached-0.48.tar.gz
3. cd libmemcached-0.48
4. ./configure
5. make && make install
Then install Memcached PECL with below command :
1. pecl install memcached (neu lenh nay o hieu thi chay lenh sau)
2. /usr/local/php5/bin/pecl install memcached
3. Neu bao lôi
4. make: *** [php_memcached.lo] Error 1
5. ERROR: `make' failed
6. thi cai
7. /usr/local/php5/bin/pecl install -f memcached-2.0.1
neu bi loi
shtool at ‘/tmp/pear/memcached/build/shtool’ does not exist or is not executable.
Make sure that the file exists and is executable and then rerun this script.
ERROR: `phpize’ failed
http://blog.litespeedtech.com/2013/0...l-doesnt-work/
Gõ lệnh mount -o remount,exec /tmp sau đó chay lai lenh
8. /usr/local/php5/bin/pecl install -f memcached-2.0.1 hoặc
9. /usr/local/php5/bin/pecl install memcached là ok
Therefore, make sure you get the right path for extension_dir Edit php.ini to have lines below : (Make sure the line "extension_dir" is there or you need a full path to memcached.so )
1. extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626"
2. extension=memcached.so
Chúc các bạn thành công !