Jump to content

How To: Build a uTorrent server with Turnkeylinux and VirtualBox


kamaradski

Recommended Posts

Posted

How To: Build a uTorrent server (or seedbox) with Turnkeylinux and Virtual box.

Enjoy but keep in mind i'm not responsible for any of the offered software, nor am i affiliated in any way with any of the below mentioned names\brands\packages and therefore i will not be able to offer any kind of official support on any of the below. Furthermore below was written in the hope to increase the end-user experience for the fantastic uTserver application.

Index:

• How-to environment

• Download the OS

• Create the new Virtual Machine

• Installing the OS

• Upgrading the OS

• Installing guest additions (optional)

• Create a new non-root user for uTorrent

• Downloading and Installing uTorrent

• Configuring uTorrent

• Testing your uTorrent installation

• Adding Utserver to init.d for autostarting on reboot

• Mounting a Samba shared drive from your Host-machine.

• Additional possible setups and tweaks

• Credits, thanks and sources:

How-to environment:

The below how-to was written based on the following setup however most of the information is applicable for most other common environments:

• Host OS: Debian Squeeze

• Kernel version: 2.6.32-5-686

• Gui: Gnome & Bash-shell

• VirtualBox 3.2.10

Download the OS:

• Download the latest version of the bare core from www.turnkeylinux.org and save it somewhere where you can find it again. I decided to work with the .ISO, however you need to decide if for your setup & environment you want to use the .ISO or one of the available VM images

∘ Currently: turnkey-core-11.2-lucid-x86.iso

∘ My save location: /home/$username/.VirtualBox/HardDisks/

Create the new Virtual Machine:

• Open VirtualBox

• Click "New" to create a new machine

• Click "Next" to skip the information window

• Give your machine a name e.g. "Torrentserver"

• Operating system: select "Linux"

• Version select: Linux 2.6

• Click "Next" to go to the next screen

• Decide how much RAM you want to make available for this server. 265 MB should be enough in most cases, however i you want to install more memory hungry applications you might want to make more memory available. You can change this later also if you run out of available memory.

• Click "Next" to go to the next screen

• Select to "create new hard disk" and click "Next" to proceed

• Click "Next" to skip the introduction screen of the hard-disk wizard.

• I recommend you to read carefully the next screen and understand the advantages of both available options. In case the displayed description is not clear to you, you should read further information on the Virtualbox website. The selection you make here will have important impact on your future performance and can NOT easily be changed later. For the purpose of this how-to i selected a "Dynamically expending storage". However in my permanent setups i run "Fixed size"

• Once you decided, click "Next" to proceed

• Select a location to save the hard-drive file. Default location: /home/$username/.VirtualBox/HardDisks/

• Select a name for the hard-drive, so when you see the file later you know to what machine it belongs to. eg: torrentserver-boot or torrentserver-drive1

• Select a size for your hard-drive. Be aware that even if you selected "Dynamically expending storage" the drive will never expand bigger than the maximum size that you select here. You need to put some thought into the drive-setup you want before permanently setting the size. Please read below a few possible setups\scenarios:

∘ Everything on one large hard drive. (OS and the downloads etc) This is the quickest and most simple setup, and should take the least system resources from the host. However this setup also has the lesser scalability options.

∘ One small 2 or 3 GB hard drive for your OS and a separate large hard drive to store your downloads\seeds. This will give your more scalability in the future, as you can always "replace" this drive with a bigger one and mount it in place of the old one when it turns out to be to small. Furthermore it is also easy to maybe mount this drive on another VM-machine in case you need to transfer the collected data. Also this will give you the opportunity to place the larger storage drive onto a separate physical hard drive to increase performance during high IO loads.

∘ One small 2 or 3 GB hard drive for your OS and a number of larger ones for storage. Generally it's not very optimal to have files of 80, 100, of even 250 GB size on your drive. Chances that something goes wrong is increasing with the file size. So it is possible to create several 10GB hard drives for instance and use LVM to link them all together into one hard drive. Or even when you only would have 4 physical hard drives of 250 GB in your server, you would still be able to create a large 1 TB partition for your downloads.

