Raspberry Pi 5 (8GB) で運用する Nextcloud が遅い原因を調査し、Redis を導入して改善した話/I am running a self-hosted Nextcloud instance on a Raspberry Pi 5 (8GB) using Docker and NVMe storage.
Raspberry Pi 5 (8GB) で運用する Nextcloud が遅い原因を調査し、Redis を導入して改善した話
自宅鯖環境として Raspberry Pi 5 (8GB) 上で Nextcloud を運用しています。 ストレージには NVMe SSD を使用し、Docker 上で Nextcloud、PostgreSQL、Redis などを構成しています。
しかし実際に運用を始めると、ブラウザから Nextcloud へアクセスした際に、 ログイン後の画面表示やファイル一覧の読み込みが思っていたより遅く感じられました。
環境
- Raspberry Pi 5 (8GB)
- Ubuntu Server
- Docker
- Nextcloud 35
- PostgreSQL
- Redis
- NVMe SSD
- Caddy
- Tailscale
最初に疑ったこと
最初は Raspberry Pi の性能不足を疑いました。 しかし Docker の統計情報を確認すると CPU 使用率は低く、 メモリにも十分な余裕がありました。
docker stats
また、データベースには PostgreSQL を利用しており、 ストレージも NVMe SSD を使用していたため、 ハードウェア性能そのものが原因ではなさそうでした。
Redis が利用されていなかった
Nextcloud の設定を確認したところ、 APCu は有効になっていましたが Redis が利用されていませんでした。
docker exec nextcloud php occ config:system:get memcache.local
docker exec nextcloud php occ config:system:get memcache.locking
確認結果:
memcache.local = APCu
memcache.locking = 未設定
Redis コンテナ自体は起動していましたが、 Nextcloud 側の設定が不足していたため実際には利用されていませんでした。
Redis 接続の確認
まず Redis コンテナへ到達できるか確認しました。
docker exec nextcloud getent hosts redis
続いて PHP から Redis へ接続できるかテストしました。
docker exec nextcloud php -r '
$redis = new Redis();
$redis->connect("redis",6379,2);
echo "OK\n";
'
問題なく接続できたため、 Docker ネットワークや Redis サーバー側には問題がないことが分かりました。
config.php を修正
Nextcloud の config.php に以下の設定を追加しました。
'redis' => [
'host' => 'redis',
'port' => 6379,
],
'memcache.locking' => '\OC\Memcache\Redis',
設定中に閉じ括弧を誤って重複記述してしまい、 次のエラーが発生しました。
Parse error: Unmatched ')'
余分な括弧を削除することで問題は解決しました。
動作確認
docker exec nextcloud php occ config:system:get memcache.locking
結果:
\OC\Memcache\Redis
これで Redis が正常に有効化されました。
Redisとは何だったのか
今回の調査を始めるまで、Redis が具体的に何をするソフトウェアなのか 正直よく理解していませんでした。
Redis コンテナが起動していたため、当然利用されているものだと思っていました。 しかし実際には Nextcloud 側の設定が不足しており、 Redis はまったく活用されていませんでした。
Redis はメモリ上で動作する高速なデータストアで、 Nextcloud では主にキャッシュやファイルロック管理に利用されます。
- APCu → ローカルキャッシュ
- Redis → ファイルロック管理(Transactional File Locking)
- PostgreSQL → データベース
PHP脆弱性対応とシステム更新
Nextcloud の調査と並行して、Ubuntu Server のシステムアップデートも実施しました。 Cockpit の管理画面から更新を行い、 PHP を含む各種パッケージを最新状態へ更新しました。
サービス構築だけでなく、 セキュリティアップデートを継続的に実施することの重要性を改めて認識しました。
Portainer のアップデート
Docker コンテナ管理には Portainer を利用しています。 今回のメンテナンスに合わせて Portainer も最新版へアップデートしました。
アップデート後も既存のコンテナ構成やボリュームは維持され、 問題なく運用を継続できています。
nano による直接編集
今回の設定変更では Docker ボリューム内の config.php を直接編集する必要がありました。 これまで Portainer や Dockge の Web UI が中心だったため、 Linux 上での直接編集は良い学習機会となりました。
作業中には PHP の構文エラーを発生させてしまいましたが、 エラーメッセージを読みながら原因を特定し、 無事に復旧できました。
今回学んだこと
- Redis コンテナを起動しただけでは Nextcloud は利用しない
- config.php に Redis 設定を追加する必要がある
- APCu と Redis の併用が推奨構成
- Linux の基本的な設定ファイル編集スキルは重要
- 定期的なシステム更新とセキュリティ対策が必要
- Raspberry Pi 5 でも十分実用的な Nextcloud 環境を構築できる
まとめ
今回のトラブルシューティングでは単に Nextcloud の動作速度を改善しただけではありませんでした。 Redis の役割を学び、Docker ネットワークを確認し、 設定ファイル編集やシステム更新についても理解を深めることができました。
最終的な原因は Raspberry Pi 5 の性能不足ではなく、 Redis が Nextcloud に設定されていなかったことでした。
サーバーは構築して終わりではなく、 継続的な運用・監視・チューニングが重要であることを改めて実感しました。
なお、本記事の構成および検証は、あくまでもテスト環境において実施したものです。
Investigating Slow Nextcloud Performance on Raspberry Pi 5 and Improving It with Redis
I run Nextcloud as part of my home lab environment on a Raspberry Pi 5 (8GB) equipped with an NVMe SSD. The services are deployed using Docker and include Nextcloud, PostgreSQL, Redis, Caddy, and Tailscale.
Although the system specifications seemed sufficient, the Nextcloud web interface felt slower than expected, especially when displaying the dashboard after login or loading file lists.
Environment
- Raspberry Pi 5 (8GB)
- Ubuntu Server
- Docker
- Nextcloud 35
- PostgreSQL
- Redis
- NVMe SSD
- Caddy
- Tailscale
Initial Investigation
My first assumption was that the Raspberry Pi lacked sufficient performance. However, Docker statistics showed low CPU usage and plenty of available memory.
Since PostgreSQL and an NVMe SSD were already in use, the hardware itself did not appear to be the bottleneck.
Redis Was Not Actually Being Used
After reviewing the Nextcloud configuration, I discovered that APCu was enabled but Redis was not configured. Although the Redis container was running, Nextcloud was not using it.
Verifying Redis Connectivity
I verified that the Nextcloud container could reach the Redis container and successfully established a PHP connection. This confirmed that both Docker networking and Redis itself were functioning correctly.
Updating the Configuration
I added the Redis configuration and enabled Redis-based file locking in Nextcloud's config.php.
During editing, I accidentally introduced a PHP syntax error by adding an extra closing parenthesis. After correcting the mistake, Nextcloud started successfully.
What I Learned About Redis
Before this investigation, I knew Redis existed but did not fully understand its role. I incorrectly assumed that running a Redis container automatically meant Nextcloud was using it.
Redis is an in-memory data store commonly used by Nextcloud for caching and file-lock management.
- APCu → Local cache
- Redis → Transactional file locking and distributed cache functions
- PostgreSQL → Primary database
Additional Maintenance Work
While troubleshooting Nextcloud, I also updated Ubuntu Server packages, including PHP, through Cockpit. In addition, I upgraded Portainer to the latest version.
These tasks reminded me that running a server is not simply about building services. Ongoing maintenance and security updates are equally important.
Lessons Learned
- Starting a Redis container does not automatically enable Redis in Nextcloud.
- Correct configuration in config.php is required.
- Using APCu together with Redis is considered best practice.
- Basic Linux file-editing skills remain valuable even when using web-based management tools.
- Regular updates and security maintenance are essential.
- A Raspberry Pi 5 can run Nextcloud very effectively when configured properly.
Conclusion
The real cause of the slow performance was not insufficient hardware performance. Instead, Redis had never been configured within Nextcloud despite the container being available.
This experience taught me that building a server is only the beginning. Monitoring, tuning, maintenance, and understanding each component's role are critical parts of long-term operation.
All testing and verification described in this article were performed in a non-production test environment.
コメント
コメントを投稿