27 October, 2016

Standard Configuration file for Redis

In my earlier post i have covered how to run multiple instances of redis also showed through a video how it can done.

In this post, I am going to cover best suitable redis configuration file structure to have to minimize confusion to identify which ports belong to which cache.

for example if you are having several ports configured for redis, how you will determine which port is associated with which redis cache.So in our case i.e redis with Magento, we normally used 3 types of cache
  • Cache (magneto configuration files cache) 
  • Full Page Cache
  • Session Cache 






So, to avoid confusion among the ports and its associated cache, i would recommend to use following data in your redis configuration for each port respectively as shown.

 

1) Create a file with name redis-base.conf under /etc/ and put the below content in it.

vi /etc/redis-base.conf   

daemonize yes
timeout 0
tcp-keepalive 0
loglevel warning
databases 2
stop-writes-on-bgsave-error yes
rdbcompression no
maxmemory-policy volatile-lru
appendonly no  (disabling Append Only File) used for persistence
appendfsync everysec   OR always ?
no-appendfsync-on-rewrite no
slowlog-log-slower-than 10000
slowlog-max-len 1024
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
slave-serve-stale-data yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
tcp-backlog 511
tcp-keepalive 0
repl-disable-tcp-nodelay no

above parameters will be common for all redis instances we are going to use for Cache, Full Page Cache and Session cache.

2)  Configuration file for Full Page cache

vi /etc/redis-fpc.conf


include /etc/redis/redis-base.conf
port 6381
pidfile /var/run/redis/redis-fpc.pid
logfile /var/log/redis/fpc.log
dir /var/lib/redis/fpc
maxmemory 1gb

3)  Configuration file for Session file

vi /etc/redis-ses.conf

include /etc/redis/redis-base.conf
port 6380
pidfile /var/run/redis/redis-ses.pid
logfile /var/log/redis/ses.log
dir /var/lib/redis/ses
maxmemory 1gb
save 900 1
save 300 10
save 60 10000

4) Configuration file for Cache

vi /etc/redis-obj.conf

include /etc/redis/redis-base.conf
port 6379
pidfile /var/run/redis/redis-obj.pid
logfile /var/log/redis/obj.log
dir /var/lib/redis/obj
maxmemory 3gb

We are including the base file /etc/redis/redis-base.conf within every configuration files as the base file is having common variables which would be require for cache/full_page_cache and session cache.

Let me know if you have any queries on above post, you can reach to me anytime.



17 October, 2016

Multiple instances of redis


In the last post I have covered how to install redis server on Centos/Rhel using rpm method and yum method and some troubleshooting skills.

In this post i am going to cover how to install and configure redis to run with multiple ports.

         
                                                               
But why we need more ports ?


If you have read my earlier post , you already know that by default redis runs on single port 6379, which any one can use it for small website to cache the data. But for heavy website like magento we need to use additional ports along with 6379 to serve different cache from different ports.

Like in Magento there is simple cache which is normally stored under /var/cache directory. Then there is Full Page Cache which is stored under /var/full_page_cache and session cache which is stored under /var/session_cache.

Note : Discussion about cache/full page cache/session is not under the scope for this document.


                                                         
Where it is Beneficial then ?


Many of the website are using redis to fasten their response time to the end user using the advantages of redis. So if you want your website should serve as fast as possible then you should think of using redis in your environment.

But for beginners the question is ? how redis does that ? so the simplest answer i can give is 
when you visit any website for first time, your browser sends a request to the server asking for data
the server in return get the data from the application/database hosted on server and serve to browser and then to you.

This is the normal situation, where there is only browser-server in back-end application (may be php) and database (may be mysql)








but when redis is in use, browser sends the request to the server, it then checks whether the request which browser has made is available in redis database or not (means cache here), if the data present then it get served to the browser from redis itself, so here asking data from application/database gets eliminated.

so the total computation power needed for any application/database to generate requested data for the browser get saved. and then get served by REDIS. This situation is very much needed in environment   serving lots of users like some big social media sites and eCommerce sites.


                                               
Create Multiple Instances of Redis 

                                
So, let move towards creating additional instances of redis, I am assuming you already have installed redis on your linux server, if in any case if you are not, then you refer the LINK for the installation of redis on Centos/Rhel server.


    Step 1 :  Check first redis is listening on its default port i.e 6379 by running below command.


    which means your redis single instance is UP and running on the server. Now after every package installation normally two types of files gets created for redis.
    • First is init file
    • Second is Configuration file
    Init file location on the Centos/Rhel server is /etc/init.d/
    Configuration file location on Centos/Rhel server is /etc/redis.conf




    Step 2 
    : Now, install it using below command.



    Which means your redis package is installed now on your linux machine using rpm method.


    By YUM Method :-


    Step 1 :  For yum method, we first need to install repository containing the redis package by running below command



    it will create "epel.repo" file under /etc/yum.repos.d/



    That its redis is installed on your server now using yum method. Only difference between rpm method and yum method is yum finds the dependecny of package required for redis to get it install.

    means if redis also need to redis-server package to run properly then yum will install both at the same time.But rpm will not do it, instead it will install only redis package on the server.
                                               
    Status Check

    Next thing is to check how to verify redis is working properly or not, so to check that we have to run below commands



    commands explains it all, but thats command will run only on Centos/RHEL server upto OS version 6. For RHEL/Centos 7 there will be different commands to run.


    You can watch below video for to know about redis installation on linux machine and some troubleshooting skills while installing it.

    Go and watch and do not forgot to share the post if you like it.