Syncthing 的简单使用

By Heanny
2021-05-29
2358 read

前言

突然发现了一个不错的多端同步软件Syncthing,拿来用用

下载

地址:https://syncthing.net/downloads/
Github:https://github.com/syncthing/syncthing
或者:https://heanny.lanzoui.com/iV1tAplcnri (arm版本)

安装

以下为在树莓派中运行

直接解压
然后给予root权限,

shmod +x syncting

编辑配置文件

vim /root/.config/syncthing/config.xml

address标签修改监听端口和ip
folder标签可以修改默认的地址,也可以在操作界面修改

启动。

./syncthing

开机启动

vi /etc/init.d/syncthing

编辑脚本

#!/bin/sh
### BEGIN INIT INFO
# Provides:          Syncthing
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Syncthing
# Description:       Syncthing is for backups
### END INIT INFO

. /lib/lsb/init-functions

DAEMON_NAME = syncthingTest               #随便起个名字
DAEMON_USER = root                        #登入树莓派的用户名,不用加双引号
DAEMON_PATH = /usr/syncthing/syncthing    #你执行程序的路径
DAEMON_OPTS = ""
DAEMON_PWD = "${PWD}"
DAEMON_DESC = $(get_lsb_header_val $0 "Short-Description")
DAEMON_PID = "/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=  0
DAEMON_LOG = '/var/log/syncthing'         #储存你日志的路径

[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"

do_start() {
  local result

    pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
    if [ $? -eq 0 ]; then
        log_warning_msg "${DAEMON_NAME} is already started"
        result=0
    else
        log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
        touch "${DAEMON_LOG}"
        chown $DAEMON_USER "${DAEMON_LOG}"
        chmod u+rw "${DAEMON_LOG}"
        if [ -z "${DAEMON_USER}" ]; then
            start-stop-daemon --start --quiet --oknodo --background \
                --nicelevel $DAEMON_NICE \
                --chdir "${DAEMON_PWD}" \
                --pidfile "${DAEMON_PID}" --make-pidfile \
                --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
            result=$?
        else
            start-stop-daemon --start --quiet --oknodo --background \
                --nicelevel $DAEMON_NICE \
                --chdir "${DAEMON_PWD}" \
                --pidfile "${DAEMON_PID}" --make-pidfile \
                --chuid "${DAEMON_USER}" \
                --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
            result=$?
        fi
        log_end_msg $result
    fi
    return $result
}

do_stop() {
    local result

    pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
    if [ $? -ne 0 ]; then
        log_warning_msg "${DAEMON_NAME} is not started"
        result=0
    else
        log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
        killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
        result=$?
        log_end_msg $result
        rm "${DAEMON_PID}"
    fi
    return $result
}

do_restart() {
    local result
    do_stop
    result=$?
    if [ $result = 0 ]; then
        do_start
        result=$?
    fi
    return $result
}

do_status() {
    local result
    status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
    result=$?
    return $result
}

do_usage() {
    echo $"Usage: $0 {start | stop | restart | status}"
    exit 1
}

case "$1" in
start)   do_start;   exit $? ;;
stop)    do_stop;    exit $? ;;
restart) do_restart; exit $? ;;
status)  do_status;  exit $? ;;
*)       do_usage;   exit  1 ;;
esac

配置

添加权限:chmod +x /etc/init.d/syncthing
添加默认启动:update-rc.d syncthing defaults
开机自动运行:update-rc.d syncthing remove

指令

service syncthing start
service syncthing stop
service syncthing restart
service syncthing status

或者

在syncthing根目录下
#命令执行后,下次开启将自动启动supervisor
systemctl enable syncthing
#下面的命令可以取消开机自启
systemctl disable syncthing

安卓手机同步

安装app
google play 安装界面
或者安装Syncthing Fork,据说比楼上好用

使用

配置共享文件夹

另一端就会有提示,邀请加入共享

点击确定后就会开始同步了

更多功能研究中

jenkins的安装与踩坑
树莓派安装omv(debian)

Comments

暂无评论,还不快来坐沙发...

Leave a Reply