Feature #196
Adding Redmine to a Centralized Memcache Server
Description
I encountered the need to have centralized session management for the multiple instances of the same content. This is where memcache comes in. First the gem for memcache needs to be installed:
sudo gem install memcache-client
Next, add the environment code to the end of
config/environment.rb
to utilize the memcache server:# Load memcache require 'memcache' config.action_controller.session_store = :mem_cache_store memcache_options = { :compression => true, :debug => false, :namespace => "mem-#{RAILS_ENV}", :readonly => false, :urlencode => false } memcache_servers = [ 'memcacheIP:11211' ] CACHE = MemCache.new(memcache_options) CACHE.servers = memcache_servers ActionController::Base.session_options[:cache] = CACHE
Updated by Daniel Curtis over 11 years ago
After deploying the above implementation, my instance of redmine broke. I could not find a proper guide to connecting redmine to a memcache server for session management. I did find an implementation for the foreman ruby application at http://projects.theforeman.org/projects/1/wiki/Set_up_memcached
I have adapted the implementation to redmine, with a few minor adjustments.
Set up memcached¶
Instead of using memcache-client, we are going to use Dalli, a ruby gem that allows Rails to use your memcached store.
Include this in your Gemfile¶
gem 'dalli'
Then run:
bundle install
Open your environment config file, it is in config/environments/*.rb
. Let's assume you will want to set memcached as your production cache store, such as config/environments/production.rb
Add the following line in the RedmineApp::Application.configure
block
config.cache_store = :dalli_store
Reboot your server (nginx, passenger, mongrel, thin..)
Additional options¶
If you have your own separate cache servers, just add it after the command like this:
config.cache_store = :dalli_store, 'cache1.myserver.com', 'cache2.myserver.com'
Use memcached to manage sessions¶
Just add something like this to your config/environment.rb
:
require 'action_dispatch/middleware/session/dalli_store'
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
Updated by Daniel Curtis over 10 years ago
I found a better way to cache sessions, still using the dalli gem however:
vi /path/to/redmine/config/environments/production.rb
Then add the following right after RedmineApp::Application.configure do:
# Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.perform_caching = true # config.cache_store = :dalli_store require 'action_dispatch/middleware/session/dalli_store' Rails.application.config.session_store :dalli_store \ , :memcache_server => ['localhost', '127.0.0.1'] \ , :namespace => 'sessions' \ , :key => '_foundation_session' \ , :expire_after => 20.minutes \ , :compress => true \ , :compressor => Dalli::GzipCompressor \ , :keepalive => true \ , :expires_in => 5.minutes #config.cache_store = :dalli_store, 'localhost', #{ :namespace => "redmine_pro", :expires_in => 3600, :compress => true } # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com"