Redis cache store: Skillnad mellan sidversioner
m (removing link to non-existing page) |
|||
(7 mellanliggande sidversioner av 5 användare visas inte) | |||
Rad 1: | Rad 1: | ||
{{Performance}} | {{Performance}} | ||
The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for user's sessions caching | The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for [[Session_handling#Redis_session_driver|user's sessions caching]] in the config.php file) | ||
Before Redis is available as a cache store, you will need to install | Before Redis is available as a cache store, you will need to install Redis service (daemon) on your Moodle server, locally in case of a single Moodle app node architecture or externally if you are using a cluster of Moodle nodes. only then, you can configure Redis as an application or session level cache store. | ||
If you are configuring a cluster of Moodle servers/nodes, the | If you are configuring a cluster of Moodle servers/nodes, the Redis service (daemon) should be installed on an external server and all Moodle nodes (servers/instances) should point to that external Redis. So all user's data is available when the user is using (connected to) any of the Moodle nodes. An external Redis (NoSQL) service can be installed on the main SQL server alongside the MySQL/MariaDB service, just make sure you have enough memory allocated on that server for both services. | ||
A good practice is to give the | A good practice is to give the Redis cache store prefix a proper short name and not leave it empty, as later on, it might conflict with user's session Redis cache you might choose to use, or other Moodle instances that will be installed on the same server. for example "my-school-name_cs_", where you replace "my-school-name" with your short school name. (and if you are also using a user's session store on the config.php file, you might like to prefix it with "my-school-name_us_") | ||
When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client. | When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client. | ||
Rad 12: | Rad 12: | ||
==Installing Redis server== | ==Installing Redis server== | ||
* [https://www.linode.com/docs/databases/redis/install-and-configure-redis-on-centos-7 install and configure redis on centos 7] | * [https://www.linode.com/docs/databases/redis/install-and-configure-redis-on-centos-7 install and configure redis on centos 7] | ||
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04 install and configure redis on Ubuntu 18.04] | |||
* [[Session_handling#Redis_session_driver]] and [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04 How to Set Up a Redis Server as a Session Handler for PHP] | * [[Session_handling#Redis_session_driver]] and [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04 How to Set Up a Redis Server as a Session Handler for PHP] | ||
* Install [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/redis5.html Redis 5] via IUS CentOS 7 repository. | |||
* [https://github.com/microsoftarchive/redis/releases Windows port] (the MSI file installs a service) | |||
==Installing Redis php driver== | ==Installing Redis php driver== | ||
* For CentOS, you can use either [https://rpms.remirepo.net/ Remi] or [https://ius.io/ IUS] repositories, and install the [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-redis.html php71u-pecl-redis] driver. | * For CentOS, you can use either [https://rpms.remirepo.net/ Remi] or [https://ius.io/ IUS] repositories, and install the [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-redis.html php71u-pecl-redis] driver. | ||
* [https://gist.github.com/hollodotme/418e9b7c6ebc358e7fda Redis php-fpm 7 driver on Ubuntu 14.04] | * [https://gist.github.com/hollodotme/418e9b7c6ebc358e7fda Redis php-fpm 7 driver on Ubuntu 14.04] | ||
* [https://pecl.php.net/package/redis Windows PHP extensions] including DLLs for Windows. Check your PHP version, CPU (64bit or x86) and thread-safe value (see Site Admin > Server > PHP Info) to get the right version; add DLL file to ext directory, add 'extension=php_redis.dll' entry to php.ini and restart your web server. | |||
==Configuring Redis in Moodle== | |||
* Navigate to Site admin > Plugins > Caching > Configuration. | |||
* When installed, you should see a tick next to "Redis" under "Installed cache stores" and a link to add an instance. | |||
[[File:Redis_cache_ready.png]] | |||
* Click "Add instance". | |||
** Give your Redis instance a name, like "Redis1" and set the IP:port for the Redis server. If it is on the same machine, the default would be 127.0.0.1:6379. | |||
** The new instance should appear under "Configured store instances" with a "Ready" tick. | |||
* Under "Stores used when no mapping is present" click '''Edit mappings". Set "Redis1" (or the name used earlier) for the "Application" and "Session" caches. | |||
[[File:Set_Redis_as_default_Application_and_Session_cache.png]] | |||
* After saving this, you should see Redis as the cache for most cache stores. | |||
==See also== | ==See also== | ||
* [https://gist.github.com/kabel/10023961 Monitor Redis stats (a php one page app)] | * [https://gist.github.com/kabel/10023961 Monitor Redis stats (a php one page app)] | ||
* MDL-48468 | * MDL-48468 : Add a Redis cache store to Moodle core | ||
[[de:Redis Cache]] | [[de:Redis Cache]] |
Nuvarande version från 13 augusti 2020 kl. 12.45
The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for user's sessions caching in the config.php file)
Before Redis is available as a cache store, you will need to install Redis service (daemon) on your Moodle server, locally in case of a single Moodle app node architecture or externally if you are using a cluster of Moodle nodes. only then, you can configure Redis as an application or session level cache store.
If you are configuring a cluster of Moodle servers/nodes, the Redis service (daemon) should be installed on an external server and all Moodle nodes (servers/instances) should point to that external Redis. So all user's data is available when the user is using (connected to) any of the Moodle nodes. An external Redis (NoSQL) service can be installed on the main SQL server alongside the MySQL/MariaDB service, just make sure you have enough memory allocated on that server for both services.
A good practice is to give the Redis cache store prefix a proper short name and not leave it empty, as later on, it might conflict with user's session Redis cache you might choose to use, or other Moodle instances that will be installed on the same server. for example "my-school-name_cs_", where you replace "my-school-name" with your short school name. (and if you are also using a user's session store on the config.php file, you might like to prefix it with "my-school-name_us_")
When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client.
Installing Redis server
- install and configure redis on centos 7
- install and configure redis on Ubuntu 18.04
- Session_handling#Redis_session_driver and How to Set Up a Redis Server as a Session Handler for PHP
- Install Redis 5 via IUS CentOS 7 repository.
- Windows port (the MSI file installs a service)
Installing Redis php driver
- For CentOS, you can use either Remi or IUS repositories, and install the php71u-pecl-redis driver.
- Redis php-fpm 7 driver on Ubuntu 14.04
- Windows PHP extensions including DLLs for Windows. Check your PHP version, CPU (64bit or x86) and thread-safe value (see Site Admin > Server > PHP Info) to get the right version; add DLL file to ext directory, add 'extension=php_redis.dll' entry to php.ini and restart your web server.
Configuring Redis in Moodle
- Navigate to Site admin > Plugins > Caching > Configuration.
- When installed, you should see a tick next to "Redis" under "Installed cache stores" and a link to add an instance.
- Click "Add instance".
- Give your Redis instance a name, like "Redis1" and set the IP:port for the Redis server. If it is on the same machine, the default would be 127.0.0.1:6379.
- The new instance should appear under "Configured store instances" with a "Ready" tick.
- Under "Stores used when no mapping is present" click Edit mappings". Set "Redis1" (or the name used earlier) for the "Application" and "Session" caches.
- After saving this, you should see Redis as the cache for most cache stores.
See also
- Monitor Redis stats (a php one page app)
- MDL-48468 : Add a Redis cache store to Moodle core