樹莓派–seafile搭建私人網盤
此次目的就是搭建私有雲盤,由于之前搭建的nextcloud太過于龐大,小小的樹莓派無法支撐nextcloud這艘巨輪,是以這次是換個輕量的雲私有 seafile
文章目錄
-
- 樹莓派--seafile搭建私人網盤
-
- 準備條件
- 搭建過程
-
- 準備環境
-
- 安裝系統
- 配置環境
- 挂載移動硬碟
- 開始安裝
- 補充
-
- 外網通路
- 自啟動
準備條件
- 樹莓派 3B+ 250+
- 移動硬碟 2T 470+
- 筆記本一台
- 路由器一台
搭建過程
準備環境
安裝系統
在官網中下載下傳樹莓派系統鏡像
Raspbian Buster Lite
,使用
Win32DiskImager
燒入SD卡
鏡像位址
在boot盤中建立空
ssh
檔案和
wpa_supplicant.conf
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Danke_1504"
psk="wifi.danke.life"
key_mgmt=WPA-PSK
priority=1
}
配置環境
樹莓派上電後,筆記本與樹莓派連接配接到同一路由器或同一網段。win使用以下指令擷取樹莓派ip位址
$ arp -a
一般樹莓派的mac位址是b開頭,我這裡是有兩個樹莓派
初始化使用者名和密碼分别是pi和raspberry,使用ssh工具登入,之後是換源,有需要的同志可以考慮一下,不是必須的
$ nano /etc/apt/sources.list
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main contrib non-free rpi
$ nano /etc/apt/sources.list.d/raspi.list
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/ buster main ui
$ apt-get update
挂載移動硬碟
這裡需要注意的是,剛買回來的移動硬碟是exfat格式,linux無法正常使用,需要借助其他工具來進行挂載,我這裡圖友善,是以索性格式化為ext4
$ sudo su
# 檢視移動硬碟格式
$ df -T
# 挂載硬碟
$ mount /dev/sda /data/wd
# 解除安裝硬碟
$ umount /data/wd
# 開機自動挂載
$ blkid
[email protected]:/data/wd# blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="5203-DB74" TYPE="vfat" PARTUUID="6c586e13-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="2ab3f8e1-7dc6-43f5-b0db-dd5759d51d4e" TYPE="ext4" PARTUUID="6c586e13-02"
/dev/sda: UUID="f69f23ac-8617-4825-b8e5-9abc1da1e648" TYPE="ext4"
/dev/mmcblk0: PTUUID="6c586e13" PTTYPE="dos"
$ nano /etc/fstab
UUID=f69f23ac-8617-4825-b8e5-9abc1da1e648 /data/wd ext4 defaults 0 0
開始安裝
安裝
seafile
所需要的工具和依賴
$ apt-get install libpython2.7 python-setuptools python-pil python-ldap python-urllib3 sqlite3 python-requests python-mysqldb mariadb-server -y
$ mysql
> use mysql;
> UPDATE user SET password=password('password') WHERE user='root';
> flush privileges;
> exit
到
github
中擷取專有的seafile壓縮包,我這裡下載下傳的是最新 7.0.5,下載下傳完之後,解壓安裝
github位址
打不開github的小夥伴請自行想辦法
$ mkdir /home/pi/seafile
$ cp /home/pi/seafile-server_7.0.5_stable_pi.tar.gz /home/pi/seafile
$ cd /home/pi/seafile
$ tar -zxf seafile-server_7.0.5_stable_pi.tar.gz
$ cd /seafile-server-7.0.5
這裡需要注意一下,進入到目錄後,會發現有兩個安裝腳本
setup-seafile.sh
和
setup-seafile-mysql.sh
,這裡,也就是seafile提供了兩個安裝方法,一個是不需要資料庫安裝,另一個需要資料庫安裝。我這裡選擇的是資料庫配置安裝方法。
$ ./setup-seafile-mysql.sh
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] seafile
What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] 192.168.124.37
Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/home/pi/seafile/seafile-data" ] /data/wd/seafile
[ default "/home/pi/seafile/seafile-data" ] /data/wd/seafile
Which port do you want to use for the seafile fileserver?
[ default "8082" ]
-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
[ 1 or 2 ] 1
.... # 之後一直回車
port of seafile fileserver: 8082
port of seahub: 8000
When problems occur, Refer to
https://github.com/haiwen/seafile/wiki
for information.
$ cd /home/pi/seafile/conf/
$ nano gunicorn.conf
# 修改授權通路位址
bind = "0.0.0.0:8000"
$ cd /home/pi/seafile/seafile-server-7.0.5/
$ ./seafile.sh start
$ ./seahub.sh start
# 按提示輸入管理者郵箱和密碼
# 如果需要管理端口的可以安裝ufw工具
$ apt-get install ufw
補充
外網通路
由于我的是電信動态ip,自己也有個域名,這裡使用了aliyun ddns,與光貓中設定端口映射到路由器中,路由器又DMZ虛拟主機映射,實作了可以通過外網來訪内網seafile服務。
自啟動
$ sudo su
$ nano /etc/systemd/system/seafile.service
[Unit]
Description=Seafile
After=network.target
[Service]
Type=oneshot
ExecStart=/home/pi/seafile/seafile-server-latest/seafile.sh start
ExecStop=/home/pi/seafile/seafile-server-latest/seafile.sh stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
$ nano /etc/systemd/system/seahub.service
[Unit]
Description=Seafile hub
After=network.target seafile.service
[Service]
ExecStart=/home/pi/seafile/seafile-server-latest/seahub.sh start
ExecStop=/home/pi/seafile/seafile-server-latest/seahub.sh stop
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
$ sudo systemctl enable seafile.service
$ sudo systemctl enable seahub.service