• As for this how-to i do not want to over complicate matters, i selected to create 1 large hard drive of 80GB, This should be the preferred option for most home, garden & kitchen setups. :) And click "Next" again

• Double check your final hard drive selections and click "Finish"

• Double check your final VM settings and click "Finish"

• Now we have to make a few small tweaks to the standard setup in the settings screen for this VM:

@system: select boot option to be: 1-cdrom & 2-Hard drive. Deselect all other options

@storage: make sure there is a IDE-controller available with a attached CDROM device. Then load the Turnkey-core.ISO in this virtual drive

@audio: Disable audio, you dont need it

@Network: Depending on your setup, the most common setups (small home network with router or modem) work best with "Bridged Adapter". This will result in your Virtual machine to get a new unique IP-address from your router via DHCP and gives the best options to configure open ports etc.

@shared-folders: in this how-to we will utilize the already running Samba server on the host-machine to access the local hard-drives, however you can decide to use the build-in shared-folder option from VM if you wish, or to setup a Samba server on the VM machine. I will include the steps needed to setup the guest-additions that you need for shared-folders in this how-to.

• Now finally make sure you click "OK" as we are ready to fire-up your new torrent-server for the first-time. :)

Installing the OS:

• Select, and start your new torrent server

• Select to "Install to hard drive"

• Enjoy some of this scrolling code on the screen for a while and imagine you are in the Matrix

• Select "guided - use entire disk and set up LVM" in the first installer screen and press "Enter"

• Select "Yes" to save the changes to disk

• Type "max" and press "Enter" to utilize the complete hard drive

• Again select "Yes" to confirm to write the changes

• Depending your the speed of your host machine, you can now take a quick break and fetch a cuppa while your OS is being installed

• Install the GRUB boot-loader on your drive by hitting "Yes"

• Reboot the OS to finalize the last installation options

• Type your new root-password, and confirm it in the next screen

• In case you use the Backup & Migration service you can enter your API-key next, otherwise press "skip"

• Be sure to click "Install" and get the latest security updates next (With the slow host machine i am using today this gave me time for another smoke and coffee)

• After this your machine will enter it's standard running state and show you it's configuration console. If all went ok you should now have a running bare OS with latest security installed.

• Now pres: "ALT + ->" to go to the first console "TTY1" and log-in as root.

• Type: "shutdown -h now" to close your VM and save your first snapshot in VirtualBox, so you can always revert to a clean install.

• Also you can now unmount your cd-rom image in VirtualBox so your next boot will be from hard-drive and not again from the installation cd-rom. Another option is to just remove the cd-rom from the boot sequence.

∘ Or if you are not using the cd-rom to install the guest-addition software (VirtualBox shared-drive) you can remove the complete IDE controller all together and save some system recources.

Upgrading the OS:

• After saving the snapshot and rebooting of the system, open a local console and use SSH to login your VM (better resolution and performance) to do this type: ssh root@123.123.123.123 (make sure to use your correct IP for your VM instead of 123).

• The first time you need to confirm the RSA encryption fingerprint by typing: Yes

• Type your password

• Run: apt-get update

• Run: apt-get install apt-utils

• Run: apt-get upgrade

∘ Depending on your installation you might hit a bug where your upgrade hangs during the installation and restart of the udev process. Follow below instructions to workaround this bug:

∘ Installation will hang with the following message: "Setting up udev (151-12.3)"

Before deciding it is actually hanging leave it for a few minutes and see that there is really no CPU or HD activity.

∘ Open a new local console on your host

∘ Run: ssh root@123.123.123.123

Login with your password

∘ Run: ps aux|grep "restart udev" (this will list the offending udev process on your screen)

