使用BitTorrent-Sync實現雙機文件雙向同步 - camash
來自: http://www.cnblogs.com/shenfeng/p/btsync_on_linux.html
BitTorrent-Sync是一款基于P2P的分布式文件同步工具,簡稱btsync,非開源軟件但免費使用。本文使用btsync實現兩臺服務器上的軟件雙向同步。
</div>
安裝
直接從官網下載相應的安裝包,為了在Linux服務器上安裝,使用的是Linux x64版本 BitTorrent-Sync_x64.tar.gz 。
然后解壓到指定的文件夾,即可執行程序。
sudo mkdir -p /usr/local/btsyncsudo chown shenfeng /usr/local/btsync
tar -zxvf BitTorrent-Sync_x64.tar.gz -C /usr/local/btsync/</pre>
進入解壓后的目錄,可以看到3個文件,其中btsync為可執行文件。
$ lsbtsync LICENSE.TXT README</pre>
執行 --help 可以查看幫助信息
./btsync --helpBitTorrent Sync 2.3 (239)
Usage:
btsync [ options ... ]
Options:
--help Print this message
--configUse a configuration file
--storageStorage path for identity and license
--identityCreates user identity
--licenseApply owner license
--nodaemon Do not daemonize
--dump-sample-config Print a sample configuration file
--logSet log file
--webui.listen: Set the webui listening interface
--generate-secret Generate a read/write key
--get-ro-secret <r/w key> Get the read-only key associated to a read/write key
</file> </div> </path> </div> </user> </div> </path> </div></path> </div>
</div>
配置
編寫啟動腳本。
$ 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</pre>
編寫啟動配置文件
{ "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, }</pre>
啟動程序,通過web頁面進行登錄和后續配置。
$ /etc/init.d/btsync startStarting 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 </pre>
Webui is listening on 0.0.0.0:8888
BitTorrent Sync forked to background. pid = 15002
</div>
在瀏覽器頁面登錄控制頁面,即服務器IP+8888端口。
使用配置文件中的賬號密碼進行登錄。
![]()
在啟動一臺主機上,點擊左上角的Add Folder按鈕,增加需要同步的目錄。
![]()
確認打開目錄后,會生成該目錄的Key,因為需要雙向同步,那么選擇READ+WRITE的Key。
![]()
登錄第二臺服務器,登錄后,點擊Add Folder的第三個選項。填入上面復制的Key之后,選擇本地用于同步的目錄就可以進行同步了。
![]()
![]()
參考文檔
</div>本文由用戶 EmeliaLowry 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!相關資訊
sesese色