Skip navigation.

Posts tagged with "tutorial"

SERVER : Install eAccelerator so that PHP pages load faster

, , , ...

The latest version of the PHP cache eAccelerator has been released… one of the more popular PHP extensions that attempts to speed up PHP performance. This is first non-beta of eAccelerator that supports PHP 5.1 and PHP 5.2.

So, first of all, we need to get eAccelerator, for that you can go do the eAccelerator site and download the latest build in some folder you'll be able to access (just make shore you get the tar.bz2 file).

I assume the folder you used is /mnt/local/install, if its not then modify the following commands to reflect that.
So, first we need to extract the archive, for that do
cd /mnt/local/install
tar xvjf eaccelerator-0.9.5.tar.bz2
(of course, the filename might be different if you're using a newer version).

Now we need to install the development packages, because we need to compile eAccelerator. For that do this :
sudo apt-get install build-essentials php5-dev

After it finished installing we need to run the following commands :
cd eaccelerator-0.9.5
/usr/bin/phpize
sudo ./configure --enable-eaccelerator --enable-shared --with-php-config=/usr/bin/php-config
this will configure PHP and the eAccelerator. If you didn't get any errors you can go on and biuld the eAccelerator module, for that do this :
sudo make
sudo make install

After the compilation finishes, we need to configure Apache to use this module too. For that, run this
sudo editor /etc/php5/apache2/php.ini
and add the following lines to the end of the file
# eAccelerator
#zend_extension="/usr/lib/php5/20051025/eaccelerator.so"
extension="eaccelerator.so"
eaccelerator.shm_size="0"
eaccelerator.cache_dir="/var/local/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.allowed_admin_path="/var/www/apache2-default/control.php"

now, for safety, add the same lines to the PHP-CGI too, for that run
sudo editor /etc/php5/cgi/php.ini
.
Now we need to create the temporary folders that will be used by eAccelerator, for that do the following :
sudo mkdir /var/local/eaccelerator
sudo chown root:www-data /var/local/eaccelerator
sudo chmod u=rwx,g=rwx,o= /var/local/eaccelerator

The last thing left to to is to chec if the configuration is OK, so run
apache2ctl configtest
if it says Syntax OK then restart apache2, for that do this
/etc/init.d/apache2 restart


If you want to see if eAccelerator is working, you might do this :
sudo editor /var/www/apache2-default/php_test.php
and enter in that page the following text
<?php
phpinfo();
?>
Now load up the http://your_server_ip/apache2-default/php_test.php page, and you should see the PHPInfo page, in there search for eAccelerator, and you should see something similar to this

To modify eAccelerator's settings, you need to copy the control panel. For that do the following
cp control.php /var/www/apache2-default
, now edit the file and change the user-name and password to something you can remember, this is needed so that nobody else can run the eAccelerator configuration utility. For that, run this
sudo editor /var/www/apache2-default/control.php
now scroll down to the /** config **/ part, and modify it to your liking, for example
/** config **/
$user = "my_user";
$pw = "my_password";
/** /config **/

After you've saved the file, it's time to check out the configuration page, for that, go to http://your_server_ip/apache2-default/control.php and log in with the user-name and password you've just set. From this page you ca n enable/disable the caching and optimization, you can also clear the cache, that's not really needed unless you get a PHP page that doesn't want to update (it rarely happens, but who knows, you might need it).

Performance tuning

Since eAccelerator first stores compiled PHP pages in shared memory, then on disk when that runs out, the size of the shared memory pool will likely have the largest impact on performance.

By default, eAccelerator uses the maximum shared memory available which on Ubuntu 6.10 seems to be around 33 MB, regardless of installed memory. That may be too large for a server with limited RAM… in low memory situations it’s better to leave more memory for applications and the Linux disk cache. You can reduce shared memory usage by setting eaccelerator.shm_size to something other than zero.

Conversely, if your server is dedicated to serving PHP pages and has lots of installed memory, increasing shared memory might improve performance. See the eAccelerator release notes for info on increasing available shared memory in the Linux kernel.

On a very busy server where PHP code doesn’t change often, performance might be improved by setting eaccelerator.check_mtime="0" to disable checking of source files for changes. Beware if you do this then when php files change you’ll have to clear the eAccelerator cache (via the control panel or using ‘apache2ctl graceful‘ at the command line) for changes to become visible.

SERVER : Adding a printer to the SAMBA share

, , , ...

Ok, so in the previous post I've showed you how to get SAMBA installed and how to add a shared folder to it.
Now it's time to move the printer to the server too, so anybody from the internal network can print on the printer, this is usually called "network printer" (well its not really a 100% network printer since the printer itself doesn't support printing trough the network, our server will do the network communications part).

Anyways, for sharing printers from linux you have to install CUPS (also known as Common UNIX Printing System).
For that, you'll have to do the following :
sudo apt-get install cupsys cupsys-driver-gimpprint defoma fontconfig foomatic-db foomatic-filters libcupsimage2 libexpat1 libfontconfig1 libfreetype6 libjpeg62 libpaper1 libpng12-0 libslp1 libtiff4 patch perl perl-modules ttf-bitstream-vera ucf

The instalation will take some time, as it has to download about 6Mb pf data.
After it finished installing, edit the /etc/cups/cupsd.conf file and edit to look similar to this :

You have to modify 192.168.1.1 to your server IP address so that you can configure the CUPS server from a remote computer too (the remote computer can be on the local network too).

