Struggle to get Redis working with Nextcloud
Hello, this is incompetent.
Set up Nextcloud 21.0.1 + Nginx + PHP + MariaDB + Redis on Ubuntu 20.04
I followed this article, which I also referred to when I previously installed Nextcloud, but Redis did not work correctly in my environment.
It works fine even without it, so I don't necessarily have to do it...
But it's been bothering me, so here's the solution.
By the way, since I had set up a proxy cache in Nginx, I wondered what the difference was, so I asked ChatGPT to explain it. You can see it by pressing the button below.
#myText { display: none; } #toggleButton:checked ~ #myText { display: block; }
Show explanation
Nginx's proxy cache is built into the web server (Nginx) itself.
It functions as a reverse proxy, caching requests to the application server and returning responses.
It is mainly used for caching web content (HTML, images, CSS, JavaScript, etc.).
It speeds up the delivery of static files and reduces the load on the server.
Nginx's proxy cache can be easily managed and controlled using Nginx configuration files.
You can set cache expiration, size, target URLs for caching, and more.
Nginx's proxy cache operates within a single Nginx server, and techniques such as Nginx clustering or replication are required for scalability and high availability.
It stores temporary cache files on disk, but it does not provide features for long-term data persistence or durability.
Redis is an independent database and caching platform.
It runs on a separate server, and applications connect to Redis to read and write cached data.
It is a general-purpose caching platform capable of caching various types of data.
The types of data that can be cached include strings, lists, sets, sorted sets, hashes, and more.
Redis is directly controlled and managed by programs.
Redis commands are used to manipulate cached data, such as setting, getting, deleting, and setting expiration times.
Problems
First of all, Redis didn't work.
Packages finally installed
Redis , Redis-server , Redis-tools , php-fpm
When I tried to start Redis
sudo service redis-server start
The error that appeared
Part 1
Reading the configuration file, at line 1
>>> 'logfile "/var/log/redis/redis.log"'
Can't open the log file: No such file or directory
Solution: It complains that it cannot access the log configured in redis.conf!
Even without specifying "logfile", it seems to create one automatically, so I set it to "". If truly necessary, it should work normally by configuring the log, permissions, and ownership.
Part 2
# Opening port: bind: Address already in use
Solution: It complains that the port is already in use!
The port initially configured in redis.conf is 6379. For some reason, on Devuan (OpenRC), sudo service redis-server stop also throws an error and doesn't stop. So, to check what is using it, I entered the following:
root@hoge:~# lsof -i :6379
If there's a Redis process running in the background, that's it. Check the PID and kill it.
root@hoge:~# kill -9 <PID>
After this, it should start normally.
Part 3
*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 135
>>> 'slave-serve-stale-data yes'
Bad directive or wrong number of arguments
Solution: I realized that this error usually occurs due to a version mismatch between Redis and the redis.conf file.
Choose the configuration file matching your Redis version from the Redis website and copy-paste it entirely.
Part 4
Failed opening the RDB file dump.rdb (in server root dir /) for saving: Permission denied
6232:M 07 Jul 2023 03:56:39.182 # Background saving error
Solution: It says "Cannot open dump.rdb file~".
Similarly, if an old RDB file remains, Redis might crash midway after starting. I initially thought it was a memory issue, but it wasn't.
This happened after Redis started and I changed the cache destination folder Dir */~ in redis.conf.
Even if you change the cache directory, it seems to try to read the old one, so let's forcibly delete it. Mine was at /var/lib/redis/dump.rdb.
sudo rm /var/lib/redis/dump.rdb
This resolved the Redis-side issues.
Nextcloud Side
root@hoge:~# sudo -u www-data php /var/www/html/nextcloud/occ maintenance:update:htaccess
What you do when updating htaccess.
RedisException: Connection refused in /var/www/html/nextcloud/lib/private/RedisFactory.php:137
~~~~~
Solution: If many errors occur afterwards with a filename, it's an error indicating that Redis is not running correctly or Nextcloud's configuration is wrong and cannot connect to Redis.
Focus on suspecting Redis and Nextcloud's php.config.
I feel like there were other issues, but I think this covers most of them.
Now I can confidently handle Redis in the future.
By the way, I wonder if stacking memory caches would actually slow things down? If it's fast enough up to a certain point, wouldn't the response speed of the communicating server or device become the bottleneck?
It's still uncharted territory, so I'm looking forward to it.
I'm exhausted.
See you.