将Moodle LMS连接到Redis服务器以进行Moodle缓存

nxagd54h  于 4个月前  发布在  Redis
关注(0)|答案(1)|浏览(76)

我试图将托管在Windows Server 2019计算机上的Moodle 3.9网站连接到运行在Red Hat Redis服务器上的Redis示例,以便配置Moodle使用Redis进行缓存,但我很难将Moodle网站连接到该Redis服务并使缓存工作。
我已经提到了https://docs.moodle.org/402/en/Redis_cache_store,但是在文档中有很多空白。
Moodle中的“已安装的缓存存储”页面在Moodle的“缓存管理”页面中为Redis显示了一个绿色勾号。
Moodle PHPInfo页面显示PHP Redis模块已安装在PHP中。
在Moodle中,在“站点管理/插件/缓存/配置”下,Redis显示在已安装的缓存存储列表中。
在Moodle中,我为Redis添加了一个Store示例,并将Store示例中的Server字段指向我的Redis服务器的'myredisserver.mydomain.com'名称。我还尝试了Redis服务器的IP地址。
在“Site Admin / Plugins / Caching / Cache Stores / Redis”下,我在测试服务器字段中添加了我的Redis Red Hat Linux服务器名称为“myredisserver.mydomain.com”。
在Red Hat命令行中,我输入:$redis-cli ping命令,Redis返回PONG,这意味着Redis正在工作。
那么,为什么Moodle不能连接到Redis?我做错了什么?
我需要在Moodle缓存配置中指定6379端口吗?
或者是我错过了一个Linux网络问题?
我还错过了什么

wsxa1bj1

wsxa1bj11#

有几件事可以尝试:首先,你是从哪里ping到你的redis服务器的?是从你的moodle服务器吗?你是否启用了服务器的防火墙来允许它们通信?
在你的步骤中,你没有提到你的php redis设置。你需要修改你的php.ini https://github.com/phpredis/phpredis

session.save_handler = redis
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5"

字符串
最后,你还需要在moodle.php中配置redis(你没有指定,所以我猜你没有)。搜索下面的行,它们被注解了,所以取消注解并填写你的配置信息:

//   Redis session handler (requires redis server and redis extension):
      $CFG->session_handler_class = '\core\session\redis';
      $CFG->session_redis_host = '127.0.0.1';
//      Use TLS to connect to Redis. An array of SSL context options.     Usually:
      $CFG->session_redis_encrypt = ['cafile' => '/path/to/ca.crt']; or...
      $CFG->session_redis_encrypt = ['verify_peer' => false, 'verify_peer_name' => false];
      $CFG->session_redis_port = 6379;                     // Optional.
      $CFG->session_redis_database = 0;                    // Optional, default is db 0.
      $CFG->session_redis_auth = '';                       // Optional, default is don't set one.
      $CFG->session_redis_prefix = '';                     // Optional, default is don't set one.
      $CFG->session_redis_acquire_lock_timeout = 120;      // Default is 2 minutes.
      $CFG->session_redis_acquire_lock_warn = 0;           // If set logs early warning if a lock has not been acquried.
      $CFG->session_redis_lock_expire = 7200;              // Optional, defaults to session timeout.
      $CFG->session_redis_lock_retry = 100;                // Optional wait between lock attempts in ms, default is 100.
                                                           // After 5 seconds it will throttle down to once per second.


最后一件事:检查你的redis是否在php-m中激活。如果没有,你可能需要在你的php的mods-available文件夹中添加一个redis.ini(但如果它显示在你的php信息中,就不太可能了)。
编辑:
在debian / ubuntu上你应该安装redis-server

apt install redis-server


然后编辑redis.conf

cp /etc/redis/redis.conf /etc/redis/your-service-name.conf


https://redis.io/docs/management/config-file/
然后激活您的服务

systemctl enable [email protected]

相关问题