SERVER : File and Printer sharing with Windows computers (using Samba)

, , , ...

After I've installed TorrentFlux on the server and downloaded the first files i've dicovered that using WinSCP to get the files from the server was just to slow, I've goft an avarage speed of 800-900Kb/s which is very low, especially since all my network devices are 100Mbps (which comes out to about 12 Mb/s).

While I was trying to figure out why was my file transfer so slow, I've discovered that SCP connections use SSH codification (or at least something similar) so that's why it's slow.
On the Ubuntu Forums I've read that I needed to install Samba and make some Samba shares in order to let the Win computers (and Linux too) gain access to shared resourcer (folders, printers, ...)

Step1 - Install SAMBA

Ok, so I should better show you how i've installed Samba and made the shares.
First thing, you have to install Samba, for that do this :
sudo apt-get install samba samba-common samba-doc libcupsys2-gnutls10 libkrb53 winbind smbclient
If you get a message that samba is already installed, similar to the one below
samba is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
it simply means you've already got samba installed (maybe you've installed something that uses it and that's why you have it installed).

Now lets modify the config file, you should run this :
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf-original
sudo editor /etc/samba/smb.conf
and you should modify the file to look something like the one bellow :
[global]
   workgroup = MYWORKGROUP
   netbios name = MERLIN
   server string = %h server (Samba, Ubuntu)
   
   passdb backend = tdbsam
   security = user
   username map = /etc/samba/smbusers
   name resolve order = wins bcast hosts
   domain logons = yes
   preferred master = yes
   wins support = yes
   
   # Set CUPS for printing
   printcap name = CUPS
   printing = CUPS
   
   # Default logon
   logon drive = Y:
#   logon script = scripts/logon.bat
   logon path = \\merlin\profile\%U

   # Useradd scripts
   add user script = /usr/sbin/useradd -m %u
   delete user script = /usr/sbin/userdel -r %u
   add group script = /usr/sbin/groupadd %g
   delete group script = /usr/sbin/groupdel %g
   add user to group script = /usr/sbin/usermod -G %g %u
   add machine script = /usr/sbin/useradd -s /bin/false/ -d /var/lib/nobody %u
   idmap uid = 15000-20000
   idmap gid = 15000-20000

   # sync smb passwords with linux passwords
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n .
   passwd chat debug = yes
   unix password sync = yes
   
   # set the loglevel
   log level = 3

[homes]
   comment = Home
   valid users = %S
   read only = no
   browsable = no

[printers]
   comment = All Printers
   path = /var/spool/samba
   printable = yes
   guest ok = yes
   browsable = no

[netlogon]
   comment = Network Logon Service
   path = /home/samba/netlogon
   admin users = Administrator
   valid users = %U
   read only = no

[profile]
   comment = User profiles
   path = /home/samba/profiles
   valid users = %U
   create mode = 0600
   directory mode = 0700
   writable = yes
   browsable = no


The "netbios name" in the smb.conf must be the same then the hostname of your server (Merlin in my case). Also make shore the logon path is correct to.
"workgroup = MYWORKGROUP" specifies the Windows domain that the Windows workstations use.
"logon drive = Y:" is the drive letter under which the SAMBA share will appear in the Windows Explorer.
With "logon script = scripts/logon.bat" you can specify a Windows batch script that is executed as soon as a Windows workstation logs in. If you want to use the script you must uncomment that line.

Now lets create the directories for domain logon and profiles :
sudo mkdir /home/samba
sudo mkdir /home/samba/netlogon
sudo mkdir /home/samba/profiles
sudo mkdir /var/spool/samba
sudo chmod 777 /var/spool/samba/ 
sudo chown -R root:users /home/samba/
sudo chmod -R 771 /home/samba/

Now you need to restart SAMBA so it takes the changes, for that execute
samba /etc/init.d/samba restart

Now edit the /etc/nsswitch.conf file with
sudo editor /etc/nsswitch.conf
and modify the hosts: files dns to be hosts: files wins dns.

Add all computers of your workgroup in the /etc/hosts file on the server
192.168.1.1 merlin
192.168.1.10 workstation1
192.168.1.11 workstation2
192.168.1.12 workstation3
192.168.1.13 workstation4
192.168.1.14 workstation5
192.168.1.15 workstation6

Add the root user to the SAMBA password database. The root user (alias: Administrator) will be our domain administrator. This account is needed to add new computers to the SAMBA domain.
smbpasswd -a root

Create the file /etc/samba/smbusers and add the line by executing:
echo "root = Administrator" > /etc/samba/smbusers

This will allow us to use the common windows username "Administrator" as alias for the Linux root user.

Now lets see if the shares are working, for that you can use this :
smbclient -L localhost -U%
you should get something similar to this :
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.22]

        Sharename       Type      Comment
        ---------       ----      -------
        netlogon        Disk      Network Logon Service
        profile         Disk      User profiles
        IPC$            IPC       IPC Service (merlin server (Samba, Ubuntu))
        ADMIN$          IPC       IPC Service (merlin server (Samba, Ubuntu))
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.22]

        Server               Comment
        ---------            -------
        WORKSTATION_1        emil's computer
        MERLIN               merlin server (Samba, Ubuntu)

        Workgroup            Master
        ---------            -------
        MYWORKGROUP          MERLIN

As you can see, my computer is also started, its name is WORKSTATION_1

