为了能随时随地学习,所以在家里的服务器上搭了一个私有网盘。
家里的旧笔记本拿来做服务器了,之前已经部署了一些服务了,但是为了物尽其用,同时方便自己保存文件,所以想要搭一个私有的网盘系统。看了很多开源网盘,最终还是选用了NextCloud,虽然很多功能用不上,比如协同工作,但是它能支持app还是很不错的。
NextCloud部署
因为懒得安装php等环境,所以打算直接使用docker部署。
编写启动脚本start-nextcloud.sh:
docker run -d -p 8080:80 \
--name nextcloud \
-v /opt/nextcloud/files:/var/www/html \
--restart=always \
nextcloud
使用nextcloud镜像,并映射到服务器的8080端口,将nextcloud的文件挂载到/opt/nextcloud/目录。
赋予脚本执行权限:
chmod +x start-nextcloud.sh
./start-nextcloud.sh
docker会自动下载nextcloud镜像并完成启动。
之后打开浏览器,输入http://ip:8080进行设置。
输入管理员账号和密码。默认使用sqlite也可以,我使用了mysql,需要提前创建数据库,唯一要注意的是需要使用ifconfig
查看一下docker网卡的地址,填入mysql的服务器地址栏中,否则连接不上。
直接复制文件到网盘目录
之前试用其他网盘时已经上传过一些文件了,所以我需要直接把文件移动到NextCloud的data目录里。
进入data目录可以看到需要进入对应的用户下的files目录,将文件拷贝或移动到该目录后,在网页上并没有看到对应的文件,此时需要执行如下命令:
docker exec nextcloud php occ files:scan --all
提示:
Console has to be executed with the user that owns the file config/config.php
Current user id: 0
Owner id of config.php: 33
Try adding 'sudo -u #33' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u 33' to the docker command (without the single quotes)
根据要求修改一下命令:
docker exec -u 33 nextcloud php occ files:scan --all
最后输出:
Starting scan for user 1 out of 1 (admin)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 184 | 1041 | 00:00:26 |
+---------+-------+--------------+
然后再回到网页上,刷新即可看到拷贝进去的文件了。