原文我在微信公眾號寫的,現(xiàn)在搬過來讓更多人看到
可以支持下我的網(wǎng)站嗎
起因:手機空間不夠
經(jīng)過:在搭建環(huán)境時抓狂
結(jié)果:放棄
哈哈哈逗你玩的
那么接下來進入正文~
首先給大家解釋一下NAS是什么(畢竟看我文章的又不是什么技術(shù)大牛)
NAS(Network Attached Storage:網(wǎng)絡(luò)附屬存儲)按字面簡單說就是連接在網(wǎng)絡(luò)上,具備資料存儲功能的裝置,因此也稱為“網(wǎng)絡(luò)存儲器”。它是一種專用數(shù)據(jù)存儲服務(wù)器。它以數(shù)據(jù)為中心,將存儲設(shè)備與服務(wù)器徹底分離,集中管理數(shù)據(jù),從而釋放帶寬、提高性能、降低總擁有成本、保護投資。其成本遠遠低于使用服務(wù)器存儲,而效率卻遠遠高于后者。目前國際著名的NAS企業(yè)有Netapp、EMC、OUO等
復制百度百科的hhh
NAS就是私有云,公有云有百度網(wǎng)盤,騰訊微云等,私有云純粹就是自己用的。
我主要是因為手機空間不足,拍完的照片必須馬上移動到別的地方,還有我拿不住手機的特性,一不小心就可能讓它壯烈殉職。。。
正好家里有一臺在角落吃灰的樹莓派,那么就來動工吧!
1.將樹莓派掛到路由器旁邊
因為我的樹莓派已經(jīng)有系統(tǒng)了,所以在這里不說刷入系統(tǒng)的步驟。
找到一根網(wǎng)線,一個充電頭,一個充電線,一個U盤(其實這里應(yīng)該是移動硬盤,但是我沒有)
然后把網(wǎng)線連到樹莓派的網(wǎng)口和路由器的LAN口,接上電源。
第一步就完成了!
2.選網(wǎng)盤軟件
現(xiàn)在在Linux上的網(wǎng)盤大概有owncloud,nextcloud,seafile
nextcloud是owncloud原團隊再做的
所以它們倆選一個就可以了。
我看了這個文章
Seafile和Nextcloud相比較哪個好用
http://www.yizu.org/archives/690/
根據(jù)我的需求類比再三,最終選擇了seafile
這是噩夢的開始?我開始高興的下載seafile系統(tǒng)
3.搭建Seafile環(huán)境
來到seafile的官網(wǎng)
https://www.seafile.com/home/
嗯雖然是有付費的企業(yè)版,但也有免費的個人版。
點擊下載
在服務(wù)器端選擇Raspberry PI(樹莓派)的Latest version
到它的Github界面
可以看到它現(xiàn)在已經(jīng)更新到了7.0.4
那么就下載
seafile-server_7.0.4_stable_pi.tar.gz
然后想辦法把它傳到樹莓派的U盤里
(U盤必須是EXT4,不然安裝不了)
我把這個文件放到服務(wù)器上然后用Curl傳到樹莓派的
接下來連接樹莓派的SSH
首先確保樹莓派的SSH開啟(新樹莓派系統(tǒng)boot下放一個名字叫ssh的空文件)
接下來打開路由器的控制界面
找到raspberrypi,看它的IP地址
這里是192.168.31.211
那么在putty輸入這個IP,就能訪問樹莓派了,樹莓派初始用戶名和密碼是pi,raspberry
先輸入sudo -s變成管理員
接下來開始掛載U盤
root@raspberrypi:~# fdisk -lDisk/dev/ram0: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram1: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram2: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram3: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram4: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram5: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram6: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram7: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram8: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram9: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram10: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram11: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram12: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram13: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram14: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/ram15: 4 MiB, 4194304 bytes, 8192 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 4096 bytesI/Osize (minimum/optimal): 4096 bytes / 4096 bytesDisk/dev/mmcblk0: 7.4 GiB, 7901020160 bytes, 15431680 sectorsUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisklabeltype: dosDiskidentifier: 0x72b43211DeviceBoot? Start? ? ? End? Sectors? Size Id Type/dev/mmcblk0p18192? 532480? 524289? 256M? c W95 FAT32 (LBA)/dev/mmcblk0p2540672 15431679 14891008? 7.1G 83 LinuxDisk/dev/sda: 60 GiB, 64382566400 bytes, 125747200 sectorsDiskmodel: Flash DiskUnits:sectors of 1 * 512 = 512 bytesSectorsize (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisklabeltype: dosDiskidentifier: 0xcfd906efDeviceBoot Start? ? ? End? Sectors Size Id Type/dev/sda1??*?????2048?125747199?125745152??60G??c?W95?FAT32?(LBA)root@raspberrypi:~#?mkdir?/heheroot@raspberrypi:~#?mount?/dev/sda1 /hehe
具體的掛載過程不再闡述,自己百度
然后將seafile搬到U盤并解壓
cd /heheweget?http://filedrop.boxpaper.club/seafile-server_7.0.4_stable_pi.tar.gztar -xzvf seafile-server_7.0.4_stable_pi.tar.gzcd seafile-server-7.0.4
先安裝點必要的庫
apt-getupdateapt-getinstallpython2.7libpython2.7python-setuptools?python-ldap?python-urllib3?sqlite3?python-requests
接著去運行安裝程序
./setup-seafile.sh
服務(wù)器名隨便填
域名就填0.0.0.0
保存位置不變(/hehe/seafile-data)
端口不變
然后一路Enter
(抱歉這里沒有截圖)
那就看看官方給的配置說明
Seafile配置選項
選項描述注意
服務(wù)器名稱此Seafile服務(wù)器的名稱3-15個字符,僅允許使用英文字母,數(shù)字和下劃線('_')
服務(wù)器IP或域此服務(wù)器使用的IP地址或域名Seafile客戶端程序?qū)⑹褂么说刂吩L問服務(wù)器
Seafile數(shù)據(jù)目錄Seafile將您的數(shù)據(jù)存儲在此目錄中。默認情況下,它將放在當前目錄中。隨著您將越來越多的數(shù)據(jù)放入Seafile,此目錄的大小將會增加。請選擇具有足夠可用空間的磁盤分區(qū)。
文件服務(wù)器端口Seafile文件服務(wù)器使用的TCP端口默認值為8082.如果已被其他服務(wù)使用,則可以將其設(shè)置為其他端口。
安裝完成了就可以啟動了
先增大文件打開數(shù)量
ulimit-n?30000
接下來啟動服務(wù)
./seafile.shstart./seahub.shstart
在啟動seahub時會要求你創(chuàng)建管理員,輸入郵箱與密碼,設(shè)置了記好
不出意外你現(xiàn)在應(yīng)該可以在8000端口找到它
(我半天都沒有安裝好,最后原來是U盤的格式問題,用SSH居然就好了
還有那個開機掛載盤,我弄錯兩次害得它啟動不了,最后不敢開機自動掛載了,手動吧。。。)
接著放出seafile的重啟與關(guān)閉命令
#關(guān)閉./seahub.shstop./seafile.shstop#重啟./seafile.sh restart./seahub.sh restart
以上步驟都可以在下方鏈接找到
https://manual.seafile.com/deploy/using_sqlite.html
4.綁定域名
這一步還挺關(guān)鍵的,決定你是否能在外網(wǎng)訪問樹莓派
我的寬帶給的是公網(wǎng)IP,內(nèi)網(wǎng)穿透先不考慮
首先在路由器ddns綁定一個別的域名
如圖
我使用了3322的動態(tài)域名解析服務(wù)
免費的。。。
然后去把自己的域名設(shè)置CNAME解析,解析到那個3322的動態(tài)域名,
這樣靜止的域名就有了動態(tài)IP
(我騰訊云注冊的域名)
接下來在路由器設(shè)置端口轉(zhuǎn)發(fā)
我圖省事直接設(shè)置DMZ主機,讓外網(wǎng)的所有訪問都到樹莓派
接下來訪問你設(shè)置的 http://域名:8000 應(yīng)該也有了
5.安裝Nginx并設(shè)置SSL
好倒是好了,可是我域名證書都下來了,還用著http,豈不是降低檔次!
(免費域名證書自己找)
那么該配置Nginx和反向代理了。
首先安裝nginx
sudo apt-getinstall nginxsudo /etc/init.d/nginx start
現(xiàn)在在樹莓派80端口應(yīng)該會有nginx的歡迎頁面:Welcome to Nginx!
開始配置ssl和反向代理
創(chuàng)建并寫入/etc/nginx/sites-available/seafile.conf
nano/etc/nginx/sites-available/seafile.conf
server{listen80;rewrite ^https://$http_host$request_uri?permanent;# force redirect http to httpsserver_tokensoff;? ? }server{listen443ssl;sslon;ssl_certificate/etc/nginx/sites-available/ct/1_moe.boxpaper.club_bundl$//設(shè)置成你自己的域名根證書????????ssl_certificate_key?/etc/nginx/sites-available/ct/2_moe.boxpaper.club.k$//設(shè)置成你自己的域名私鑰ssl_protocols TLSv1 TLSv1.1TLSv1.2;ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;ssl_prefer_server_cipherson;ssl_session_cacheshared:SSL:10m;ssl_session_timeout10m;server_tokensoff;location/ {proxy_passhttp://127.0.0.1:8000;//設(shè)置成你自己的proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Host$server_name;proxy_set_headerX-Forwarded-Proto https;access_log/var/log/nginx/seahub.access.log;error_log/var/log/nginx/seahub.error.log;proxy_read_timeout1200s;client_max_body_size0;? ? ? ? }# If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI),# which is not recommended, you should use the following config for location `/`.##? ? location / {#? ? ? ? fastcgi_pass? ? 127.0.0.1:8000;#? ? ? ? fastcgi_param? SCRIPT_FILENAME? ? $document_root$fastcgi_script_name;#? ? ? ? fastcgi_param? PATH_INFO? ? ? ? ? $fastcgi_script_name;##? ? ? ? fastcgi_param? ? SERVER_PROTOCOL? ? $server_protocol;#? ? ? ? fastcgi_param? QUERY_STRING? ? ? ? $query_string;#? ? ? ? fastcgi_param? REQUEST_METHOD? ? ? $request_method;#? ? ? ? fastcgi_param? CONTENT_TYPE? ? ? ? $content_type;#? ? ? ? fastcgi_param? CONTENT_LENGTH? ? ? $content_length;#? ? ? ? fastcgi_param? ? SERVER_ADDR? ? ? ? $server_addr;#? ? ? ? fastcgi_param? ? SERVER_PORT? ? ? ? $server_port;#? ? ? ? fastcgi_param? ? SERVER_NAME? ? ? ? $server_name;#? ? ? ? fastcgi_param? REMOTE_ADDR? ? ? ? $remote_addr;#? ? ? ? ? fastcgi_read_timeout 36000;##? ? ? ? client_max_body_size 0;##? ? ? ? access_log? ? ? /var/log/nginx/seahub.access.log;#? ? ? ? ? error_log? ? ? /var/log/nginx/seahub.error.log;#? ? }location/seafhttp {rewrite ^/seafhttp(.*)$$1break;proxy_passhttp://127.0.0.1:8082;//設(shè)置成你自己的client_max_body_size0;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_connect_timeout36000s;proxy_read_timeout36000s;proxy_send_timeout36000s;send_timeout36000s;proxy_request_bufferingoff;? ? ? ? }location/media {root/hehe/seafile-server-latest/seahub;?//設(shè)置成你自己的? ? ? ? }? ? }
接著刪除/etc/nginx/sites-enabled/default
并創(chuàng)建符號鏈接
rm /etc/nginx/sites-enabled/defaultln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf
重啟nginx
sudo/etc/init.d/nginx?reload
如果出現(xiàn)
[ ok ] Reloading nginx configuration (via systemctl): nginx.service.
那么就成功了。
現(xiàn)在訪問你的域名就可以看到Seahub了。
6.安裝手機端APP
Seafile安卓客戶端:
http://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-2.2.17.apk
蘋果直接搜索Seafile下載
電腦端訪問
https://www.seafile.com/download/
就可以享受同步照片的樂趣啦!
結(jié)尾
這個文章可能是我寫過最長的一篇,把它寫下來也是記錄我鼓搗中的經(jīng)驗,
雖然可能有些小眾化,但是應(yīng)該能幫到其他也想部署私有云的人。