Python学习教程:玩转树莓派—搭建属于自己的云盘服务
最近在整理硬盘中的一些视频文档,虽然之前进行了分类,但时间一长,还是有点乱,找个东西得翻找半天。于是我就想着能不能子做个小玩意,意,自建云盘服务。
软硬清单外接硬盘一枚(用于挂载)宽带、路由器(家中常备)SSH连接工具(SecureCRT,Xshell)Nginx、PHP、owncloud、ngrok装好系统的树莓派 3B+ 一只(充电器、CPU散热风扇等)配置环境安装 Nginx
sudoapt-getupdatesudoapt-getinstallnginxsudoservicenginxstart
安装 PHP
#owncloud需要的基础库,必须要安装sudoapt-getinstallphp7.0-fpmphp7.0-cliphp7.0-curlphp7.0-gdphp7.0-mcryptphp7.0-cgisudoapt-getinstallphp7.0-intlphp7.0-mysqlphp7.0-zipphp7.0-domphp7.0-mbstringsudoservicephp7.0-fpmrestart
安装 MySql
sudoapt-getinstallmysql-serversudoapt-getinstallmysql-client
安装完成以后进入数据库,无需输入密码:
sudomysql-uroot-p
修改密码:
sudosystemctlrestartmysqlsudosystemctlstatusmysql云盘安装
下载最新资源,国外网站,可能略慢,请耐心等待:
wgethttps://download.owncloud.org/community/owncloud-10.1.1.tar.bz2
下载完成,解压文件:
sudotar -xvf owncloud-10.1.1.tar.bz2
云盘 owncloud 配置文件:
server{ #80端口被占用,这里使用8081listen8081default_server;listen[::]:8081default_server; #安装目录root/home/pi/owncloud;indexindex.php index.htm;client_max_body_size10G;fastcgi_buffers644K;gzipoff;rewrite^/caldav(.*)$/remote.php/caldav$1redirect;rewrite^/carddav(.*)$/remote.php/carddav$1redirect;rewrite^/webdav(.*)$/remote.php/webdav$1redirect;indexindex.php;error_page403/core/templates/403.php;error_page404/core/templates/404.php;location=/robots.txt{allowall;log_not_foundoff;access_logoff;}location~^/(?:\.htaccess|data|config|db_structure\.xml|README){denyall;}location/{#Thefollowing2rulesareonlyneededwithwebfingerrewrite^/.well-known/host-meta/public.php?service=host-metalast;rewrite^/.well-known/host-meta.json/public.php?service=host-meta-jsonlast;rewrite^/.well-known/carddav/remote.php/carddav/redirect;rewrite^/.well-known/caldav/remote.php/caldav/redirect;rewrite^(/core/doc/[^\/]+/)$$1/index.html;try_files$uri$uri//index.php;}location~\.php(?:$|/){fastcgi_passunix:/run/php/php7.0-fpm.sock;fastcgi_split_path_info^(.+\.php)(/.+)$;includefastcgi_params;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramPATH_INFO$fastcgi_path_info;#ifastcgi_passphp-handler;}location~*\.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)${expires30d;#Optional:Don'tlogaccesstoassetsaccess_logoff;}}
配置完成后,进入安装界面,输入管理员账号密码以及数据库相关信息,点击进入下一步即可安装成功:
初始页面:
内网穿透如果你想要在非局域网中访问,就需要加一个穿透,来访问我们内网的服务。
首先,我们要把之前生成的 ngrok 客户端(linux_arm)上传到树莓派:
然后,创建一个 ngrok.yml 配置文件:
server_addr:"ngrok.52itstyle.vip:4443"trust_host_root_certs:falsetunnels:owncloud:proto:http:"8081"
启动服务:
./ngrok-config=ngrok.ymlstartowncloud
SSH是要关闭的,所以要使 ngrok 后台运行:
#首先安装screensudoapt-getinstallscreen
之后运行:
screen-S任意名字(例如:keepngork)
然后运行ngrok启动命令:
./ngrok-config=ngrok.ymlstartowncloud
最后按快捷键:
ctrl+A+D
如果出现以下,既可以保持ngrok后台运行。
[detachedfrom14930.keepngork]
最后,配置信任域名,否则穿透域名无法访问:
sudovimconfig/config.php
加入代理域名:
array(0=>'192.168.1.157:8081',1=>'owncloud.ngrok.52itstyle.vip',),
前台:
后台:
音频播放:
小结云盘在内网体验还是蛮好的,搜索、收藏、分享,功能很齐全。只是加了代理穿透以后,上传大文件有点慢。当然了如果想正儿八经的使用,最好挂载一个 T 级别的硬盘。
更多的Python学习教程也会继续为大家更新!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。