bittorrent+sync+java_使用BitTorrent-Sync实现双机文件双向同步

BitTorrent-Sync是一款基于P2P的分布式文件同步工具,简称btsync,非开源软件但免费使用。本文使用btsync实现两台服务器上的软件双向同步。

安装

直接从官网下载相应的安装包,为了在Linux服务器上安装,使用的是Linux x64版本BitTorrent-Sync_x64.tar.gz。

然后解压到指定的文件夹,即可执行程序。

sudo mkdir -p /usr/local/btsync

sudo chown shenfeng /usr/local/btsync

tar -zxvf BitTorrent-Sync_x64.tar.gz -C /usr/local/btsync/

进入解压后的目录,可以看到3个文件,其中btsync为可执行文件。

$ ls

btsync LICENSE.TXT README

执行--help可以查看帮助信息

./btsync --help

BitTorrent Sync 2.3 (239)

Usage:

btsync [ options ... ]

Options:

--help Print this message

--config Use a configuration file

--storage Storage path for identity and license

--identity Creates user identity

--license Apply owner license

--nodaemon Do not daemonize

--dump-sample-config Print a sample configuration file

--log Set log file

--webui.listen :Set the webui listening interface

--generate-secret Generate a read/write key

--get-ro-secret Get the read-only key associated to a read/write key

配置

编写启动脚本。

$ sudo vi /etc/init.d/btsync

#!/bin/sh

#

# description: starts and stops the btsync client

CONF=/usr/local/btsync/btsync.cfg

PROC=/usr/local/btsync/btsync

PIDFILE=/usr/local/btsync/btsync.pid

start() {

PID1=$(pidof btsync)

if [ -z ${PID1} ]; then

echo -n "Starting BitTorrent Sync: "

${PROC} --config ${CONF}

else

echo "BitTorrent Sync is already running at pid:${PID1}"

fi

return $?

}

stop() {

echo -n "Stopping BitTorrent Sync: "

PID1=$(pidof btsync)

if [ ! -z ${PID1} ]; then

kill -9 ${PID1}

echo "OK"

else

echo "Failed"

fi

return $?

}

status() {

PID1=$(pidof btsync)

PID2=$(cat ${PIDFILE})

echo -n "Checking BitTorrent Sync: "

if [ ! -z ${PID1} ] && [ "${PID1}" -eq "${PID2}" ]; then

echo "OK"

else

echo "Failed"

fi

return $?

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep 1

start

;;

status)

status

;;

*)

echo $"Usage: $0 {start|stop|restart|status}"

exit 2

esac

编写启动配置文件

{

"device_name": "vm_2",

"listening_port" : 8889, // 0 - randomize port

"check_for_updates" : false,

"use_upnp" : false,

"storage_path" : "/usr/local/btsync",

"pid_file" : "/usr/local/btsync/btsync.pid",

"download_limit" : 0, // 0 - no limit

"upload_limit" : 0,

"webui" :

{

"listen" : "0.0.0.0:8888",

"login" : "admin",

"password" : "btsync"

}

,

"folder_rescan_interval" : 1,

"lan_encrypt_data" : false,

}

启动程序,通过web页面进行登录和后续配置。

$ /etc/init.d/btsync start

Starting BitTorrent Sync: By using this application, you agree to our Privacy Policy, Terms of Use and End User License Agreement.

https://www.getsync.com/legal/privacy

https://www.getsync.com/legal/terms-of-use

https://www.getsync.com/legal/eula

Webui is listening on 0.0.0.0:8888

BitTorrent Sync forked to background. pid = 15002

在浏览器页面登录控制页面,即服务器IP+8888端口。

使用配置文件中的账号密码进行登录。

815e43e3fd5a4883ddf5dd317a3c589d.png

在启动一台主机上,点击左上角的Add Folder按钮,增加需要同步的目录。

7328ba74d73d1da060da9de031e7a7ae.png

确认打开目录后,会生成该目录的Key,因为需要双向同步,那么选择READ+WRITE的Key。

71793c76bccfaa32ac4aff94394087c7.png

登录第二台服务器,登录后,点击Add Folder的第三个选项。填入上面复制的Key之后,选择本地用于同步的目录就可以进行同步了。

027994c2675628a7dad1fa57b76358b0.png

9f5f1846224a59ae0b455df9156e6e25.png

参考文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值