docker搭建nextcloud 个人私有nas网盘
1.修改yum源
(1)备份原来的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
(2)下载阿里的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
(3)安装相关插件
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
(4)添加docker-ce源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2.安装docker-ce,配置docker仓库
yum install -y docker
tee /etc/docker/daemon.json <<-‘EOF’
{
“insecure-registries” : [“0.0.0.0/0”],
“registry-mirrors”: [“https://bytkgxyr.mirror.aliyuncs.com”,“https://registry.docker-cn.com”,“http://hub-mirror.c.163.com”]
}
EOF
systemctl restart docker
systemctl enable docker
3.安装docker-compose
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-uname -s
-uname -m
> /usr/local/bin/docker-compose
chmod 777 /usr/local/bin/docker-compose
docker-compose --version
4.拉取相关docker镜像
docker pull redis:latest
docker pull mariadb:latest
docker pull nextcloud:latest
5.编写docker-compose 搭建
mkdir /root/nextcloud && cd /root/nextcloud
vim docker-compose.yaml
---
version: '3.2'
networks:
default:
name: nextcloud
services:
app:
image: nextcloud:latest
restart: unless-stopped
volumes:
- ./app:/var/www/html
environment:
- MYSQL_PASSWORD=nextcloud_password # 按需修改
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
ports:
- 81:80 # 按需修改
networks:
- default
cache:
image: redis
restart: unless-stopped
expose:
- "6379" # 可用此默认。因为这是暴露而不是映射
volumes:
- ./cache:/data
command: redis-server --requirepass 'redis_password' # 按需修改
networks:
- default
db:
image: mariadb:latest
restart: unless-stopped
# 下面的command与官网略有不同。它将有助于避免MYSQL数据库的4047报错。
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-file-per-table=1 --skip-innodb-read-only-compressed
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=nextcloud_mysql_password # 按需修改
- MYSQL_PASSWORD=nextcloud_password # 按需修改
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
networks:
- default
docker-compose up -d
5.配置redis(先进入游览器 http://ip:81 配置完再配置redis)
cat app/config/config.php
<?php
$CONFIG = array (
'htaccess.RewriteBase' => '/',
// 'memcache.local' => '\\OC\\Memcache\\APCu', //注释这行
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.distributed' => '\\OC\\Memcache\\Redis', // 分布式缓存使用Redis
'memcache.locking' => '\\OC\\Memcache\\Redis', // 启用Redis缓存的文件锁
'redis' => array(
'host' => 'cache', // 这里和mariadb的逻辑相同,填写容器links时映射的主机名
'port' => 6379,
'password' => 'redis_password' // 这是之前在配置docker-compose时配置的redis密码
),
docker-compose down && docker-compose up -d
设置→管理→基本设置 Cron
宿主机:vim /etc/crontab
*/5 * * * * root docker exec -u 33 nextcloud_app_1 php -f /var/www/html/cron.php 2>&1 /dev/null
#nextcloud 后台任务配置