∘ Run: kill -15 xxxx ( where you replace xxx with the process number listed as "restart udev"

∘ Now you should see in your original ssh terminal where you are running the apt-get upgrade, that the installation continues.

Wait for this to finish and run the following to exclude udev from the upgrade process in the future: echo udev hold | dpkg --set-selections

• Your upgrade might ask to update your GRUB-configuration file. In most cases it is save to over write you existing file with the new updated one from the package maintainer.

• Now your upgrade is complete this is another fine moment to make a new snapshot of your system, before continuing. Also not required but recommended, the reboot involved in making a snapshot will straighten any stray bits that might have been caused by installing so many new upgrades.

Installing Linux Guest Addition software to utilize VirtualBox shared-drive (optional):

You can use a shared folder to transport files to and from your VM, or even to create a watch folder to auto-load torrent files (not working in the current uTorrent version today?)

• Make sure the VM is again up and running

• In the VM window click "HOST+D" or go to "Devices-->install guest additions"

• Or you can do grab a manual download from: http://dlc.sun.com.edgesuite.net/virtualbox/

• Double check if the cd-image is hosted on the IDE CD-Rom device, by right clicking the CD-Rom icon in the bottom of the VM window.

Login via SSH again on your VM (as described above)

• Run: apt-get install dkms (to install dynamic kernel module support)

• Run: uname -r and take note of the displayed kernel release

• Run: apt-get install build-essential linux-headers-"output of uname -r"

∘ example: apt-get install build-essential linux-headers-2.6.32-34-generic

• Run: mkdir /media/cdrom (to create a mount point for your cdrom containing the guest additions)

• Run: mount /dev/cdrom /media/cdrom (/dev/cdrom might be named different in your installation, like /dev/cdrom1)

• Run: cd /media/cdrom (to go to your newly mounted CD-Rom.

• Run: ./VBoxLinuxAdditions-x86.run (this will execute the installation script for the guest additions)

• Run: mkdir /media/shared

• Run: mount -t vboxsf share_name /media/shared (Where "share_name" is the actual name you gave your share in the VirtualBox configuration. to manually mount this share, for the current session)

• Make sure there is some file(s) in the shared-driver and run: ls /media/shared (the output of this command should confirm that it is working as it should)

• To make this share permanent and execute on reboot:

∘ For this to work you need to give your shared drive a name with lower-caps otherwise you risk running into error: sbin/mount.vboxsf: mounting failed with the error: Invalid argument

∘ Run: pico /etc/fstab (open your mount configuration file in a text-editor)

∘ Add the following on a new empty line in the fstab file: share_name /media/shared vboxsf defaults 0 0

∘ Press "CTRL+X", type "y" to save and "enter" to confirm saving with the same name.

∘ Run: "mount -a" to test if this works as disigned and when there are no errors it will work upon reboot.

• Now is again a good time to make a new snapshot of your system, and give it a recommended but not needed reboot.

Create a new non-root user for utorrent to run:

• Most easy way to do this is to log into the webmin tool provided in the turnkey installation

• use a browser to browse to https://123.123.123.123:12321 and login with your root credentials

• Browse to: "system --> users and groups"

• Click: Create a new user

∘ Username: torrent

∘ Real name: torrent

∘ Password: torrentpass

∘ Check that home directory is set yo: automatic

∘ Scroll down and click: create

Downloading and Installing uTorrent:

• Open a new terminal and use SSH to login as the new user: SSH torrent@123.123.123.123

• Run: wget http://download.utorrent.com/linux/utorrent-server-3.0-25053.tar.gz (at the time of reading the version and file name might have changed, so check for the latest version first)

• Confirm that you received your download by running: ls

• Unpack the received package: tar -zxvf utorrent-server-3.0-25053.tar.gz

• This will have created a directory called: utorrent-server-v3_0, containing all files from the tar.gz-archive

mv utorrent-server-v3_0 utserver (rename this directory to something easier to remember)

• clean up after ourselves by deleting the unneeded original tar: rm -v utorrent-server-3.0-25053.tar.gz

• Lets start uTorrent for the first time: /etc/utserver/ & ./utserver

• Ignore all errors about missing files, Utorrent will create all files needed himself later on.

• Test if everything is working by browsing on you host machine to http://123.123.123.123:8080/gui , If all went well you will see the webinterface of utorrent. (default login credentials is admin\blank)

• For the time being you can exit uTorrent again by pressing CTRL+C and wait a second until it exits.

Configuring uTorrent:

- If you are not logged in anymore, login via ssh as user torrent: ssh torrent@123.123.123.123

• take root control by typing: su

• Run: mkdir /media/torrents (this will be your main storage for your torrent files etc.. you can change the location according to your own setup)

• Run: mkdir /media/torrents/completed-downloads (here will be your completed downloads)

• Run: mkdir /media/torrents/new-downloads (here will be your current in-complete downloads)

• Run: mkdir /media/torrents/completed-torrents (here will be your .torrent files of completed downloads)

• Run: mkdir /media/torrents/current-torrents (here will be your .torrent files of downloads in progress)

• Run: chgrp -Rv users /media/torrents (to set user permission of this directory to the torrent user)

• Run: chmod -Rv 775 /media/torrents/ (to give the correct file permissions for the torrent user)

• Exit root user: exit

• Leave this shell running, but open the console of the running VM

• Use ALT+ -> to switch to another terminal and log in as "torrent"

• Start uTorrent with the following commands:

cd utserver/

./utserver

• Open the webgui in a local browser

• Go to Preferences

• You can make lots of different options here so i will only list a few of the things i think should be generic or important enough to mention in this how-to:

@webgui: set a new username and password

@general: set "pre-allocate all files" (especially if you use a dynamic disk space setup for your VM)

@directories: set here all directories as created in /media/torrents/....

@directories: you can also set here /media/shared as a watch-folder for new torrents (however to my best knowledge this option is not yet functional today?)

@bandwidth: Make sure you are not overkilling the amount of connections that uTorrent can make simultaniously.

Save settings and exit preferences screen

• Now we should be able to download your favorite linux distro from linuxtracker.org/

∘ Browse to: http://linuxtracker.org/

∘ Go to: torrents

∘ Today "ubuntu 11 10 desktop i386 iso" has about 3700 seeds and should give you max-speed

∘ To find the best seeded distro click the small blue "S" above the distro list.

Click the link to your desired distro to see the details

Right-click on the download link and copy the link location\address

∘ Go to the uTorrent web-gui and click "add torrent"

∘ Past the link location into the field that say: Torrent URL (in this test case the correct URL was: http://linuxtracker.org/download.php?id=8ac3731ad4b039c05393b5404afa6e7397810b41&f=ubuntu-11.10-desktop-i386.iso.torrent

∘ After hitting "ok" your download should start downloading pretty quick :)

• Finaly lets check if the directory set-up is working correctly:

∘ While downloading you should see the download and the .torrent file is the following directories:

ls /media/torrents/new-downloads/

ls /media/torrents/current-torrents/

∘ And after the download you should see the files have moved to:

ls /media/torrents/completed-downloads/

ls /media/torrents/completed-torrents/

Add init upstart for Utserver autostart on reboot:

• Be adviced that i'm using the upstart script from vortex-5 as found on the uTorrent forums, this is not a official solution, but it should work perfectly :)

SSH into your VM again as root

• Run: pico /etc/init/utorrent.conf

• Copy paste below script into the file (if your setup differs from above how-to you might need to make changes according to your local setup)

• Reboot your system: shutdown -r now

• Test if the uTorrent comes up automatically by browsing to the uTorrent webgui on your local machine

# It is highly recommended that you run this under a user account and not as root
# The LOGFILE must also be set to a directory writable by the user account

# Location of the log file (must be by the current user writable)
env LOGFILE=/home/torrent/utserver/log/utorrent.log

# Path to the utorrent server
env UTORRENT_PATH=/home/torrent/utserver

# Name of the utorrent server binary (you usually don't need to change this)
env EXEC=utserver

# Nice value you can comment this out if don't want to run at a lower priority
# nice 15

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [016]

# It is highly recommended that you don't run as the root user you will need
# to change this line to have your own user account for example:
#
# exec su <your user account> -c <utorrent command>

exec su torrent -c "$UTORRENT_PATH/$EXEC -settingspath $UTORRENT_PATH -logfile $LOGFILE"

post-start script
#bind validation
while [ ! -e $LOGFILE ]; do
sleep 1 #Wait for file to be generated
done

while [ ! -n "$(cat $LOGFILE|grep 'IPv6 is installed')" ]; do
#wait until utorrent has finished bootup (IPv6 MESSAGE is the last message)
sleep 1
done

RESULT=$(cat $LOGFILE|grep 'bind failed')
if [ -n "$RESULT" ]; then
#bind failure stop the job
exit 3
fi
end script

post-stop script
#block process until server is completed shutting down fully
while [ -n "$(pidof "$EXEC")" ]; do
sleep 1
done

rm $LOGFILE
end script

Mounting a Samba shared drive from your Host-machine:

• In this chapter i assume you already have a running Samba server on the host computer and have atleast a working share setup with the user torrent added to the write-list.

• logged in as root issue the following commands:

• Run: apt-get install smbfs (this will install support for the smb filesystem)

• Run: pico /etc/fstab

• Add the following line: //10.0.0.10/Dump /media/dump smbfs username=torrent,password=torrentpass 0 0

Replace 10.0.0.10 with your own IP or computername

Replace /Dump with your share name

Replace /media/dump with the location where you would like to have this mount on your torrent server

∘ Make sure you create /media/dump with the mkdir command before mounting the drive.

• Run: "mount -a" to activate the mount

• You will now be able to move files here and access them from your host computer (or whatever computer is hosting this samba share)

Make sure to create another snapshot of your VM after finalizing your setup, and BEFORE adding any torrents to your client.

Additional possible setups and tweaks not covered in this how-to:

This is all up to you, but you might need want a look at the below ideas and recommendations:

• Installing a Samba server to share the files you downloaded across your network, and use your favorite local file browser to fetch and organize your files.

• Installing a FTP server to be able to fetch your files also across different networks, or from anywhere in the world

• Mask and hide your IP using different available solution like (public) proxy's or VPN solutions.

• In case you would like to implement any remote administration on this box i would recommend you using some sort of SSH tunnel.

• Configure your router to give your VM a dedicated IP-address in the DHCP table based on MAC-address or host-name so you always know where to find this machine.

• Be sure to use the webmin iptables based firewall to close all ports not needed by any of the following software: basic networking maintenance, SSH, uTorrent, FTP, Samba, Webmin, SSH-in-a-box or anything else you installed. After doing this it might be a good idea to open-up the DMZ to this machine so it lets all traffic through for best connectivity to your uTorrent

• Use forced encryption in your uTorrent configuration, it will reduce the amount of available clients that can connect to you, however it will increase security. A middle way is to enable encryption but not force it, and allow incoming legacy connections.

• You could remove the GRUB-countdown to increase boot-up speed of your system.

• Installing a IP-filter solution to block IP's of suspected authorities (MPAA, RIAA, etc)

• Installing anti-virus software

Credits, thanks and sources:

Jeremy (aka JedMeister) at the Turnkeylinux support forums for posting the initial bug concerning the apt-get upgrade freeze while udev reboot, and follow-up on this issue by sumerizing the correct workaround. http://www.turnkeylinux.org/forum/support/20100928/tkl-lucid-core-apt-get-upgrade-freeze-installing-udev-151-121

David Hillman at the Turnkeylinux forums for posting his supurb how-to on installing Linux Guist additions. http://www.turnkeylinux.org/forum/general/20110128/lamp-and-virtualbox-4-shared-folders

Everyone that contributed to the following thread on the uTorrent forums with links, advice, and troubleshooting tips. https://forum.utorrent.com/viewtopic.php?id=83842

Upstart script from Vortex-5: https://forum.utorrent.com/viewtopic.php?pid=612724#p612724

http://www.turnkeylinux.org/ - Thanks for providing such a great resource friendly platform for all my VM needs.

http://www.utorrent.com/ - Thanks for providing the best BitTorrent application available, and now also for Linux.

So that was a lot of typing, hope someone will find this usefull :)

Regards

Kamaradski

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...