文档章节

[翻译中] 树莓派搭建Torrent服务器

八宝粥
 八宝粥
发布于 2013/07/02 21:01
字数 1837
阅读 819
收藏 0

In this tutorial I document what I did to set up Raspberry Pi (RPi) as a torrent server. Before you begin, please set up your RPi correctly. See:http://elinux.org/RPi_Easy_SD_Card_Setup.

I used Debian Squeeze 6.0.4 for my OS. Instructions may differ for Arch, Fedora, or for some of the other microOS distributions that are out there. Because the GUI on Debian Squeeze (LXDE) can be a bit of a memory hog (LXDE is actually quite light weight…but we only have 256mb of ram to work with), the entire tutorial will be done in command line. In addition, you need the following parts:

  1. A USB External Hard Drive

  2. USB wire (for External Drive)

  3. Ethernet wire

  4. A GOOD quality power supply (>= 2A current maximum).

This tutorial is presented in three parts. I give the basic setup on the RPi itself to get the task done. After this, more advanced tweaking options for transmission torrent client are given. Depending on your kernel or possible errors that occur, I outline some additional problems I encountered, and how they were solved.

Note: For the code examples given, single arrow “>” means command line input. Double arrow “>>”means the lines one puts in the configuration files.

Basic Setup:

1) First let’s make our lives easier. On Debian, file permissions can cause some obstructions when running and editing files. Lets setup root and login as root. By default root access on Debian is done with sudo, and the “root” user is not setup. Go to terminal and type:

> sudo passwd root

and give root a password. Now log out of the system, and sign in as root.

2) With root access, lets get our torrent client. I chose transmission because its well supported and already available in our Debian repository. Type:

> apt-get update
> apt-get install transmission transmission-daemon transmission-cli

There are actually three different packages for the torrent client: transmission, transmission-daemon, and transmission-clitransmission is the regular application that a desktop user would run; in an X windows environment it would launch a GUI front end.

Transmission is a lot more robust than this; transmission-daemon is a ‘headless’ (non-GUI) form of transmission used for more complex setups (such as, having multiple instances of transmission running across multiple computers in a LAN).  We only need one instance of transmision-daemon for our purposes.

3) Once installed, locate the transmission-daemon folder on your system. Type:

> cd /etc/transmission-daemon ; ls

You will see a number of files, but we care about the settings.json. Type:

> nano settings.json

And open it up. We are going to set up the ports for transmission-daemon traffic, and for the webUI port. Specifically, look for lines that start with “rpc”. Here are the RPC lines:

“rpc-enabled”: true,
“rpc-password”: “<your password>”,
“rpc-port”: “<your chosen port>”,
“rpc-username”: “<your username>”,

Here we are enabling the Remote client. Set “rpc-enabled” to true, as well as your chosen port, password and user name.

Note #1: Security conscious users might be worried about storing their password in plain text. Dont worry: when transmission starts running, it reads this file and replaces the password entered with a hashed password. You can check this out yourself to verify it.

Note #2: You need to check to make sure your ports are free. Before doing this, type:

> netstat -nap.

and see if your desired port is already registered!

4) Next,  configure your LAN router to allow for outside connections. Get your IP address for your RPi by typing:

> ifconfig eth0

If you are on a LAN, your IP address should have the form 192.168.X.Y.

Log into your router, and in the ‘Virtual Servers’ tab, associate your chosen port number to your RPi’s given IP address. Here it is for my router: I’ve chosen port 8002 for the webconsole, and 8001 for incoming torrent traffic.

Most routers have DHCP enabled, so we need a static IP address for port mappings to hold. Configure your router to permanently assign the RPi and IP address, so the mappings sticks. Again, it’s up to you to find this option on your router. On my router (a D-link), I was able to do this under “Network Settings”.

Mounting a Hard Drive:

5) We need to connect an external hard drive to Linux, to store our torrent files. I happened to have an NFTS file system on my external hard drive. RPi will recognize the drive, but it may not mount it correctly.

To start, connect your hard drive via USB and let it initialize. Now type:

> fdisk -l

The tables that are produced represent each physical hard drive; every row of the table is a partition on the hard drive. Look for the table with “NFTS” and record the device boot path. In my example, it is /dev/sda1. Sample console output below:

6) For Debian, mounted drives are accessed through the /media folder. Lets mount the drive:

> cd /media
> mkdir <your directory name>
> mount -t ntfs-3g /dev/sda1 /media/<your directory name>

