标签为 Sync 的文章

在Linux上安装配置BitTorrent Sync

背景介绍:
目前我们线上的前端服务器数量比较多,超过200多台,每次发布新应用的时候,都是将软件包放在一台专门的Push服务器上,再由所有的前端服务器通过rsync自动同步。但随着前端服务器的数量越来越多,Push服务器的带宽已经成为了瓶颈。
而BitTorrent Sync这种P2P方式的同步则是一种解决方案。同时它的跨平台支持也非常好,无论是Windows,Linux,Mac OS,甚至手机端都有相应的客户端。虽然目前尚未开源,但可以免费使用,还是很不错的。

下面,就是我们在线上的纯Linux测试环境中的安装与配置步骤:
Servers:
idc2-server1,idc2-server2,idc2-server3

1. 下载BitTorrent Sync,在所有服务器上:
$ sudo wget http://download-lb.utorrent.com/endpoint/btsync/os/linux-x64/track/stable -O /tmp/btsync_x64.tar.gz
$ sudo mkdir /opt/btsync
$ cd /opt/btsync
$ sudo tar xzf /tmp/btsync_x64.tar.gz

2. 创建服务管理脚本,在所有服务器上:
$ sudo vim /etc/init.d/btsync

 
#!/bin/sh
#
# description: starts and stops the btsync client

CONF=/opt/btsync/btsync.cfg
PROC=/opt/btsync/btsync
PIDFILE=/opt/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

$ sudo chmod +x /etc/init.d/btsync

3. 创建用于同步的目录,在所有服务器上:
$ sudo mkdir /opt/btsync_transfer

4. 创建配置文件,在idc2-server1上:
[heydevops@idc2-server1 btsync]$ sudo vim /opt/btsync/btsync.cfg

 
{ 
  "device_name": "idc2-server1",
  "listening_port" : 8889, // 0 - randomize port

  "check_for_updates" : false,
  "use_upnp" : false,

  "storage_path" : "/opt/btsync",
  "pid_file" : "/opt/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" : 60,
  "lan_encrypt_data" : false,
  "lan_use_tcp" : true
}

5. 创建同步所需的密钥,在idc2-server1上:
$ sudo /etc/init.d/btsync start

打开Web UI:http://idc2-server1:8888
用户名: admin
密码: btsync

点击 "Add Folder",
在 "Path" 中输入 "/opt/btsync_transfer"
点击 "Generate" 得到 "Secret" 为 "ALUORWDEWOLV354ZHPHFT4TSQO67JWQAN"
如下图所示:
2
阅读全文 »

,

6 Comments