Header ads

Header ads
» » » » Cài đặt Redis trên CentOS 7/6

Redis ra đời, không chỉ hỗ trợ cache dạng keys/values tốt như Memcached mà còn hỗ trợ lưu tags. Do đó, khi sử dụng Redis, tốc độ hệ thống Magento được cải thiện lên rất nhiều do không phải lưu cache trên ổ cứng nữa mà tất cả được chuyển hết lên bộ nhớ.

redis

Hướng dẫn cài đặt Redis

Để Redis có thể làm việc được với Magento, chúng ta sẽ cần cài đặt Redis server cùng với extension PhpRedis để PHP có thể kết nối được với Redis.
1. Thêm repo epel, remi
## CentOS 7 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

## CentOS 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2. Cài đặt Redis và PhpRedis extension
## PHP 5.6 ##
yum --enablerepo=remi,remi-php56 install redis php-pecl-redis
service php-fpm restart

## PHP 5.5 ##
yum --enablerepo=remi,remi-php55 install redis php-pecl-redis
service php-fpm restart
– Chạy Redis và tự động khởi động khi boot
chkconfig redis on
service redis start

Kiểm tra lại quá trình cài đặt Redis

1. Check lại Redis server
redis-cli ping
Nếu kết quả về PONG là ok
2. Check lại PhpRedis extension
php -m | grep redis
Kết quả trả về redis là ok
3. Redis shell tools
Mặc định Redis cài đặt với một công cụ comment là redis-cli
Sau khi khởi động Redis, các bạn có thể sử dụng một số command như:
  • FLUSHALL – clear all databases
  • SELECT # – select database under index #
  • FLUSHDB – empty currently selected database
  • KEYS * – list all keys from currently selected
Xem danh sách đầy đủ command ở đây.

Sử dụng Redis với Magento

Redis hỗ trợ các phiên bản Magento khác nhau. Trong trường hợp phiên bản Magento của bạn không hỗ trợ Redis cache hoặc session backend (hoặc cả hai), bạn có thể sử dụng extensions cài đặt thêm.
Magento CE >= 1.7.0.0 và < 1.8.0.0
  • Session storage – không hỗ trợ
  • Cache backend –không hỗ trợ, tên class sau khi cài đặt là Cm_Cache_Backend_Redis
Magento CE >= 1.8.0.0
  • Session storage – hỗ trợ
  • Cache backend –hỗ trợ, tên class sau khi cài đặt là Mage_Cache_Backend_Redis
Magento EE >= 1.13.0.0 và < 1.13.1.0
  • Session storage – không hỗ trợ
  • Cache backend – hỗ trợ, tên class sau khi cài đặt là Mage_Cache_Backend_Redis
Magento EE >= 1.13.1.0
Session storage – hỗ trợ
Cache backend – hỗ trợ, tên class sau khi cài đặt là Mage_Cache_Backend_Redis
Sử dụng Redis làm backend cache
Để kích hoạt Redis, bạn hãy sửa file app/etc/local.xml, thêm đoạn sau vào vị trí tương ứng để sử dụng database 0
<config>
    <global>
 
        <!-- other configuration nodes -->
 
        <cache>
          <backend>CACHE_BACKEND_CLASS_NAME</backend>
          <backend_options>
            <server>127.0.0.1</server>              <!-- or absolute path to unix socket -->
            <port>6379</port>
            <persistent></persistent>               <!-- Specify a unique string like "cache-db0" to enable persistent connections. -->
            <database>0</database>
            <password></password>
            <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
            <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures -->
            <read_timeout>10</read_timeout>         <!-- Set read timeout duration -->
            <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default -->
            <compress_data>1</compress_data>        <!-- 0-9 for compression level, recommended: 0 or 1 -->
            <compress_tags>1</compress_tags>        <!-- 0-9 for compression level, recommended: 0 or 1 -->
            <compress_threshold>20480</compress_threshold>  <!-- Strings below this size will not be compressed -->
            <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy -->
          </backend_options>
        </cache>
 
        <!-- other configuration nodes -->
 
    </global>
</config>
Thay CACHE_BACKEND_CLASS_NAME bằng tên class như đã đề cập bên trên.
Sau khi kích hoạt Redis, bạn có thể xóa toàn bộ nội dung trong folder var/cache. Để kiểm tra xem Redis có đang hoạt động thực sự hay không, hãy chạy tool redis-cli rồi dùng lệnh sau với database 0
SELECT 0
KEYS *
Ngoài ra, bạn có thể sử dụng phpRedisAdmin để theo dõi trạng thái cache ngay trên trình duyệt web.

Tổng kết

Trong trường hợp bạn có một shop nhỏ với Magento thì không cần thiết phải sử dụng Redis. Tuy nhiên, lúc này hãy sử dụng ổ cứng SSD để có thể tăng tốc độ đọc ghi cache. Còn nếu shop lớn, hãy sử dụng Redis.
Tham khảo thêm:

About Học viện đào tạo trực tuyến

Xinh chào bạn. Tôi là Đinh Anh Tuấn - Thạc sĩ CNTT. Email: dinhanhtuan68@gmail.com .
- Nhận đào tạo trực tuyến lập trình dành cho nhà quản lý, kế toán bằng Foxpro, Access 2010, Excel, Macro Excel, Macro Word, chứng chỉ MOS cao cấp, IC3, tiếng anh, phần mềm, phần cứng .
- Nhận thiết kế phần mềm quản lý, Web, Web ứng dụng, quản lý, bán hàng,... Nhận Thiết kế bài giảng điện tử, số hóa tài liệu...
HỌC VIỆN ĐÀO TẠO TRỰC TUYẾN:TẬN TÂM-CHẤT LƯỢNG.
«
Next
Bài đăng Mới hơn
»
Previous
Bài đăng Cũ hơn