Above, we made a directory for our mount command to associate the mounted drive to a folder. Now that this is done, let’s go to settings.json and set up our folders for transmission-daemon:

>cd /etc/transmission-daemon
> nano settings.json

Look for the following lines, and type in the following information:

>>”download-dir”: “/media/<your directory name>/<folder on drive>”,
>>”incomplete-dir”: “/media/<your directory name>/<some other folder on drive>”,
>>”incomplete-dir-enabled”: true,

Where <your directory name> is the name chosen when we made the directory (above). Save the file.

7) Finally, we would like our transmission torrent client to start up automatically when our RPi is turned on. We need to edit the rc.local start up
file to make this possible.

> cd /etc
> nano rc.local

Add the following lines to the very bottom of the file:

>> mount -t ntfs-3g /dev/sda1 /media/<your directory name>
>> transmission-daemon &

Restart your RPi. Basic setup is done!

Check that RPi is Working Correctly:

1) First check if you can access your torrent server from inside your LAN. In a browser, type: <RPi’s LAN address>:<web client port number>. A login box should appear:


Login with your creditials. If successful, you will see the web console like so:

2) Now check to see if you can access from outside your LAN. You will need the IP address assigned to your modem, from your ISP (google: whats my ip? to get this). In a browser type: http://<your modem ISP>:<your webUI port number>.  You should go straight to the webUI console, if you already logged in in step (1).

Additional Setup:

There are a number of other features in settings.json that can be set. Here are some of note:

  • “cache-size-mb”: Sets our cache size before writing to the External USB drive.

  • “download-limit”, “download-limit-enabled”: Set your download limits.

  • “encryption”: Set to 1 to turn it on.

  • “max-peers-global”, “peer-limit-global”,”peer-limit-per-torrent”: Control the number of peers that connect to your server.

  •  “open-file-limit”: Limit how many torrent files can download at once.

  • “ratio-limit”, “ratio-limit-enabled”: Limit your Leech:Seed Ratio. Be nice and set it to 1.000 or above :) .

  • “script-torrent-done-enabled”,”script-torrent-done-filename”: Quite an interesting feature. When your torrent file finishes, you can run a script to process it, or move it to another directory.

  • “speed-limit-down”, “speed-limit-down-enabled”, “speed-limit-up”, “speed-limit-up-enabled”, “upload-limit”, “upload-limit-enabled”, “upload-slots-per-torrent”: This whole list of options controls download and upload speeds.

Problems and Hangups:

Alas, doing the basic setup probably won’t work for everyone. I had a number of issues I had to solve before I could get things working.

1) Incomplete torrent files don’t stick around: Make sure the “incomplete-dir-enabled” option is set to True (1).

2) My RPi’s Ethernet Driver keeps crashing!

This is by far the biggest issue for the whole setup. You might find that doing file transfers or Downloads at high speeds (> 500k/sec) causes the RPi ethernet driver to crash. You won’t be able to SSH into the RPi, or access the internet with it, but the RPi runs fine otherwise.
The reasons for this vary. Perhaps a bit of background is in order.

The RPi Ethernet and USB ports are controlled by one single chip, which share the same system bus. Naturally, our torrent box application puts a lot of load on this chip and bus. Not only is a lot of traffic flowing through the ethernet port, but we are also using the same system bus to write to the USB connected hard drive.  More specifically, Ethernet packets are being saved to a cache in memory (RAM), as are the incomplete torrent files. RPi also writes cached information to the disk, while accessing other disk files to supply information to other leechers on our torrent network. So there is high two-way traffic across the bus. You better have a well compiled kernel to handle all this traffic correctly.

Here are a number of solutions to try (in order of complexity), to avoid an Ethernet Driver Crash:

(a) Use a proper power supply: I’ve mentioned this before. And I know using your microUSB phone charger to power the RPi is tempting. But high External Hard Drive + Ethernet usage needs more than the 700mA minimum quoted in the RPi operating specs. Most phone power supplies are 1A or below. Please try a more beefy power supply. Really.

(b) Change your Kernel: Older versions of the ARM kernel aren’t compiled to handle the high system bus traffic problem outlined above. A newer kernel patch has been recently issued to alleviate this problem. Apparently the Arch Linux RPi distribution has a kernel update that patches this automatically. Other distributions do not, and you have to replace your kernel manually:

In theory, the Linux kernel should be perfectly swappable and your system should boot, after you swap your old kernel for the patched one. For the brave, type the following commands to do so:

> cd /boot
> wget http://positron.dckd.nl/~jeroen/stuff/rpi-ipv6-kernel.img
> mv kernel.img kernel.backup.img
> mv rpi-ipv6-kernel.img kernel.img

