引
有人問我何時產(chǎn)生了做這種東西的想法泌霍,其實很早就產(chǎn)生了,最初是在我剛開始接觸入門級路由器(類似網(wǎng)件以及阿蘇斯的入門級)的時候铅鲤,梅林固件上面就有一些離線下載軟件類似 Aria2、迅雷離線下載 Xware(已經(jīng)停止服務),并且當時正值郭佳插手網(wǎng)盤行業(yè)引起一大批網(wǎng)盤服務關閉懒构,出于對個人數(shù)據(jù)的敏感,便開始了解 個人/家庭NAS耘擂。經(jīng)過一番了解后便止步于價格上呵呵呵......(群暉主流型號 DS218+ 價格2500左右)之后便轉向更為經(jīng)濟的 VPS 自建網(wǎng)盤胆剧。
正文
這次因為有網(wǎng)盤的作用,所以需要一個大硬盤的VPS醉冤,同時也要兼顧與國內(nèi)的帶寬速度秩霍,我用的是 Hosthatch 家 1核1G內(nèi)存1T硬盤1Gbps位于 LA 的 VPS。
內(nèi)容簡述
本次教程主要涉及在 Debian9 中安裝 NextCloud蚁阳、Transmission铃绒,并為 NextCloud的 訪問添加 HTTPS 證書。
開啟 Debian9 中的 BBR
這里參考自:Debian 9快速開啟Google BBR的方法螺捐,實現(xiàn)高效單邊加速
- 修改系統(tǒng)變量
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
- 保存生效
sysctl -p
- 查看內(nèi)核是否已開啟BBR
sysctl net.ipv4.tcp_available_congestion_control
#顯示以下即已開啟:
net.ipv4.tcp_available_congestion_control = bbr cubic reno
4颠悬、查看BBR是否啟動
lsmod | grep bbr
#顯示以下即啟動成功:
tcp_bbr 20480 00
NextCloud 的安裝
參考自:How to Install Nextcloud 13 Server on Debian 9
- 系統(tǒng)準備
apt-get update -y
#下面這條需要時間較長,可以不運行
apt-get upgrade -y
- LAMP服務安裝
NextCloud 的運行需要Apache定血、MySQL和PHP
#安裝 Apache 和 MariaDB
apt-get install apache2 mariadb-server -y
安裝完成后運行以下命令來運行 Apache 和MariaDB 并開啟開機啟動
systemctl start apache2
systemctl enable apache2
systemctl start mysql
systemctl enable mariadb
安裝 PHP 以及其他需要的模塊
apt-get install libapache2-mod-php php7.0 php7.0-xml php7.0 php7.0-cgi php7.0-cli php7.0-gd php7.0-curl php7.0-zip php7.0-mysql php7.0-mbstring wget unzip -y
- 配置 MariaDB
數(shù)據(jù)庫安全配置
mysql_secure_installation
配置
Enter current password for root (enter for none): 設置 mysql 的管理密碼
Change the root password? [Y/n] 輸入n
Remove anonymous users? [Y/n] 輸入y
Disallow root login remotely? [Y/n] 輸入y
Remove test database and access to it? [Y/n] 輸入y
Reload privilege tables now? [Y/n] 輸入y
登陸 MariaDB 控制臺進行配置
mysql -u root -p
#輸入上面設置的密碼
CREATE DATABASE nextclouddb;
#創(chuàng)建 nextcloud 的數(shù)據(jù)庫,請務必帶上分號澜沟;運行
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'mypassword';
#mypassword 字段請?zhí)鎿Q為數(shù)據(jù)庫密碼(非管理密碼)
GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextcloud'@'localhost';
#向Nextcloud數(shù)據(jù)庫授予權限
FLUSH PRIVILEGES;
#重載privileges table
\q
#離開控制臺
- 安裝 NextCloud
獲取最新版本的NextCloud
wget https://download.nextcloud.com/server/releases/latest.zip
解壓
unzip latest.zip
將解壓得到的文件夾移到 /var/www/html/
mv nextcloud /var/www/html/
為 nextcloud 文件夾提供適當?shù)臋嘞?/p>
chown -R www-data:www-data /var/www/html/nextcloud
為NextCloud創(chuàng)建一個apache虛擬主機文件
nano /etc/apache2/sites-available/nextcloud.conf
寫入以下內(nèi)容(不必太過介意其中的參數(shù)灾票,后面 HTTPS 的配置還會修改)
完成后Ctlr+O、回車茫虽、Ctlr+X刊苍、回車
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot "/var/www/html/nextcloud"
ServerName 192.168.0.187
<Directory "/var/www/html/nextcloud/">
Options MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /var/log/apache2/nextcloud_access.log
ErrorLog /var/log/apache2/nextcloud_error.log
</VirtualHost>
啟用NextCloud虛擬主機文件并禁用默認虛擬主機文件
a2dissite 000-default
a2ensite nextcloud
重啟 Apache 以應用改變
systemctl restart apache2
- 開放防火墻端口
安裝防火墻管理軟件(iptable 真尼瑪難用hhh)
apt-get install ufw -y
開啟并配置 ufw
ufw enable
ufw allow 80
ufw allow 22
- NextCloud 數(shù)據(jù)庫以及管理員賬戶配置
在瀏覽器輸入你服務器的公網(wǎng) ip 地址就可以訪問你剛剛搭建好的 NextCloud 了,初次訪問需要配置 admin 賬號以及數(shù)據(jù)庫訪問密碼席噩,其他照填就行班缰。
為 NextCloud 配置 HTTPS 證書
參考文章:How To Secure Apache with Let's Encrypt on Debian 9
這里你需要有一個自己注冊的域名,你可以去 www.name.com 買悼枢,或者注冊一個免費但需要隔一段時間就要驗證的 www.freenom.com 埠忘;購買后將域名解析到 VPS 的公網(wǎng)地址。
- 安裝 Certbot
這里的認證我們使用 Let's Encrypt 簽發(fā)的免費證書,第一步是在服務器上安裝Certbot軟件莹妒。默認情況下名船,Debian軟件存儲庫中不提供Certbot,為了使用apt下載軟件旨怠,您需要將backports存儲庫添加到sources.list
文件中渠驼。
打開sources.list
并在最后一行寫入以下內(nèi)容
nano /etc/apt/sources.list
#寫入內(nèi)容
deb http://ftp.debian.org/debian stretch-backports main
Save and close the file by pressing CTRL+X, Y, then ENTER, then update your package lists:(其實直接看參考文章就行了,瞧瞧這?簡單到爆炸的英語)
apt update
使用特定的源來安裝 Certbot :
apt install python-certbot-apache -t stretch-backports
- 配置 SSL證書
打開網(wǎng)站虛擬化配置文件鉴腻,替換ServerName
后的值為指向這臺vps的域名
nano /etc/apache2/sites-available/nextcloud.conf
#修改例子
...
ServerName example.com;
...
保存后運行命令檢查配置文件的語法
apache2ctl configtest
#正常輸出的顯示
Syntax OK
重啟 Apache 以加載新配置
systemctl reload apache2
現(xiàn)在 Certbot 能夠讀取配置了迷扇。
- 防火墻開放443端口
ufw allow 443
- 獲取 SSL證書
Certbot提供了多種通過插件獲取SSL證書的方法。Apache插件將負責重新配置Apache并在必要時重新加載配置爽哎。請運行以下命令:
#其中的 example.com 換成自己的域名
certbot --apache -d example.com
第一次運行時蜓席,他會讓你輸入你的郵箱來讓你同意使用協(xié)議并驗證你使用的域名是否屬于你。
然后會讓你選擇是否重定向 HTTP 流量到 HTTPS 中
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
#輸入2并回車
輸入選擇并回車之后课锌,程序就會進行配置厨内,成功后會告訴你你的證書被放在哪里、證書過期時間以及其他雜七雜八的信息渺贤。
現(xiàn)在你已經(jīng)可以通過安全的 HTTPS 協(xié)議來訪問自己的 NextCloud 了雏胃。
- Verifying Certbot Auto-Renewal(我懶了)
Let's Encrypt's certificates are only valid for ninety days. This is to encourage users to automate their certificate renewal process. The certbot
package we installed takes care of this for us by adding a renew script to /etc/cron.d.
This script runs twice a day and will automatically renew any certificate that's within thirty days of expiration.
To test the renewal process, you can do a dry run with certbot
:
certbot renew --dry-run
If you see no errors, you're all set. When necessary, Certbot will renew your certificates and reload Apache to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.
安裝 Transmission
我裝 Transmission 主要是用來玩 PT(PT下載,BT的一種志鞍,不過較為隱秘)瞭亮,但如果你要在國外下載公開盜版 BT資源的話,你的 VPS 會面臨投訴被 BAN 的風險述雾。
- 安裝 Server 端
apt install transmission-daemon --install-suggests
似乎這種安裝方法存在依賴編譯的過程街州,時間比較久,大概半個多到一個小時玻孟,這個時間可以出去買個奶茶吃個夜宵啥的唆缴。
- 配置
#停止服務
service transmission-daemon stop
#打開配置文件配置
nano /etc/transmission-daemon/settings.json
#更改以下參數(shù)的值
#替換為遠程連接的密碼
"rpc-password":"yourpassword",
#遠程管理訪問端口
"rpc-port": 9999,
#登陸用戶名
"rpc-username": "username",
#關閉遠程連接白名單
"rpc-whitelist-enabled": false,
#啟動服務
service transmission-daemon start
默認下載文件夾:/var/lib/transmission-daemon/downloads
現(xiàn)在你可以通過網(wǎng)頁端管理 Transmission 了,也可以下載 Client 端獲取更舒適的界面體驗(Transmission 官網(wǎng)獲仁螋帷)面徽。
網(wǎng)頁地址:ip地址:端口
在 NextCloud 中添加 Transmission 的下載文件夾
- 為 NextCloud 安裝外部儲存插件
- 點擊右上角的圓圈頭像上,點擊展開菜單「應用」
- 找到 “External storage support” 并啟用
- 點擊右上角的圓圈頭像上匣掸,點擊展開菜單「設置」
- 點擊左側菜單欄中的「管理」中的「外部儲存」
- 「目錄名稱」任意填寫趟紊,「外部儲存」選擇本地,「配置」
填寫/var/lib/transmission-daemon/downloads
碰酝,「可用于」選擇admin
用戶組或用戶 - 回到首頁「文件」頁面你就會看到你剛才添加的文件夾了霎匈,但里面的東西你只有讀取權限,這個是數(shù)據(jù)庫用戶組
www-data
對 Transmission 創(chuàng)建的文件/文件夾沒有寫入/執(zhí)行權限造成的送爸,將 Transmission 文件夾及其下的文件設置成 5777 應該就行了(我不知道也沒試過hhh)
- 使用
大致流程就是在 Transmission 上下載完成后铛嘱,在 NextCloud 里頭在線播放就行了暖释,但有時候會下到?jīng)]有配字幕的視頻文件,這里推薦一個軟件墨吓,可以置頂單純播放字幕文件球匕,挺好用的,來源:[Windows] Penguin Subtitle Player【獨立字幕播放器】【支持.srt, .ssa, .ass字幕及透明背景】
你也可以直接搜名字下載帖烘。
題外話
如果說要搭建離線下載平臺的話亮曹,更好的下載工具是 Aria2,但它不能用于 PT下載(具體為什么我也沒去了解秘症,反正我的PT站不允許)照卦,所以實用性就大打折扣了,如果你想用國外 VPS 來加速你下載國外的資源速度的話乡摹,有更簡單的方法窄瘟,就是給下載工具如IDM或者FDM套一層代理就行了,這種方法我后續(xù)會更新在我另一篇文章 教你通過軟件創(chuàng)建HTTP代理并連接 中趟卸,具體什么時候,我也不知道氏义,過幾個星期吧hhh锄列,最近太忙忙忙忙忙忙忙忙忙忙忙忙忙忙忙忙了(都是假的,就是懶hhh)
現(xiàn)在北京時間2018.11.1——3:13:52
不知不覺就到了11月惯悠,今年又快過去了邻邮,想來今年過得真快,呵呵呵呵我是不是重復兩次快了......話說回一年多的大學生活來克婶,看到了各種各樣的人筒严,也還是印證了那句話「鳥子大了什么林子都有」,人和人之間的關系是那么的「薄」情萤,有多少是因為有了「接觸」才產(chǎn)生的「關系」鸭蛙,可又有多少為了這「關系」而不遺余力地創(chuàng)造著「接觸」,得好好珍惜一直在身邊的人呀筋岛。
送給我娶视,也送給所有看到這里的人。
話說真的會有人看到這里嗎睁宰?
不知道