「玩轉樹莓派」搭建屬於自己的雲盤服務
- 2019 年 12 月 9 日
- 筆記
前言
最近在整理硬碟中的一些影片文檔,雖然之前進行了分類,但時間一長,還是有點亂,找個東西得翻找半天。於是乎,就有了下面這個小玩意,自建雲盤服務。
軟硬清單
- 外接硬碟一枚(用於掛載)
- 寬頻、路由器(家中常備)
- SSH連接工具(SecureCRT,Xshell)
- Nginx、PHP、owncloud、ngrok
- 裝好系統的樹莓派 3B+ 一隻(充電器、CPU散熱風扇等)
配置環境
安裝 Nginx
sudo apt-get update sudo apt-get install nginx sudo service nginx start
安裝 PHP
# owncloud 需要的基礎庫,必須要安裝 sudo apt-get install php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-mcrypt php7.0-cgi sudo apt-get install php7.0-intl php7.0-mysql php7.0-zip php7.0-dom php7.0-mbstring sudo service php7.0-fpm restart
安裝 MySql
sudo apt-get install mysql-server sudo apt-get install mysql-client
安裝完成以後進入資料庫,無需輸入密碼:
sudo mysql -u root -p
修改密碼:
sudo systemctl restart mysql sudo systemctl status mysql
雲盤安裝
下載最新資源,國外網站,可能略慢,請耐心等待:
wget https://download.owncloud.org/community/owncloud-10.1.1.tar.bz2
下載完成,解壓文件:
sudo tar -xvf owncloud-10.1.1.tar.bz2
雲盤 owncloud 配置文件:
server { # 80埠被佔用,這裡使用8081 listen 8081 default_server; listen [::]:8081 default_server; # 安裝目錄 root /home/pi/owncloud; index index.php index.htm; client_max_body_size 10G; fastcgi_buffers 64 4K; gzip off; rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect; rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect; rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect; index index.php; error_page 403 /core/templates/403.php; error_page 404 /core/templates/404.php; location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ ^/(?:.htaccess|data|config|db_structure.xml|README){ deny all; } location / { # The following 2 rules are only needed with webfinger rewrite ^/.well-known/host-meta /public.php?service=host-meta last; rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last; 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_pass unix:/run/php/php7.0-fpm.sock; fastcgi_split_path_info ^(.+.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; #ifastcgi_pass php-handler; } location ~* .(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { expires 30d; # Optional: Don't log access to assets access_log off; } }
配置完成後,進入安裝介面,輸入管理員帳號密碼以及資料庫相關資訊,點擊進入下一步即可安裝成功:

初始頁面:

內網穿透
如果你想要在非區域網中訪問,就需要加一個穿透,來訪問我們內網的服務。
首先,我們要把之前生成的 ngrok 客戶端(linux_arm)上傳到樹莓派:
然後,創建一個 ngrok.yml 配置文件:
server_addr: "ngrok.52itstyle.vip:4443" trust_host_root_certs: false tunnels: owncloud: proto: http: "8081"
啟動服務:
./ngrok -config=ngrok.yml start owncloud
SSH是要關閉的,所以要使 ngrok 後台運行:
# 首先安裝screen sudo apt-get install screen
之後運行:
screen -S 任意名字(例如:keepngork)
然後運行ngrok啟動命令:
./ngrok -config=ngrok.yml start owncloud
最後按快捷鍵:
ctrl+A+D
如果出現以下,既可以保持ngrok後台運行。
[detached from 14930.keepngork]
最後,配置信任域名,否則穿透域名無法訪問:
sudo vim config/config.php
加入代理域名:
array ( 0 => '192.168.1.157:8081', 1 => 'owncloud.ngrok.52itstyle.vip', ),
演示地址:http://owncloud.ngrok.52itstyle.vip
前台:

後台:

音頻播放:

小結
雲盤在內網體驗還是蠻好的,搜索、收藏、分享,功能很齊全。只是加了代理穿透以後,上傳大文件有點慢。當然了如果想正兒八經的使用,最好掛載一個 T 級別的硬碟。
參考
https://blog.52itstyle.vip/archives/3987/