and restart your system. I got my kernel from the RPi fourm thread [ http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=5142&hilit=%5Bsolved%5D+ethernet&start=25 ], and it alleviated my Ethernet problems.

Note: Recovering the kernel: This worked for me (and many others), but in the event it doesn’t work for you – or worse, your RPi doesn’t boot, do the following to recover your old kernel. Access your RPi file system by plugging the SD card in another system, and navigate to the /boot folder. Then delete the new kernel.img file, and reinstate the old backup one. So:

> rm -f kernel.img
>mv kernel.backup.img kernel.img

(c) Edit vm.cache: Once your kernel is patched, the torrent server should work fine in most cases. If not, you can edit the sysctrl.conf file to increase cache size, like so:

>cd /etc
> nano sysctl.conf
…. locate the line vm.cache_size….

>> set vm.cache_size = 32000

And save the file.  Restart your system.

Change Log and Thanks: 
27/08/2012: Fixed command line typos [therulerofchina]

© 著作权归作者所有

八宝粥
粉丝 50
博文 24
码字总数 35970
作品 0
程序员
私信 提问
吃『派』那些事儿——阿里云 IoT 树莓派实战集锦

树莓派是什么? 各位物联网的极客们对树莓派(Raspberry Pi)肯定不会陌生,它是一台只有信用卡大小的基于ARM的微型电脑,官方系统基于 Debian 。由于其出色的传感器兼容性以及相对低廉的价格...

cxlwill
02/14
0
0
树莓派自建 NAS 云盘之——云盘构建

用自行托管的树莓派 NAS 云盘来保护数据的安全! 在前面两篇文章中,我们讨论了用树莓派搭建一个 NAS 云盘所需要的一些 软硬件环境及其操作步骤。我们还制定了适当的 备份策略 来保护 NAS 上...

作者: Manuel Dewald
2018/10/17
0
0
用树莓派构建你自己的微型服务器,可以外网访

第一,你得有一个路由器,否则下面的内容都无法实现了。 第二,你得申请一个免费的动态域名解析,由于我用的是TP-LINK的路由器,只支持花生壳,所以我申请了花生壳的动态域名解析。 申请花生...

maweitao
2014/07/25
23.4K
4
新手教程:如何 SSH 进入树莓派

在这篇树莓派文章中,你将学到如何在树莓派中启用 SSH 以及之后如何通过 SSH 进入树莓派。 在你可以用树莓派做的所有事情中,将其作为一个家庭网络的服务器是十分流行的做法。小体积与低功耗...

作者: Chinmay
05/23
0
0
树莓派部署Elasticsearch6集群

版权声明:欢迎转载,请注明出处,谢谢。 https://blog.csdn.net/boling_cavalry/article/details/89440971 今天在两个树莓派3B上部署了Elasticsearch6.7.1版本的集群,和在一般Linux服务器上...

博陵精骑
04/21
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Spring使用ThreadPoolTaskExecutor自定义线程池及实现异步调用

多线程一直是工作或面试过程中的高频知识点,今天给大家分享一下使用 ThreadPoolTaskExecutor 来自定义线程池和实现异步调用多线程。 一、ThreadPoolTaskExecutor 本文采用 Executors 的工厂...

CREATE_17
今天
5
0
CSS盒子模型

CSS盒子模型 组成: content --> padding --> border --> margin 像现实生活中的快递: 物品 --> 填充物 --> 包装盒 --> 盒子与盒子之间的间距 content :width、height组成的 内容区域 padd......

studywin
今天
7
0
修复Win10下开始菜单、设置等系统软件无法打开的问题

因为各种各样的原因导致系统文件丢失、损坏、被修改,而造成win10的开始菜单、设置等系统软件无法打开的情况,可以尝试如下方法解决 此方法只在部分情况下有效,但值得一试 用Windows键+R打开...

locbytes
昨天
8
0
jquery 添加和删除节点

本文转载于:专业的前端网站➺jquery 添加和删除节点 // 增加一个三和一节点function addPanel() { // var newPanel = $('.my-panel').clone(true) var newPanel = $(".triple-panel-con......

前端老手
昨天
8
0
一、Django基础

一、web框架分类和wsgiref模块使用介绍 web框架的本质 socket服务端 与 浏览器的通信 socket服务端功能划分: 负责与浏览器收发消息(socket通信) --> wsgiref/uWsgi/gunicorn... 根据用户访问...

ZeroBit
昨天
10
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部