Asuswrt-Merlin Syncthing (檔案同步)

文章目錄

需求

Syncthing 是一個 Open Source 的檔案同步軟體, 預計把她跑在 Asuswrt-Merlin 上, 然後在上面掛一顆 USB HDD, 以便及時把檔案同步備份過去.

注意

Syncthing 滿吃 CPU 的, 而分享器的 CPU 通常效能很弱, 因此不建議同步太多檔案上去 !!!

安裝

目前 amtm 並沒有支援 Syncthing, 不過可以透過 opkg 來安裝

  1. 首先看一下 opkg 上面的 Syncthing, 目前有兩個, 我的 Asus AC68U B1 要用的是 nohf 版本.

    1admin@RT-AC66U_B1-B898:/tmp/home/root# opkg list |grep synct
    2syncthing - 1.22.1-1 - Syncthing replaces proprietary sync and cloud services with something open, trustworthy and decentralized. Your data is your data alone and you deserve to choose where it is stored, if it is shared with some third party and how it''s transmitted over the Internet.
    3syncthing_nohf - 1.22.1-1 - Syncthing replaces proprietary sync and cloud services with something open, trustworthy and decentralized. Your data is your data alone and you deserve to choose where it is stored, if it is shared with some third party and how it's transmitted over the Internet.
    
  2. 這裡我們安裝 syncthing_nohf

    1admin@RT-AC66U_B1-B898:/tmp/home/root# opkg install syncthing_nohf
    2Installing syncthing_nohf (1.22.1-1) to root...
    3Downloading https://bin.entware.net/armv7sf-k2.6/syncthing_nohf_1.22.1-1_armv7-2.6.ipk
    4Configuring syncthing_nohf.
    
  3. 先手動把程式跑起來

    1admin@RT-AC66U:/tmp/mnt/usb/entware/etc/init.d# /opt/etc/init.d/S92syncthing start
    2 Starting syncthing...              done.
    
  4. 可以用這個指令檢查程式是否有跑成功, 如果顯示 alive, 那就是有跑起來了.

    1admin@RT-AC66U:/tmp/mnt/usb/entware/etc/init.d# /opt/etc/init.d/S92syncthing check
    2 Checking syncthing...              alive.
    
  5. 連線到 http://192.168.1.1:8384/ (假設你的分享器 IP 是 192.168.1.1), 剩下的部分, 就和一般的 Syncthing 一樣了.

  6. 如果要把 Android 手機上的檔案同步過去, 可參考 手機照片自動備份到電腦 (使用 Syncthing for Android)

注意

GUI 的密碼萬一忘了怎麼辦?

  1. 打開 /opt/etc/init.d/S92syncthing, 尋找 gui 這個段落, 然後把 user, password 這兩行移除

    1    <gui enabled="true" tls="false" debugging="false">
    2        <address>0.0.0.0:8384</address>
    3        <user>user123</user>
    4        <password>sdfjsdf*SDJFlkjewqflkdsMldsakfjlkewjflkdsajflkdsaf</password>
    5        <apikey>oHV57ywtwXARYmeZgWDUvyKCSQpU23v4</apikey>
    6        <theme>default</theme>
    7    </gui>
    
  2. 重開 Syncthing, 然後再登入 GUI, 就會要你重新建立一個帳號了

    1    /opt/etc/init.d/S92syncthing restart
    2    Shutting down syncthing...              done.
    3    Starting syncthing...              done.
    

如何不讓 Syncthing 在開機時自動執行?

  1. 打開 /opt/etc/init.d/S92syncthing, 將第 10 行改成 ENABLED=no, 下次重開機就不會自動執行了
     1#!/bin/sh
     2
     3if [ ! -d "/opt/etc/syncthing" ]; then
     4syncthing -generate="/opt/etc/syncthing"
     5sed -i 's|127\.0\.0\.1|0.0.0.0|' /opt/etc/syncthing/config.xml
     6elif [ -n "$(grep '127\.0\.0\.1' /opt/etc/syncthing/config.xml)" ]; then
     7sed -i 's|127\.0\.0\.1|0.0.0.0|' /opt/etc/syncthing/config.xml
     8fi
     9
    10ENABLED=no
    11PROCS=syncthing
    12ARGS=""
    13PREARGS=""
    14DESC=$PROCS
    15PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    16
    17. /opt/etc/init.d/rc.func
    

Syncthing 很吃 CPU 嗎?