On the Windows machines you should setup the default domain groups for windows, for that run this :
net groupmap modify ntgroup="Domain Admins" unixgroup=root
net groupmap modify ntgroup="Domain Users" unixgroup=users
net groupmap modify ntgroup="Domain Guests" unixgroup=nogroup
you could probably make a BAT (batch) file, put the above in it, and set that to be the script that's executed by SAMBA on login (the "logon script = scripts/logon.bat" from the smb.conf file)

Now we have to configure the Samba server and create the shares. In my case I wanted to share the /mnt/c and /mnt/d folders and make them fully accessible to the users i've created (this is so because the 2 partitions where supposed to be a kind of backup or sharing drives). You might want to make some folders in the /home/ folder and share those, it's all up to you.


Step2 - add user access

First thing, lets create some users that will have access to the Samba shares, for that use :
sudo useradd username_to_add -m -G users
sudo smbpasswd -a username_to_add
Of course the username_to_add will be the name of the user you want to add. The first line creates a new user on the server, adds him to the "users" group and creates his home folder too. The second one adds the user to the SAMBA password database and asks for the password.
You should see something like this :
New SMB password:
Retype new SMB password:
Added user username_to_add.

:idea: By default Windows computers don't use passwords for accesing shares, so if you want to "follow" that philosophy you can just press "ENTER" and leave the password empty.
But as any "linux guru" would tell you, it's better to put a password.

:idea::star: If you want to add a user that can access the SAMBA shares but don't want to have shell (command prompt) access on the server (this is the best method if you don't want to give them any kind of access on the server except for the shares), you should use the following :
sudo useradd username_to_add -m -G users -s /bin/true
sudo smbpasswd -a username_to_add
the "-s /bin/true" part will force the user to use /bin/true as shell, but that program doesn't do anything, so he actually doesn't have any access to the shell.

Step3 - create the shares

So, now we have the users, lets create the shares.
For that do the following
sudo mkdir -p /path_to_the_folder/you_want/all_users_to_access/
sudo chown -R root:users /path_to_the_folder/you_want/all_users_to_access/
sudo chmod -R ug+rwx,o+rx-w /path_to_the_folder/you_want/all_users_to_access/
The first command will create the folder /path_to_the_folder/you_want/all_users_to_access/ (of course you should enter what you want), the second command will make the folder accessible by any user who's part of the users group, and the third command will enshure the folder is writeable by all users (from the users group).

Now lets add the folder to SAMBA, so it knows what to share :
sudo editor /etc/samba/smb.conf
at the end of the file add this
[share_name]
  comment = All Users
  path = /path_to_the_folder/you_want/all_users_to_access/
  valid users = @users
  force group = users 
  create mask = 0660
  directory mask = 0771
  writable = yes
of course the share_name will be the name as it appears when you browse the computer in Network Neighbourhood (just make shore you don't put any special characters or spaces), and the path will be the path you just created before.

After you've added all the shares, you have to restart SAMBA so it reads its data again, for that run this command :
sudo /etc/init.d/samba restart

SERVER : TorrentFlux and MRTG for TorrentFlux problems.

, , , ...

Hy.

I've ran into some problems, and i thought I'd share how i fixed them.

:idea:First of all, i had to restart the server, and after that the graphs in MRTG didn't want to update anymore. After a while I've discovered that there's a folder missing, the /var/lock/mrtg folder. This is the folder that mrtg writes its lock file (the file used to know it's running, so only 1 instance can run at a time).
In order to recreate it here's what i did :
sudo mkdir /var/lock/mrtg
sudo chown www-data:www-data /var/lock/mrtg
sudo chmod 777 /var/lock/mrtg

Now, since it seems that I have to run this each time I reboot the computer, its better to put it in the /etc/rc.local file, so just run
sudo editor /etc/rc.local
and insert the above lines before the exit 0 line.
Here's my file as it looks like now :
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# start No-Ip so that my web-name is updated correctly
/usr/local/bin/noip2

# create the lock file for MRTG, it seems to get lost each time i restart the computer
mkdir /var/lock/mrtg
chown www-data:www-data /var/lock/mrtg
chmod 777 /var/lock/mrtg

# start IPKungfu, so port forwarding and gateway work correctly
/usr/sbin/ipkungfu

exit 0


:idea:Second problem was that I've managed to block TorrentFlux so badly that i wasn't even able to log in. I've tried restarting the Apache server but that didn't help, so when I was about to give up on TorrentFlux (and that would have been a shame) I've found out how to fix my problem.
Luckily, the developers of TorrentFlux included a little application that can be used from the console to control TorrentFlux. The application's name is fluxcli.
First thing was that I needed to find where it is, for that use this :
locate fluxcli.php
, you should get something similar to this :
/var/www/torrentflux/bin/fluxcli.php

Now that we know where it is, lets execute it, for that do this :
cd /var/www/torrentflux/bin
php fluxcli.php repair

FluxCLI can be used for other things too, for example you can start/stop torrents.
If you want to see what exactly fluxcli can do, just run it without commands, you should see something similar to this :
fluxcli.php Revision 1958

Usage: fluxcli.php action [extra-args]

