Setup a linux seedbox from scratch using Arch Linux and TFlux-b4rt

courtesy of lowtide.

NOTE: This guide is not intended for noobs! I try to explain all the steps, but a lot of computer knowledge and knowledge of the linux operating system will help tremendously. But don’t fret, if you pay close attention to the guide and follow it step by step everything should go without a hitch. There is also A TON of help at http://wiki.archlinux.org, please go there first before asking people questions since chances are it will solve your problems.

Part 1: Setting up the base Arch Linux system.

NOTE: This is just installing linux, for help, go to:
http://wiki.archlinux.org/index.php/Beginners_Guide
You can follow this to setup the machine, but there are a few details that are specific to servers not mentioned in the wiki.

1. Download an Arch Linux installation iso from one of the mirrors at http://www.archlinux.org/download/ and burn it to a cd. Arch Linux is available for i686 and x86_64 architectures. I suggest getting an FTP release so it is as up to date as possible. Iso’s are located in mirror > iso > latest.

2. Put the CD in the box you want to install linux on, and restart the machine. It is helpful to know what hardware is in the box before this step to make configuring it easier. Also THIS WILL DESTROY ALL THE DATA CURRENTLY ON THE BOX! Please make sure you backup anything you want to save!

3. Welcome to the Arch Linux setup! You should see a bunch of text fly by and eventually greeted with a nice introductory letter and a login prompt. Login with the username ‘root’ and you will now be at a bash prompt. Type ‘/arch/setup’ to initiate the setup script.

4. When it asks where the installation source is, choose FTP.

5. Select ‘0. Configure Network’, select your network interface (usually eth0) and select ‘DHCP’. This should connect you to the internet.

6. Select ‘1. Prepare Hard Drive’, and select ‘Partition Hard Drives’. This will send you to a program called ‘cfdisk’ and if you have never seen it before might look a little strange. The up/down arrows select partitions and the right/left arrows select options. If there are any partitions listed, go ahead and delete them since we will be completely repartitioning the hard drive. Now, create a new primary partition, 8096MB in size (8GB is more than enough for a root partition for the server we are making) placed at the beginning of the drive. Next, create another primary partition, this time if you have 512MB of RAM installed, make the partition 1024MB in size, otherwise equal the size of the partition to the amount of RAM installed, and place this one at the end of the drive. Now we need to change the type of this partition to swap, so highlight it, and go to the type option and change it to ‘82′. Finally, make one last partition, the rest of the size of the disk at the beginning of the drive. Go to the ‘Write’ option to apply changes.

7. Select ‘2. Set Filesystem Mountpoints’. If you followed the last step to the tee, your drive will be set up with sda1=8GB, sda2=swap and sda3=rest of drive. It will first ask you what partition to use for swap, select sda2. Next is the partition for the root partition, select sda1 with filesystem XFS. Now choose to mount sda3 also, and when it prompts for a mount place that defaults with ‘/boot’, change it to ‘/home’, again using filesystem XFS.

8. Select ‘3. Select Packages’ and choose a mirror to download the installation from. I use http://mir.archlinux.fr since it is usually up to date and rather fast. When the prompt comes for ‘base-devel’, select it with the space bar and then press enter to start downloading. If you want to view the progress, press Alt f5, Alt f1 goes back to the installation screen.

9. Select ‘4. Install Packages’ and select ‘Yes’. Let it do its business and press enter when it is done.

10. Select ‘5. Configure System’. This is where paths will split and I suggest going to the Arch Linux wiki to get box specific info. Anyway, select ‘Yes’ when it asks about hwdetect, a ‘No’ for everything after UNTIL you are met with a prompt for a text editor, either NANO or VI. If you know how to use vi, do it, otherwise choose nano. You are met with a list of configuration files:

/etc/rc.conf: Change ‘HARDWARECLOCK’ to ‘UTC’, ‘TIMEZONE’ to ‘US/Eastern’ (for east coast usa). DO NOT TOUCH THE HARDWARE SECTION. Change ‘HOSTNAME’ to whatever you want to call your box, mine is zen, and ‘eth0′ to ‘dhcp’. DO NOT TOUCH THE DAEMONS SECTION.

/etc/hosts: add the hostname that you chose in /etc/rc.conf after ‘localhost’, separated by a space.

/etc/locale.gen: open this file and exit it.

Root-Password: set an admin password

Pacman-Mirrorr: Select ‘Yes’.

Step 11. Select ‘6. Install Bootloader’ and choose ‘GRUB’. When you are met with the configuration file, exit it, then select ‘/dev/sda’.

Step 12: All done! Exit the install, type reboot, and remove the CD when the machine is starting up. If all is well, the machine should boot your brand spanking new Arch Linux installation and greet you with a login prompt. This can look VERY sparse if you have never seen it before.

Part 2: Setting up the system

NOTE: We will not be installing a Desktop Environment since we don’t need one. Feel free to follow the wiki if you wish to.

Step 1: Login with username ‘root’ and whatever root password you chose. Next, update the package management databases with ‘pacman -Syu’. Once done, ‘pacman -S sudo’ to install sudo, then ‘nano /etc/sudoers’ and remove the ‘#’ before the line ‘%wheel ALL=(ALL) ALL’.