這是測試 Android -> Asuswrt-Merlin 的 CPU loading.

  1. 一般大約 30%~50% 左右

     1    0[||||||||||||||||||||||||||                                        33.8%] Tasks: 116, 22 thr, 33 kthr; 2 running
     2    1[||||||||||||||||||||||||||||||||                                  43.9%] Load average: 1.76 1.74 1.39
     3Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||176M/250M] Uptime: 00:37:30
     4Swp[||                                                          16.9M/2.00G]
     5
     6[Main] [I/O]
     7PID USER       PRI  NI  VIRT   RES   SHR S  CPU%-MEM%   TIME+  Command
     816939 admin       31  11  797M 60788  8596 S  35.7 23.8  0:44.51 /tmp/mnt/USBext4/entware/bin/syncthing
     916958 admin       31  11  797M 60788  8596 S  11.5 23.8  0:10.24 /tmp/mnt/USBext4/entware/bin/syncthing
    1016961 admin       31  11  797M 60788  8596 S   8.9 23.8  0:12.03 /tmp/mnt/USBext4/entware/bin/syncthing
    1116942 admin       31  11  797M 60788  8596 S   7.6 23.8  0:05.79 /tmp/mnt/USBext4/entware/bin/syncthing
    1216959 admin       31  11  797M 60788  8596 S   5.1 23.8  0:15.21 /tmp/mnt/USBext4/entware/bin/syncthing
    1316940 admin       31  11  797M 60788  8596 S   2.5 23.8  0:00.90 /tmp/mnt/USBext4/entware/bin/syncthing
    
  2. 偶爾也是會跳到 80% 甚至 90% 以上

     1    0[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 90.0%] Tasks: 116, 22 thr, 33 kthr; 2 running
     2    1[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||      83.1%] Load average: 2.81 2.01 1.51
     3Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||177M/250M] Uptime: 00:38:34
     4Swp[||                                                          16.9M/2.00G]
     5
     6[Main] [I/O]
     7PID USER       PRI  NI  VIRT   RES   SHR S  CPU%-MEM%   TIME+  Command
     816939 admin       31  11  797M 61104  8472 S  43.8 23.9  1:07.74 /tmp/mnt/USBext4/entware/bin/syncthing
     916958 admin       31  11  797M 61104  8472 S  15.0 23.9  0:15.59 /tmp/mnt/USBext4/entware/bin/syncthing
    1016961 admin       31  11  797M 61104  8472 S  13.8 23.9  0:18.20 /tmp/mnt/USBext4/entware/bin/syncthing
    1116942 admin       31  11  797M 61104  8472 S  13.1 23.9  0:09.29 /tmp/mnt/USBext4/entware/bin/syncthing
    1216940 admin       31  11  797M 61104  8472 S   1.2 23.9  0:02.57 /tmp/mnt/USBext4/entware/bin/syncthing
    1316960 admin       31  11  797M 61104  8472 S   0.6 23.9  0:05.12 /tmp/mnt/USBext4/entware/bin/syncthing
    

一直 Crash 怎麼辦?

方法 1: 修改參數

修改這兩個設定 (都在 進階設定 裡面), 可以撐一陣子, 但很可惜的, 跑了一陣子還是會 crash... 繼續研究中!!!

  1. 資料夾裡的 Max Concurrent Writes, 預設是 2, 把它改成 1.
  2. 設定環境變數, 以便減少 thread (參考 https://forum.syncthing.net/t/reducing-number-of-threads-created/17825)
    1export GOMAXPROCS=1
    

方法 2: 降級到 1.19.1

選這個版本的原因是因為在 Synology DSM 上面沒法跑 1.20, 所以降版到 1.19, 就想說來試試看這個版本.

  1. 下載 https://bin.entware.net/armv7sf-k2.6/archive/syncthing_nohf_1.19.1-1_armv7-2.6.ipk (請看你的 hub 選擇不同的版本)
  2. 執行 tar zxvf 把她解開, 他有包兩層, 反正就是通通解開, 取出裡面的 syncthing 執行擋
  3. 將取出的 syncthing 執行擋蓋掉 /opt/bin/syncthing (原檔案請記得備份)
  4. 修改 /opt/etc/init.d/S92syncthing, 加上這兩個參數
    1ARGS="--no-upgrade --allow-newer-config"
    
  5. 重開 Syncthing
    1    /opt/etc/init.d/S92syncthing restart
    2    Shutting down syncthing...              done.
    3    Starting syncthing...              done.
    
  6. 看起來效果還不錯, 不過有時候會吃很多 CPU
     1    0[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||     84.3%] Tasks: 118, 29 thr, 32 kthr; 2 running
     2    1[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||95.9%] Load average: 5.91 4.77 2.46
     3Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||189M/250M] Uptime: 08:57:28
     4Swp[||                                                          22.9M/2.00G]
     5
     6[Main] [I/O]
     7PID USER       PRI  NI  VIRT   RES   SHR S  CPU%-MEM%   TIME+  Command
     820906 admin       31  11  796M 74380  5260 S  58.7 29.1  7:28.88 /opt/bin/syncthing --no-upgrade --allow-newer-config
     920908 admin       31  11  796M 74380  5260 R  14.0 29.1  0:59.92 /opt/bin/syncthing --no-upgrade --allow-newer-config
    1020916 admin       31  11  796M 74380  5260 S  14.0 29.1  0:53.32 /opt/bin/syncthing --no-upgrade --allow-newer-config
    1120910 admin       31  11  796M 74380  5260 S  10.5 29.1  0:42.05 /opt/bin/syncthing --no-upgrade --allow-newer-config
    1220989 admin       31  11  796M 74380  5260 S  10.5 29.1  1:01.03 /opt/bin/syncthing --no-upgrade --allow-newer-config
    1320990 admin       31  11  796M 74380  5260 S   9.3 29.1  0:50.08 /opt/bin/syncthing --no-upgrade --allow-newer-config
    

Posts in this Series