action:
 <transfers>   : print transfers.
 <netstat>     : print netstat.
 <start>       : start a transfer.
                 extra-arg : name of transfer as known inside torrentflux
 <stop>        : stop a transfer.
                 extra-arg : name of transfer as known inside torrentflux
 <start-all>   : start all transfers.
 <resume-all>  : resume all transfers.
 <stop-all>    : stop all running transfers.
 <reset>       : reset totals of a transfer.
                 extra-arg : name of transfer as known inside torrentflux
 <delete>      : delete a transfer.
                 extra-arg : name of transfer as known inside torrentflux
 <wipe>        : reset totals, delete torrent, delete torrent-data.
                 extra-arg : name of torrent as known inside torrentflux
 <inject>      : injects a transfer-file into tflux.
                 extra-arg 1 : path to transfer-meta-file
                 extra-arg 2 : username of fluxuser
 <watch>       : watch a dir and inject+start transfers into tflux.
                 extra-arg 1 : path to users watch-dir
                 extra-arg 2 : username of fluxuser
 <rss>         : download torrents matching filter-rules from a rss-feed.
                 extra-arg 1 : save-dir
                 extra-arg 2 : filter-file
                 extra-arg 3 : history-file
                 extra-arg 4 : rss-feed-url
 <xfer>        : xfer-Limit-Shutdown. stop all transfers if xfer-limit is met.
                 extra-arg 1 : time-delta of xfer to use : <all|total|month|week|day>
 <repair>      : repair of torrentflux. DONT do this unless you have to.
                 Doing this on a running ok flux _will_ screw up things.
 <maintenance> : call maintenance and repair all died transfers.
                 extra-arg 1 : restart died transfers (true/false)
 <dump>        : dump database.
                 extra-arg 1 : type : settings/users
 <filelist>    : print file-list.
                 extra-arg 1 : dir (if empty docroot is used)
 <checksums>   : print checksum-list.
                 extra-arg 1 : dir (if empty docroot is used)

examples:
fluxcli.php transfers
fluxcli.php netstat
fluxcli.php start foo.torrent
fluxcli.php stop foo.torrent
fluxcli.php start-all
fluxcli.php resume-all
fluxcli.php stop-all
fluxcli.php reset foo.torrent
fluxcli.php delete foo.torrent
fluxcli.php wipe foo.torrent
fluxcli.php inject /path/to/foo.torrent fluxuser
fluxcli.php watch /path/to/watch-dir/ fluxuser
fluxcli.php rss /path/to/rss-torrents/ /path/to/filter.dat /path/to/filter.hist http://www.example.com/rss.xml
fluxcli.php xfer month
fluxcli.php repair
fluxcli.php maintenance true
fluxcli.php dump settings
fluxcli.php dump users
fluxcli.php filelist /var/www
fluxcli.php checksums /var/www

As you can see, it states clearly that you should not run fluxcli repair unless you really have to. So unless you get blocked out or something just dont use it :D I had to use it since I wasn't even able to log in, and it did repair my torrentflux. THe only thing is that i had to restart all torrents, but that was to be expected.

Happy downloding and graphing:cool:

SERVER : Install CACTI (or at least try to :-))

, , , ...

"CACTI is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices."

So, lets start installing CACTI.
First thing to do, is install its package, for that do
sudo apt-get install cacti

Of course, you'll have to be prepared to wait some time, as it needs to download about 6-8Mb of data.

At the beginning of the installation, you'll get a warning that the "Include path for PHP has changed", we'll deal with that later on, so just press the OK button.
After a while, you'll see another message, it asks you if you want to automatically add the database needed by cacti. Since we're installing it the first time, we should press Yes.
You'll be asked about the password of your root user (not the system root user but the MySQL root user) so you should enter that password then press OK, on the next screen it will ask for a password for CACTI, just let it create a random password and use that one, so press OKon the next screen it will ask what kind of webserver you're using, in our case is Apache2, so select that one.

If you get the following error : "mysql said: ERROR 1049 (42000): Unknown database 'cacti'" then open up your phpMyAdmin and create a new table with the cacti name. After you've created the cacti database, come back to the installer, press OK and then retry . It will jump back to the question if cacti should autoconfigure, just answer yes, enter the MySQL root user password and leave the cacti password empty.

If everything went OK, you should be returned at the prompt and see this :
dbconfig-common: flushing administrative password

Creating config file /etc/cacti/apache.conf with new version
 * Reloading apache 2.0 configuration...                                   [ ok ]



Now we need to open up a webpage to configure cacti, for that, open up a browser window with http://your_server_ip/cacti and you should see this page : just press the Next > > button.
On the next window make shore you select New Install and press Next > >
On the next screen you should have something similar with this image :
If everything seems to be ok then press the Finish button.
Now you'll get to the login screen. First time you should log in with admin as both username and password
Because of security considerations, it will now ask you to change the password for the admin user, so enter a password you can remember and then press Save.