Step 2: Now we will add an unprivileged user so we don’t mess anything up to much. Type ‘adduser’, choose a username other than ‘http’ or ‘root’ or the hostname you chose, press enter for ‘User ID’, enter for ‘Initial group’, then type ‘optical,storage,wheel,video,audio,power’ for ‘Additional Groups’. Enter for ‘Home directory’, enter again for ‘Shell’, and enter again for ‘Expiry date’. Finally, press enter to make the account and fill in the information if you want or just press enter to opt-out.

Step 3: Now type ‘exit’ and login with your newly created account.

Part 3: Turning it into a LAMP server

NOTE: For help, http://wiki.archlinux.org/index.php/LAMP

Step 1: Type ’sudo pacman -Sy apache php mysql’. This installs the server, so let it finish.

Step 2: Type ’sudo mkdir -p /home/http’. Type ’sudo chown http:http /home/http’. This creates a directory for the downloaded files, and makes the server able to access them. Also, type ’sudo chwon http:http /srv/http’, making the webserver able to access its own files.

Step 3: Type ’sudo nano -w /etc/httpd/conf/httpd.conf’, scroll down and put a ‘#’ before the line ‘LoadModule unique_id_module modules/mod_unique_id.so’.

Step 4: Type ’sudo nano -w /etc/rc.conf’ and add ‘httpd’ to the end of the DAEMONS line, but make sure it is still in parentheses. This will autostart the server when the seedbox is booted.

Step 5: Try it out! Type ’sudo /etc/rc.d/httpd start’, invoking the server. Now go find another computer and punch in the ip of the seedbox in the address bar of a web browser. You should get an empty apache directory. YAY!

Part 3.33 repeating: Setup PHP

Step 1: Type ’sudo nano -w /etc/httpd/cont/httpd.conf’ and scroll down to the end of the list of ‘LoadModule’. At the end, type ‘LoadModule php5_module modules/libphp5.so’ and ‘Include conf/extra/php5_module.conf’ on two separate lines.

Step 2: Find ‘open_basedir’ and add ‘:/bin/:/usr/bin/:/usr/local/bin/’ to the end of the line (follow the pattern).

Step 3: Find ‘allow_url_fopen = Off’ and change it to ‘allow_url_fopen = On’

Step 4: Type ’sudo /etc/rc.d/httpd restart’ to restart the server. There is a script to test PHP on the wiki link at the beggining of this part, do it.

Part 3.66 repeating: Setup MySQL

Step 1: Type ’sudo /etc/rc.d/mysqld start’ to invoke MySQL.

Step 2: Type ’sudo /usr/bin/mysql_secure_installation’ and follow the steps, disable anonymous login and test database.

Step 3: Type ’sudo nano -w /etc/my.cnf’ and add a ‘#’ in from of ’skip-networking’.

Step 4: Type ’sudo /etc/rc.d/mysqld restart’ to restart MySQL with the changes.

Step 5: Login to MySQL with ‘mysql -u root -p’ and input the password you chose. Now we need to add a new user to mysql, this will also be your login name/password for torrentflux-b4rt. In the mysql shell type "GRANT ALL PRIVILEGES ON *.* TO ‘choice of username‘@’localhost’ IDENTIFIED BY ‘choice of password‘ WITH GRANT OPTION;"

Step 6: Now we need to allow php to use mysql, type ’sudo nano -w /etc/php/php.ini’ and remove the ‘;’ from the front of the ‘extension=mysql.so’ line.

Step 7: To allow torrentflux-b4rt to connect to the mysql server, type ’sudo nano -w /etc/hosts.allow’ and add ‘mysqld: ALL’ anywhere in the middle of the file.

Part 4: Installing torrentflux-b4rt

Step 1: First, we need some necessary binaries for torrentflux-b4rt to function properly. Type ’sudo pacman -S uudeview unzip cksfv vlc unrar tar bzip2′.

Step 2: Type ‘wget http://prdownload.berlios.de/tf-b4rt/torrentflux-b4rt_1.0-beta2.tar.bz2′ and let it download.

Step 3: Type ‘tar xvjf torrentflux-b4rt_1.0-beta2.tar.bz2′ and move into the new directory by typing ‘cd torrentflux-b4rt_1.0-beta2/html’

Step 4: Move the torrentflux-b4rt files to the server root by doing ’sudo mv * /srv/http’. Now we need to make the server able to read/write these files, so do ’sudo chown -R http:http /srv/http’.

Step 5: DONE! Now restart the seedbox, and point a browser to ‘http://ip.of.the.seedox/setup.php’ and follow the steps! Choose ‘/home/http’ for the download folder, and that is about the only setting needed to change!

Now what?

Torrentflux-b4rt is able to use may dfferent bittorrent clients, so choose the one you prefer:

sudo pacman -S bittorrent azureus

If you want to use transmission or bittornado (transmission is my preferred client, it seems to cut down on resources and doesn’t kill my connection) you need to build them. Type ‘cd’ to get to the home directory, go into the base with ‘cd torrentflux-b4rt_1.0-beta2′ folder and ‘cd clients’, then read the installation instructions. Set which client to use in torrentflux-b4rt gui, ‘Admin > Transfer’.

Also, you may want to install ssh so you can work on the machine from elsewhere:

sudo pacman -S sshd

Now add ’sshd’ to the end of the ‘daemons’ line of /etc/rc.conf/ using:

sudo nano -w /etc/rc.conf

And to allow access, add ’sshd: ALL’ anywhere in the middle of /etc/hosts.allow with:

sudo nano -w /etc/hosts.allow