Configure Redis Server in Ubuntu – Caching Server For Magento

Redis – Server :-
REDIS is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis works with an in-memory dataset.

Redis-Server Installation on Ubuntu:

Execute below commands in /tmp directory.
-> wget http://download.redis.io/redis-stable.tar.gz
-> tar xvzf redis-stable.tar.gz
-> cd redis-stable
-> make

First Install Redis Cache Extension:
-> git clone https://github.com/colinmollenhour/Cm_Cache_Backend_Redis.git
-> mv Cm_Cache_Backend_Redis/Cm app/code/community
-> rm -rf Cm_Cache_Backend_Redis

Then Install Redis Session Extension:
-> git clone https://github.com/colinmollenhour/credis.git
-> mv credis lib/Credis
-> git clone https://github.com/colinmollenhour/Cm_RedisSession.git
-> mv Cm_RedisSession/code/ app/code/community/Cm/RedisSession
-> mv Cm_RedisSession/Cm_RedisSession.xml app/etc/modules/Cm_RedisSession.xml
-> rm -rf Cm_RedisSession

Just after <global> add, change persistent and db to suit.
Add below lines in app/etc/local.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<cache>
<backend>Cm_Cache_Backend_Redis</backend>
<backend_options>
<server>redis11.i</server>
<port>6379</port>
<persistent>cache-db0</persistent>
<database>0</database>
<password></password>
<force_standalone>0</force_standalone>
<connect_retries>1</connect_retries>
<read_timeout>10</read_timeout>
<automatic_cleaning_factor>0</automatic_cleaning_factor>
<compress_data>1</compress_data>
<compress_tags>1</compress_tags>
<compress_threshold>20480</compress_threshold>
<compression_lib>gzip</compression_lib>
</backend_options>
</cache>
 
<session_save>db</session_save>
<redis_session>
<host>redis1.i</host>
<port>6379</port>
<timeout>2.5</timeout>
<persistent>sess-db1</persistent>
<db>1</db>
<compression_threshold>2048</compression_threshold>
<compression_lib>lzf</compression_lib>
<log_broken_locks>0</log_broken_locks>
<max_concurrency>10</max_concurrency>
<break_after_frontend>5</break_after_frontend>
<break_after_adminhtml>30</break_after_adminhtml>
<bot_lifetime>7200</bot_lifetime>
</redis_session>

Check whether Redis-Server is correctly configured.
Execute the following commands in ssh.

root@ip:~# redis-cli (Enter)
redis 127.0.0.1:6379> KEYS *

1) “zc:ti:mage_LAYOUT_GENERAL_CACHE_TAG”
2) “zc:k:mage_LAYOUT_12B8E4E9B9664A88F620395C2B0E265C3″
3) “zc:ti:mage_PRODUCT_31489″
4) “zc:k:mage_LAYOUT_102DAFD20DE438A6CCEAB14C14CBD43E6″
5) “zc:k:mage_LAYOUT_12C9CC1468A49CEAAD89B704922CFA00D”
6) “zc:ti:mage_PRODUCT_32386″
7) “zc:k:mage_LAYOUT_145900AB7F6D4CEB9F4C7CDA3C3FDB3E0″
8) “zc:k:mage_Zend_LocaleL_en_GB_day_”
9) “zc:k:mage_LAYOUT_1570BAB63946016D4308F3846E31F3298″
10) “zc:k:mage_LAYOUT_1A81FEA2A13A548546F8C44C45F291E58″
11) “zc:k:mage_LAYOUT_178D667D0447D0D68CE44FA446B549C57″
12) “zc:k:mage_LAYOUT_1D9AB3A02AE7912CCD665FA0A14082DFE”
13) “zc:k:mage_LAYOUT_1EC736E7B6D5E1342588C904A476EF7A4″
14) “zc:ti:mage_PRODUCT_528″
15) “zc:ti:mage_PRODUCT_5001″
16) “zc:k:mage_LAYOUT_180058FA3A3E7ADD27514DD63BF803443″
17) “zc:k:mage_LAYOUT_149B9701C3A642D6FADE5A8C5EFAB3A53″
18) “zc:ti:mage_PRODUCT_5004″
19) “zc:k:mage_LAYOUT_1747906323D5671235BF2A45136D30FE6″
20) “zc:k:mage_LAYOUT_1F48BF80A73C5CDACE114DBC9168A79F9″

This should be the output.
If you are getting above output then Redis-Server is configured correctly and running. And above count should increase continuously.

For more reference :
–> http://redis.io/topics/quickstart
–> https://help.sonassihosting.com/magestack/installing-the-redis-magento-extension/
—————————————————————————————————————

How To Configure Varnish Cache In Magento With Ubuntu

Varnish Cache is one of the fastest known cache technology.. The technical principle of Varnish is that a user hits the Varnish server first before the request gets redirected to the web server if no cache version is available. If Varnish has found a cached version of the requested URL , the page will be delivered directly from the ram which takes only some milliseconds. The response time will be around 35 milliseconds + latency.

Step one : Installation of Varnish Server On Ubuntu 12.04 :
The varnish site recommends installing the varnish package through their repository.
Start the process by grabbing the repository:
*(Keep in mind that you are a root user while executing the below commands and if you are not root then use sudo in all the lines)

1.curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
2.vi /etc/apt/sources.list
Inside the file, add varnish repository to the list of sources.
deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0
3. Finally, update apt-get and install varnish.
apt-get update
apt-get install varnish



Step Two : Configure Varnish

Once you have both nginx and varnish installed, you can start to configure them to ease the load on your virtual private server.
Varnish will serve the content on port 80, while fetching it from nginx which will run on port 8080.

1. Edit /etc/default/varnish file.

Find the lines under “DAEMON_OPTS”— in the Alternative 2 section, and change the port number by “-a” to 80. The configuration should match the following code:

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

Save and exit.



Step Three : Configuring Nginx
:
Edit the vhost file as shown below
vi /etc/nginx/sites-available/your.vhost
server
{
listen 127.0.0.1:8080;
## listen for ipv4;
this line is default and implied [...]


 

Step Four : Restart Nginx and varnish.
service nginx restart
service varnish restart

Then check your browser.
If its still not working,try below commands

service nginx stop
service varnish restart
service nginx start

Check varnish by following commands.
varnishstat

Pheeww! Sit back,relax and check your website’s performance.
________________________________________________________________