:idea: If you can see the statistics but don't see any picture in CACTI, you might not have the php4-mysql or php5-mysql module installed or configured propertly. To check if the mysql module has really been added, you can check it with this :
php -m | grep mysql
you should get an answer similar to this :
PHP Warning:  mime_magic: type regex            BEGIN[[:space:]]*[{]    application/x-awk invalid in Unknown on line 0
mysql

If you don't get the above answer, then maybe your php4-mysql or php5-mysql module is not installed. You can force to install it with
apt-get install php4-mysql php5-mysql php5-mysqli

Now you should try this :
sudo dpkg-reconfigure php4-mysql
and answer Yes to the question if "Should MySQL be added to /etc/php4/cli/php.ini?"
Now do the same for PHP5, so run
sudo dpkg-reconfigure php5-mysql
and answer Yes to the question " Should MySQL be added to /etc/php5/apache2/php.ini?". You might get a second question "Should MySQL be added to /etc/php5/cgi/php.ini?" asnwer Yes to that one too.
Now we need to tell the Apache webserver to reload the settings, so just run this :
sudo apache2ctl restart

Now you should finally see your images.

:idea: Don't worry if at the beginning you see the images but there's no data just the grids, just leave some time (about 15-20 minutes) and then check the graphs again. After all, CACTI needs some time to pass in order to make the statistics.

Happy graphing.

P.S. I'm not going to tell you how to add new graphs, you should experiment, or simply look at the CACTI documentation for more info Here

SERVER : Install MRTG for TorrentFlux

, , , ...

Now that I've installed torrent flux, i wanted to see some graphs with the upload/download speeds, so i could see just how fast I'm downloading.

For that i need to install MRTG (for more info look at this site).

So, run this commands in the shell
apt-get install mrtg mrtgutils mrtg-contrib
It will ask you if you really want to install it since it will need to download about 8Mb of files, just answer with Y.
After the installation is done, it will ask you if you want to let only the MRTG user read the config file, you should answer with Yes
After a few seconds you end up back at the prompt with
Setting up mrtg (2.14.3-1) ...

Setting up mrtg-contrib (2.14.3-1) ...
lines above the prompt.
This means that we've installed MRTG.

Now lets configure TorrentFlux to use the MRTG.

Go to the folder where you downloaded and extracted the torrentflux archive and there's an addons/mrtg folder, get into it. If you've extracted the file in your home folder, simply execute this :
cd ~/torrentflux-b4rt_1.0-alpha5/addons/mrtg
.

Now, if you look inside (for example with ls command, you'll see a few files :
flux-mrtg.conf       
fluxpoller.pl  
mrtg.flux.examples.cfg
flux-mrtg-update.sh  
mrtg.flux.cfg


Now we need to customize this files to suit our needs.
First, we need to modify the flux-mrtg.conf file.
editor flux-mrtg.conf

now modify the FLUXPATH to be the folder where you set TorrentFlux to download the files to (in my case it's /mnt/d/Torrents) you should leave the rest of the settings as they are.
You should end up with something similar to this :
# $Id: flux-mrtg.conf 672 2006-09-10 12:29:05Z b4rt $

# set all lines after "CHANGEME" (get a list with: "grep -A 1 CHANGEME this")

# flux-path (aka "Path" in flux-settings)
# CHANGEME
FLUXPATH="/mnt/d/Torrents/"

# path to mrtg-conf-file.
# wherever this is, ensure directory is writable for the user running this
# script (-> user running mrtg) (mrtg creates a lockfile at its conf-file(s))
# CHANGEME
CONFFILE="/etc/mrtg/mrtg.flux.cfg"

# where is mrtg
# CHANGEME
BIN_MRTG="/usr/bin/mrtg"


Now we need to modify the mrtg.flux.cfg file too so execute
sudo editor mrtg.flux.cfg
and search for
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /usr/local/torrentflux mrtg`
you must modify the /usr/local/torrentflux to be the folder you've set for the downloads, in my case it will be
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /mnt/d/Torrents mrtg`


Now we need to create the folder where MRTG will save its data, for that execute this commands :
sudo mkdir /usr/local/torrentflux
sudo mkdir /usr/local/torrentflux/.mrtg
sudo chown -R www-data:www-data /usr/local/torrentflux
sudo chmod -R 777 /usr/local/torrentflux

This will create the folder, make it writable and owned by the Apache user (www-data).


Now we need to copy the files to their right place.
For that, execute this commands :
sudo mkdir /etc/mrtg
sudo cp flux-mrtg.conf /etc/mrtg
sudo cp mrtg.flux.cfg /etc/mrtg
sudo cp flux-mrtg-update.sh /usr/local/bin/
sudo cp fluxpoller.pl /usr/local/bin/



Now the MRTG should be configured, we should try it out, so execute this :
/usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf

If you get the following error :
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start:

       env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.flux.cfg
-----------------------------------------------------------------------
then we need to modify flux-mrtg-update.sh, so execute this
sudo editor /usr/local/bin/flux-mrtg-update.sh

Now go to the last line and edit it to look like this :
# invoke mrtg for flux
env LANG=C $BIN_MRTG $CONFFILE | tee -a $FLUXPATH/.mrtg/mrtg.log
save the file, exit and try it again
/usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf


You should get some errors that it can't remove or rename some files, that's ok
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for traffic
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for traffic was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove traffic.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename traffic.log to traffic.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for connections
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for connections was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove connections.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename connections.log to connections.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for loadavg
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for loadavg was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove loadavg.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename loadavg.log to loadavg.old updating log file
just run the aboce command 3 times and after that it should execute without giving any warning at all.

Now look in the mrtg folder (/var/www/mrtg) and there should be 2 INC files and some PNG files.
ls /var/www/mrtg
should return something like this :
connections-day.png    connections-year.png  loadavg-week.png  mrtg-r.png       traffic-month.png
connections.inc        loadavg-day.png       loadavg-year.png  mrtg-ti.png      traffic-week.png
connections-month.png  loadavg.inc           mrtg-l.png        traffic-day.png  traffic-year.png
connections-week.png   loadavg-month.png     mrtg-m.png        traffic.inc

Now we also need to tell torrentflux where to look for those images, for that you should do
sudo rm -r /var/www/torrentflux/mrtg/
cd /var/www/torrentflux
ln -s /var/www/mrtg
this will create a simbolyc link so that /var/www/torrentflux/mrtg will actually be /var/www/mrtg

Now we need to make shore the poller will be called periodically to update the data, so we need to add a new cron entry. (Cron is a program that executes commnds on a timed bases).
So, for that you need to edit the Cron settings for the Apache Web user (www-data in Ubuntu), so execute this :
sudo crontab -e -u www-data
in the editor paste this information
# invoke mrtg-update every 5 mins
*/5 * * * * /usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf> /var/log/mrtg/mrtg_cron.log

In some cases the script doesn't have access to some folders, so we should give it access.
For that you'll need to do the following
sudo chown www-data:www-data /var/lock/mrtg/
sudo chown www-data:www-data /var/www/mrtg
mkdir /var/log/mrtg
sudo chown www-data:www-data /var/log/mrtg
sudo chown -R www-data:www-data /mnt/d/Torrents/.mrtg

Now, if everything went well you'll have a working MRTG, so when you press the Graph button on FluxTorrent's main page you'll end up with some nice graphics, something like :

Of course, the image shows a very small amount of traffic accounting, after all i just started MRTG, in time it will be completely filled. You just have to wait for some time to pass before the graphic will be really visible, after all, the first graphic is updated every 5 minutes, the second every 30 minutes, the next one every 2 hours and the last one once a day.

:idea: If you have images showing up, but do not get any data in the image, and you did wait at least 20-30 minutes, then there could be 2 reasons.
  1. You don't have any traffic. You should make shore you're downloding or uploading something, or you won't get any traffic, after all, your traffic is 0
  2. You didn't set the correct folder for where you're downloding to.


To check if the path has been correctly set, open up the mrtg.flux.cfg file and search for
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /mnt/d/Torrents mrtg`
, copy the text between the ' signs and execute it in a console. You should get a response like :
17408
28672
14:26,  1 user
server_name

If the first 2 rows are 0 then either you've got no connection, or the path is wrong. The path must be the path that's set in TorrentFlux, to see what's the path, go to the torrentflux page on your server, press the admin button (upper right corner - red rectangle in the picture), press the Server button (green rectangle in the piture) and look at what's set in Path (pink rectangle in the picture).
If the path set here is different than what you had in the mrtg.flux.cfg file, please copy this path and replace the path from the file.

SERVER : Install TorrentFlux

, , , ...

Now that the server is up and running, I wanted to have it do something when I'm not at home and am not using it as a Gateway.

The first things i could think of was some kind of download system, and after searching I've found Torrent Flux - 4BT. It's a web-based front-end for command-line bit-torrent clients. It is based on TorrentFlux 2.1 written by Qrome, which can be found at www.torrentflux.com.

At the time I'm writing this post the latest version is 1.0 Alpha5 (released on 2006-12-20).
So, download the file to your server, and in the folder where you've downloaded it to execute this :
tar -jxvf torrentflux-b4rt_1.0-alpha5.tar.bz2

Now lets create the folder where torrentflux will be and copy it there
sudo mkdir /var/www/torrentflux
sudo cp -r html/* /var/www/torrentflux
sudo chown -R www-data:www-data /var/www/torrentflux

The last line will make shore that www-data which is the user used by Apache (the webserver) can access the files used by TorrentFlux.

Now open a browser and direct it to this address : http://your_server_ip_address/torrentflux
You should see something similar to this :
press the Continue button.
press the Continue button again.
Select MySQL from the combobox and press the Continue button again. You should see this : press the Continue button again.
Now we need to enter the database name, username and password used for accessing MySQL.
First we need to create the database and user so open up phpMyAdmin in another browser window and log in.
Once logged in enter torrentfluxb4rt under Create New Database and press the Create button.
You should see this : .
Now we need to create the user that will be used to access the database. We could use the root user, but it's safer to use another user. So go back to the homepage of phpMyAdmin and press privileges and there press the Add new user
You should fill the data similar to this :
then press the Go button. Now you should get a window saying you've added a new user, scroll down on that page, and there's the Database-specific privileges, you'll need to modify it so that the new user can modify the torrentfluxb4rt databaseOnce you've selected torrentfluxb4rt from the list, a new window will appear where you can set the privileges that the user has over the database I'm not shore if you have to enable all accesses, but that's how i did it. Now press Go so that the changes can be applied.

Now we return to the TorrentFlux installation, you can log out from phpMyAdmin, we need to add the user and password we just created : Make shore you uncheck the Create Database since we've already created the database. You should also check the Use Persistent Connection since it will reduce the load on the server.
After you press the continue button, you should see this : After you press the continue button, you should see this :At the next step you'll see a long output similar to this : At the next step you'll see an even longer output, if you scroll down you should have
Next step :
We now need to select a folder where the torrents will be downloaded, so lets create a folder on the second harddisk. For that, in a console do this :
sudo mkdir /mnt/d/Torrents
sudo chown www-data:www-data /mnt/d/Torrents
sudo chmod 777 /mnt/d/Torrents

This will create a new folder, grant the Apache user access to it.
So now, in the TorrentFlux installation enter this as the downloads folderyou should get this response
Now, Torrentflux will look for some programs it needs, so we must make shore those are installed, so in the console run this command :
sudo apt-get install wget unrar unzip cksfv
Some of the packages might already be installed, don't worry about that.
So, now back to the TorrentFlux installation, when you press continue from the previous image, you should see this : As you can see, torrentflux didn't find VLC, we're not using it for now, so simply ignore the error and press continue.
You should see this screen :followed by
Just like the text says, after pressing the Continue button, you'll end up at the Login screen. Enter a user name and password, but make shore you remember them, or you'll be in trouble, since this user is the SuperAdmin.
After you log in, you'll get this error message Just like the text says, the problem is that your config file is writable, you'll need to change that.
In a console enter the following command :
sudo chmod 444 /var/www/torrentflux/inc/config/config.db.php

Now press the OK button and you should end up in the TorrentFlux window.

You can now search for torrents, add torrents and of course download them, so happy downloading.
P.S. I'm not going to explain how to download stuff, you should already know that:doh:

SERVER : Install PHPMyAdmin

, , , ...

In the future I want to use a few services that rely on MySQL, so I've decided to install PHPMyAdmin so that i don't have to play with the console in order to add/edit/remove mysql tables and recors.

In order to install it, here's what you have to do :
apt-get install phpmyadmin

This will install PHPMyAdmin and the required libraries. It will take some time since it must download about 8-10Mb of data.

After a few minutes it should end without a warning. If everything went well, you'll have the PHPMyAdmin installed. In order to use it, you'll have to access the following address : http://your_ip_address/phpmyadmin/

The first time you start, you should enter "root" as the username, and leave the password empty.

:idea: The root user in MySQL is not the same with the root user of the system.

After the first login, you should see something similar to this :

As you can see, PHPMyAdmin shows a warning that the administrator user has no password and as such this represents a security risk. We're going to fix this right now, so select privileges
On the new page click on the "Edit Privileges" button for the root user on your system, as shown in the picture : The new page is quite long, so scroll down to the "Change Password" area and enter a new password for the root user (make shore you remember it, since you won't be able to add/edit/remove tables without that password).
After you press the Go button, you should see somethings like this (at the top of the page):

If you have 2 root users, one is root@localhost and the other is root@your_server_name then do the above steps for root@localhost (you can do it for the other too to be on the safe side).

Now log off from PHPMyAdmin and log in again (with the password) and the red warning should be gone (which is a good thing :smile:)
So, from now on, you can add/remove/edit mysql tables, entries and users using the simple to use PHPMyAdmin interface.

:idea: Here's what the buttons do in PHPMyAdmin

SERVER : IPKungfu (Firewall configuration utility)

, , , ...

The default linux firewall installed by Ubuntu is configured using the IPTables. I've never managed to understand the exact syntax for that, so I've ended up using a 3rd party script that configures the IPTables using some very simple rules.
To install IPKungfu you must do this :
sudo aptitude install ipkungfu
If it complains about some missing libraries then try this :
sudo apt-get -f install

After IPKungfu finished installing you can modify it by modifying the files found in /etc/ipkungfu
Here are the files I've changed (with comments about what the change is for) :
the ipkungfu.conf file :
# Please read the README and FAQ for more information

# Some distros (most notably Redhat) don't have
# everything we need in $PATH so we specify it here.
# Make sure modprobe, iptables, and route are here,
# as well as ordinary items such as echo and grep.
# Default is as shown in the example below.
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin

# Your external interface
# This is the one that connects to the internet.
# Ipkungfu will detect this if you don't specify.
EXT_NET="ppp0"

# Your internal interfaces, if any.  If you have more
# than 1 internal interface, separate them with
# spaces.  If you only have one interface, put "lo"
# here. Default is auto-detected.
INT_NET="eth0"

# IP Range of your internal network.  Use "127.0.0.1"
# for a standalone machine.  Default is a reasonable
# guess.
LOCAL_NET="192.168.1.0/255.255.255.0"

# Set this to 0 for a standalone machine, or 1 for
# a gateway device to share an Internet connection.
# Default is 1.
GATEWAY=1

# TCP ports you want to allow for incoming traffic
# Don't add ports here that you intend to forward.
# This should be a list of tcp ports that have
# servers listening on them on THIS machine,
# separated by spaces. Default is none.

# 80 is for HTTP (Apache server)
# 21 is for FTP
# 22 is for SSH
# 10000 is for WebMin
ALLOWED_TCP_IN="80 21 22 10000"
#... rest of file is unchanged (and commented by default)
Of course, if you modified the webmin, FTP, HTTP or SSH to use another port you'll have to add that port instead.

If you're paranoid, you can enable certain services only from certain computers, so for example of you want WebMin to be accessible only from a computer who's IP is 123.456.789.1 you'll have to first remove WebMin's port from ALLOWED_TCP_IN and then edit the /etc/ipkungfu/accept_hosts.conf file, and add in somethings like this :
# Please see the README and FAQ for more information
#
# IP addresses of hosts or nets to always ACCEPT
# and optionally, ports they are allowed to access
# Format: host[:port:protocol]

# accept WebMin connection only from 123.456.789.1
123.456.789.1:10000:


If you need to accept an entire range of IP's, you can add this line :
123.456.789.0/255.255.255:22:tcp
this will accept connection from any IP that starts with 123.456.789, but only on port 22 and only TCP type connections.

Since i use DC++ i also had to enable some forwarding for it, si here's my vhosts.conf file :
# enable UDP and TCP connection trough 4100-4150 ports towards 192.168.1.10
# it's used by DC++
0/0:192.168.1.10:4100-4150:4100-4150:# DC++

In DC++ enter firewall (not passiv) and enter any port from the 4100 to 4150 range, it should work without a hitch (at least it does for me p:)

Now start ipkungfu by executing this :
ipkungfu

If IPKungfu complains about the shell, edit /usr/sbin/ipkungfu and change the first line to be
#!/bin/bash
now run IPKungfu, hopefully it won't give any errors.

Now just like for NO-IP, if you restart the server, the ipkungfu program won't run automatically, so we need to ad it to /etc/rc.local which is executed each time the computer boots. Just run this command :
sudo editor /etc/rc.local
and modify the file to look like this :
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# start No-Ip si that our server is accessible with myname.no_ip_domain
noip2

# Start IPKungfu (the firewall configuration utility)
ipkungfu

# don't remove the next line, or the server fill give some errors
exit 0

:idea: Whenever you edit any of IPKunfu's files, you'll have to execute IpKungfu again, since it doesn't run in the background, it only creates the IPTables Chains when it's executed and after that it exits.

SERVER : Dynamic DNS

, , , ...

If you're using a connection that gives dynamic IPs (like for example if you connect to the net over PPPoe) you'll need a way to have a static name for your server even if it has to reconnect to the net and change its IP.

There are a lot of free DNS services, I've chosen No-IP but you can use any other service (like : DynDNS, ZoneEdit).
I've chosen No-IP because a friend showed me how to use it.

For a greater list of Free Dynamic DNS providers look at :
http://www.thefreecountry.com/webmaster/freedns.shtml
or Goole Director -> Dynamic DNS Services

Anyways, back to No-IP.

First thing is you'll have to create a new account with them (it's free so don't worry about it).
Go to their site and press Sign-Up Now and enter in all the information.

Make shore you use a correct email address as that's going to be your username used to modify your settings.
After you've registered and confirmed your registration, you'll have to log into your account and add a new Host/Redirect, for that, go to Hosts/Redirects and Add, and fill in your information
In Hostname enter the name you want to use for your computer, and from the combobox choose the domain you want to use, for example if you enter myhost and select no-ip.biz your address will be http://myhost.no-ip.biz.
In the Host Type you have to select the option you want to use, generally you should use DNS Host(A), for more information about what each type is, click on the question mark, it will open a popup with the information.
You shouldn't worry too much about the IP as we're going to install the program that will auto update that IP for us.
Now press Create Host

Now we have to download the client and install it on our server. For that, go to Downloads and click on the nice penguin (for Linux) and download the file to your server (or download it somewhere else and then transfer it to the server).

Now go to the folder where you've copied or downloaded the file, and execute this :
tar -xzvf noip-duc-linux.tar.gz
you should get a nice output similar to this :
noip-2.1.3/
noip-2.1.3/binaries/
noip-2.1.3/binaries/noip2-Linux
noip-2.1.3/COPYING
noip-2.1.3/debian.noip2.sh
noip-2.1.3/gentoo.noip2.sh
noip-2.1.3/LEEME.PRIMERO
noip-2.1.3/LISEZMOI.ENPREMIER
noip-2.1.3/mac.osx.startup
noip-2.1.3/Makefile
noip-2.1.3/noip2.c
noip-2.1.3/README.FIRST
noip-2.1.3/README.FIRST-SWE
noip-2.1.3/README.FIRST.FRANCAIS
noip-2.1.3/README.FIRST.ITALIANO
noip-2.1.3/README.FIRST.JAPANESE
noip-2.1.3/README.FIRST.pt_BR
noip-2.1.3/redhat.noip.sh
noip-2.1.3/suse.noip2.sh

To copy the no-ip program, execute this :
sudo cp noip-2.1.3/binaries/noip2-Linux /usr/local/bin/noip2
, of course the folder name might be different if you're using a different version of the client. The command will copy the noip executable and name it noip2. Now we need to create the config for NoIp2. It uses a nonstandard folder for the config file (at least the folder doesn't exist by default on Ubuntu), so first we need to create that folder, so execute this :
sudo mkdir /usr/local/etc
.
Now execute
noip2 -C
and follow the onscreen instructions, for me it was like this:
Auto configuration for Linux client of no-ip.com.

Multiple network devices have been detected.

Please select the Internet interface from this list.

By typing the number associated with it.
0       eth0
1       eth1
2       ppp0
press 2 (I use PPPoe for Internet connection), then
Please enter the login/email string for no-ip.com
here you have to enter the email address you've used to register at noip, and enter the password
Please enter the password for user '**********@*******'

If you registered multiple hosts, it will ask you
2 hosts are registered to this account.
Do you wish to have them all updated?[N] (y/N)
of course you should press y to update all of them. If you registered just 1 host, it will skip this question.
Now it will ask
Do you wish to run something at successful update?[N] (y/N)
you should press n unless you really want to execute something after update.
If everything went well, you'll get this answer :
New configuration file '/usr/local/etc/no-ip2.conf' created.


Now we only need to execute
noip2
and in a few seconds our selected domains will be forwarded to our own server.

Now there's just one little catch, if you restart the server, the noip2 program won't run automatically, so we need to ad it to /etc/rc.local which is executed each time the computer boots. Just run this command :
sudo editor /etc/rc.local
and modify the file to look like this :
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# start No-Ip si that our server is accessible with myname.no_ip_domain
noip2

# don't remove the next line, or the server fill give some errors
exit 0
July 2009
S M T W T F S
June 2009August 2009
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31