Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New FAQs to document how to use Redis for sessions and cache #7767

Closed
mattab opened this issue Apr 25, 2015 · 5 comments
Closed

New FAQs to document how to use Redis for sessions and cache #7767

mattab opened this issue Apr 25, 2015 · 5 comments
Assignees
Labels
c: Website matomo.org For issues related to our matomo.org website. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Apr 25, 2015

The goal of this issue is to document in the FAQs

  • how to use Redis to store caches
  • how to use Redis to store sessions
    • update the FAQ about enabling db sessions to link to the redis alternative

follows up #6800

@mattab mattab added Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change. c: Website matomo.org For issues related to our matomo.org website. labels Apr 25, 2015
@mattab mattab added this to the Piwik 2.14.0 milestone Apr 25, 2015
@tsteur
Copy link
Member

tsteur commented Apr 28, 2015

Maybe we could even write a blog post on how to use Redis when using Piwik in a load balanced environment and also include QueuedTracking plugin for handling peaks etc. I will create an issue for this.

@mattab mattab modified the milestones: 2.14.1, 2.14.0 Jun 16, 2015
@mattab mattab modified the milestones: 2.14.1, 2.15.0 Jul 16, 2015
@tsteur
Copy link
Member

tsteur commented Jul 29, 2015

Maybe something like this? @mattab

How to configure Redis as a shared cache in a load balanced environment

By default Piwik caches data in the local filesystem of each server. If your Piwik environment consists of multiple servers a common problem is that caches are only invalidated on one server instead of all servers. To workaround this we recommend to use a shared cache for all of your servers. You can do this by installing and configuring Redis.

To use Redis as a cache follow these steps:

  • Make sure you are using at least Piwik 2.10 (latest Piwik version recommended)
  • Install Redis see Redis Quickstart
  • Install the PHP extension phpredis
  • Don't forget to restart your webserver
  • Once successfully setup, enable it in the config file config/config.ini.php. Make sure to adjust the section [RedisCache] to your needs. You have to make this change on each of your server.
[Cache]
backend = chained

[ChainedCache]
backends[] = array
backends[] = redis

[RedisCache]
host = "127.0.0.1" 
port = 6379
timeout = 0.0
password = ""
database = 14
; In case you are using queued tracking: Make sure to configure a different database! Otherwise queued requests will be flushed

How to configure Redis for session handling in a load balanced environment

By default Piwik uses the filesystem as a session handler. If your Piwik environment consists of multiple servers a common problem is that multiple sessions are created per user meaning a user might have to log in multiple times and a log out might actually log out a user only on one server. To workaround this there are two options:

  • Use the database to handle sessions
  • Use Redis to handle sessions (described in this FAQ). Redis is usually faster than a database and we recommend it in case one has Redis already configured as a [Cache](TODO LINK TO REDIS CACHE FAQ) or for Queued Tracking.

To use Redis as a session handler follow these steps:

  • Install Redis see Redis Quickstart
  • Install the PHP extension phpredis
  • Configure Redis as PHP session handler in php.ini on each of your server:
session.save_handler = redis 
session.save_path    = tcp://127.0.0.1:6379?database=10
; In case you are using queued tracking or Redis as a cache: Make sure to configure a different database! Otherwise queued requests will be flushed

; multiple servers can be configured comma separated
session.save_path = "tcp://host1:6379?weight=1&database=2, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"

See Redis Session Handler for more documentation.

  • Don't forget to restart your webserver
  • Once successfully setup, make sure there is no Piwik default session handler configured by setting the session_save_handler to an empty value in the config file config/config.ini.php. You have to make this change on each of your server.
[General]
session_save_handler = ""

@tsteur
Copy link
Member

tsteur commented Aug 6, 2015

assigning to @mattab for now to put it into FAQ in case it is ok

@mattab
Copy link
Member Author

mattab commented Aug 12, 2015

Text is very clear, both FAQs have been published:

Nice new resource for admin who want to re-use the power of Redis!

@mattab mattab closed this as completed Aug 12, 2015
@tangzhiqiangh
Copy link

“session.save_path = tcp://127.0.0.1:6379?database=10”invalid ,Excuse me where is the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Website matomo.org For issues related to our matomo.org website. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Projects
None yet
Development

No branches or pull requests

3 participants