So you may have read the article Rob posted at Bauer-Power on how to setup a fast dedicated torrent server but can't find a good deal on a server. Not to worry, there is another way to get those torrents fast. That solution is EC2 from Amazon AWS. Amazon's EC2 is a pay as you go type service where you only pay for how long the server is running (by the hour) and for how much bandwidth you use (per GB). EC2 has multiple types of instances that have different amounts of RAM and CPU resources available. For a complete list of the different types of instances and how much they cost you can check out aws.amazon.com/ec2/
An advantage of EC2 over a dedicated server is that once you shutdown your instance, the data stored on it is erased and reallocated to be written over by other EC2 users. So any sensitive data can't be recovered after you are done with the server.
What You Need
In this article I am going to show you an alternative way that is more cost effective for setting up a dedicated server for torrents.
What you will need:
- An AWS account from aws.amazon.com (Free)
- Once you have your AWS account you will need to sign up for EC2 (Free)
- Some knowledge of Linux (EC2 has Windows instances but that’s not going to be covered here)
- An SSH client
- A plug-in for Firefox called ElasticFox, an awesome and easy way to manage your EC2 instances right in Firefox.
Back in the article Rob did he used rtorrent, a text based torrent client. In this article I am going to show you how to setup a web based torrent client, that I think is more user friendly, called TorrentFlux. TorrentFlux is web front-end written in PHP with a MySQL backend for the tomato torrent client. I could go on for a while on its features so just check out their site for all the details on what it can do. If you still want to just use the same client, refer to that article on setup as it will be the same thing on the setup once the server is up.
Because the client I am showing here is web-based we will need to setup a few additional things.
So the software we will be using is:
- Ubuntu as the server OS*
- The Apache Web Server with PHP5
- MySQL server
* any linux distro will work the same way, though the commands to install apache, php and mysql will change slightly
Registering and setting up Amazon EC2
Now that we have the boring stuff out of the way lets get started getting our torrent server setup.
Open up Elasticfox by going to Tools->Elasticfox. The first time you you open Elasticfox you will be asked if you would like to enter your AWS credentials so select "Yes".
You will need your AWS Access Key and your AWS Secret Access Key. You can get these by logging into your AWS account and selecting "Select Account Identifiers" from the left hand navigation. They are located on the right on side of the page each labeled.
You will also need to add your Account ID to Elasticfox by selecting the Account IDs button at the top
This number is located near the top of the page under your name when you are logged in.
Once you have entered that information you are ready to move on. In my case I noticed that Elasticfox did not update correctly after I entered the info and I had to close the tab and reopen it. Results may vary.
Accessing your Amazon EC2 Server
Now before we go and start up our server we need to setup a few things so that we can access our server.
All EC2 instances must be accessed using public/private key authentication. So lets create the key pair we are going to use to access our server. You will only need to do this once as you can use the same key pair for multiple servers.
Select the KeyPairs tab within Elasticfox and click the green key icon. A window will popup and you will need to give the pair a name. Once you have provided a name you will be ask were you would like to save the key pair. Just put it someone where you will remember as you will need to use the file it creates later on.
On top of public/private key authentication EC2 has what are called Security Groups. They are basically firewall rules for allowed and blocked ports. Now by default you have one Security Group named default which has no ports open. So we will need to add two ports so we can access our server. Those are 22 and 80. Select the Security Groups tab. You will notice two sides. The one of the left shows your different groups and the one on the right shows all of the rules for that group. On the right side select the green check icon to create a rule. Elasticfox has some default options for standard ports like SSH and HTTP. So select SSH and for the host you can enter your IP address so only you can access the server or you can enter 0.0.0.0 and allow any IP address to connect.
For security reasons I would recommend that you only select your IP*. You will repeat this process for HTTP.
* You can find out what your public IP is by going to a website like IPChicken. Depending on your ISP, your IP address might change over time, so you might need to change the IP address that is allowed every once in awhile.
Now if you are going to use PuTTY for your SSH client there is one thing we need to do to be able to use the key pair we generated earlier. We need to create a PuTTY compatible version of the private key so we can access our server. To do this we will need to use a program called PuTTYgen. You can get it from the same website you get PuTTY from.
Once you have PuTTYgen open select the Load button. Once the Open File dialog box appears you will need to change the File of type to All files so you can see the .pem file that was created. Now locate and select the file you saved when creating your key pair. Once the key pair is loaded you can create password that will be need to be entered every time you authenticate with the private key, this is optional. Now select the Save private key button and save your PuTTY version of your private key where you can find it later.
I know that this is a little time consuming, but not to worry you only need to do this part once. After this all you need to do is create your instance with your key and in your security group, install the software and you are ready to go.
Return to Elasticfox and select the AMIs and Instances tab and select the refresh button.
You will now see a list of available images to create your instance from. For this article I am using ami-1a5db973. You can type that in the text box located on the right. Once you have it selected, click the green power button. You will then be presented with a window to select your instance type, the key pair to use, the number of instances to launch, and the security group. Once you have those selected, click launch. Once you select launch you will see it in the "Your Instances" window at the bottom. It will say that the state is pending until the instance is ready for you to login. Select refresh until the state is running. Once it is running we can continue.
Now open PuTTY (or your SSH client of choice). Enter the Public DNS of your instance. Then under the Category section on the left select plus on SSH and select Auth. Under there you need to browse and select the private key associated with key pair you selected when you launched the instance. Once you have loaded the private key select open. When the connection is open you will need to say yes to the instance key. When asked for the username just enter "root" and press enter. Since we are using public/private authentication you will not need to enter password (unless you selected a password for your private key).
Configuring the EC2 Server for Torrenting
Yes!!! Finally!!! You did it!!! You now have your EC2 instance running.
Now that you logged into your instance we can get to work on getting the rest of this setup. If you have never used Linux before, some of the terminology that follows may be a little confusing. If you are interested in learning what all these terms mean, I suggest using Google. Otherwise, just follow the commands listed and you will be all set!
The first thing you need to do is update the repositories to make sure we get the latest packages. You can copy and paste all of the following commands into PuTTY, and it will work. No need to type them out manually, I did all the hard work for you!
In the shell run:
apt-get update; apt-get dist-upgrade
When it asks you to continue just type Y and wait for the update to finish. This should take less than a minute.
Please note that securing this instance is outside the purpose of this article and it is up to you to make your server instance secure. You should be quite secure by default if you followed the above directions and only allowed your IP to access the server over SSH.
Once its finished run the following to install apache 2:
apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1
Once that completes you should now have apache running. Make sure its running by opening the public dns in your web browser and see if you get the default apache page.
Now that you have confirmed that the server is working we are going to install php5.
Type the following into the terminal:
apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-mysql
After that process completes run the following to install the mysql server.
apt-get install mysql-server
During the install process you will asked to set the root password for mysql. You can set this to whatever you want but it is something that should be secure.
Now run the following command to reload the apache web server to load php with the mysql module.
We are almost there, I promise. After that completes you have a few more things until you can start downloading torrents.
We will now need to download TorrentFlux via http://downloads.sourceforge.net/torrentflux/torrentflux_2.4.tar.gz?modtime=1213797423&big_mirror=0
To get that file on your instance you can run the following command:
Once the download completes we need to untar the file. You can do so by running:
tar zxvf torrentflux_2.4.tar.gz
Then to work with easier folder names we are going to rename the folder from torrentflux_2.4 to just torrentflux. To do this just run:
mv torrentflux_2.4 torrentflux
The next step involves preparing the mysql database. You will first need to login into mysql server by running:
mysql -uroot -p[your password] -hlocalhost
Once logged into the server run the following SQL to create your torrentflux database:
CREATE DATABASE torrentflux;
Now switch to that database by running:
All of the actions you run now will affect the torrentflux database. To make things easy, torrentflux has provided a sql file that will prep the database for us. To load that file run this command.
Once that completes you can type exit to logout of mysql. Now we need to copy the torrentflux php files in the the default apache root of /var/www (on debian based distributions at least).
We will need to create a directory for the files to live. To do that run:
First you will need to change directories into the torrentflux directory. Then run the following command to copy the files to that directory.
cp -r html/* /var/www/torrentflux/
Now that the files are copied you just have two things left to do before TorrentFlux is ready. First cd (stands for Change Directory, or in Windows speak changing folders) into the /var/www/torrentflux directory. Then open config.php into your favorite editor. I like nano so you could run:
Scroll down with the down arrow until you see settings related to "Your Database Connection Information"
Once you have found it adjust the information there to match your mysql server settings.
After you make those changes they can be saved by pressing Ctrl & O. Then you can exit nano by pressing Ctrl & X.
The second thing to do it chmod the download directory to allow things to be written. You can do so by runnning:
chmod +w /var/www/torrentflux/downloads/
Then you will need to change the ownership to the apache user of www-data by running
chown www-data -R /var/www/torrentflux/downloads/
Setting up TorrentFlux
You can now access TorrentFlux by going to the public dns name of your instance and go to the torrentflux directory.
You will be asked to login. Whatever you enter here will be your username and password from here on out to login to torrentflux.
This will be the same every time you create an instance and install torrentflux
The interface is self explanatory and you should be able to figure it out. I might seem like a lot of steps to load up an instance and installing apache, php, mysql and torrentflux but you get a fast and cheap torrent server.
I might work on creating a custom EC2 AMI that has all of these things installed and ready. Then all you would have to do is launch the instance, set the TorrentFlux username and password and you will be all set. I will let Rob know and possibly post here when that might be available for you.
If you have questions about something, feel free to leave a comment and I will try to check them on a regular basis and help where I can.
About the author: Ben Haan is a web developer and coding junkie that lives in West Michigan. He'd love it if you stopped by his blog, BenHaan.com.