segunda-feira, 13 de julho de 2009

Instalando o wTorrent/Apache no CentOS 5.3

Depois de ler muita documentação e exemplos de configurações, eis que consegui instalar o danado no CentOS 5.3 sem problemas!
Estou utilizando um módulo do Apache para a conexão com o rTorrent, o SCGI, ele que irá fazer a comunicação em XML com o XMLRPC-C e o rTorrent.
A instalação que realizei pode ser feita em um servidor dedicado ao wTorrent, modificando-se algumas configurações.
Vamos ao trabalho:


0) Instalação dos pacotes

yum -y groupinstall "Ferramentas de desenvolvimento"
yum -y install dtach samba mod_scgi curl-devel libsigc++20-devel ncurses-devel libxml2-devel


1) Instalação do xmlrpc-c

cd /usr/src/
svn checkout https://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced xmlrpc-c
cd xmlrpc-c
./configure --disable-wininet-client --disable-libwww-client --enable-libxml2-backend --disable-tools --disable-abyss-threads --enable-cgi-server --disable-abyss-server --disable-cplusplus --enable-curl-client
make
make install
cd ..


2) Instalação do libtorrent/rtorrent

mkdir rtorrent-svn
cd rtorrent-svn
svn co svn://rakshasa.no/libtorrent/trunk
cd trunk
cd libtorrent
./autogen.sh
./configure --disable-debug --enable-ipv6 --enable-aligned --enable-static --enable-shared --disable-dependency-tracking
make
make install
cd ../rtorrent
./autogen.sh
PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" ./configure --disable-debug --enable-ipv6 --with-xmlrpc-c --disable-dependency-tracking
make
make install
cd ../..


3) Instalação do wtorrent

mkdir wtorrent-svn
cd wtorrent-svn
svn co svn://wtorrent-project.org/repos/trunk/wtorrent/
cp -R wtorrent /var/www/html
touch /var/www/html/wtorrent/db/database.db
chown -R apache:apache /var/www/html/wtorrent

---------- arquivo de configuração do wtorrent ----------

vim sample.user.conf.php
< ?php
/*
This file is part of wTorrent.

wTorrent is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

wTorrent is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see .

Modified version of class done by David Marco Martinez
*/

// Default language for the app
define( 'LANGUAGE', 'en');

// SQLite database file (set folder permision 0777 or chmod to httpd server) (wTorrent will create database when running install.php)
define( 'DB_FILE', 'db/database.db');

// Host or IP to connect to rTorrent (lighttpd or apache host and port)
define( 'RT_HOST', 'localhost');
define( 'RT_PORT', 80);
// This is the scgi.server folder set in lighttpd or apache conf
define( 'RT_DIR', 'RPC2/');
// Set this to false if you don't have any autentification method to access http:///
// This is NOT the user to access wtorrent, your user will be set up after editing this file
define( 'RT_AUTH', true);
define( 'RT_USER', 'myrpcuser');
define( 'RT_PASSWD', 'senha');
// where to use multicall or not
// if wTorrent makes your rtorrent crash, set this to true
define( 'NO_MULTICALL', true);
// Use scriptaculous effects (IMPORTANT: notice the '' arround true or false)
define( 'EFFECTS', 'true');

// Directory in which to save uploaded .torrent files (set folder permision 0777 or chmod to httpd server)
// This reffers to the wtorrent folder, don't use exact paths like /data/watch (see Ticket #104)
define( 'DIR_TORRENTS', 'torrents/');

// Full path to application directory (where index.php is)
define ('DIR_EXEC', '/var/www/html/wtorrent/');

// Default location to save downloaded files (can be set for every uploaded .torrent on the ui)
define ('DIR_DOWNLOAD', '/home/wtorrent/torrents/doing');

?>
:wq


4) Configurar o daemon do rtorrent

useradd wtorrent
passwd wtorrent (cadastre uma senha)

cd /home/wtorrent
mkdir ./torrents
mkdir ./torrents/watch
mkdir ./torrents/doing
mkdir ./torrents/done
mkdir ./.rtsession
chmod -R 777 ./torrents


---------- arquivo de configuração do rtorrent ----------

vim .rtorrent.rc
# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 5

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 45

# Default directory to save the downloaded torrents.
directory = ~/torrents/doing

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = ~/.rtorrent

# Watch for new torrents
schedule = watch_directory,5,5,load_start=~/torrents/watch/*.torrent
schedule = tied_directory,5,5,start_tied=
schedule = untied_directory,5,5,close_untied=

on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,~/torrents/done/ ;d.set_directory=~/torrents/done/"
on_start = link1,"create_link=tied,,.started"
on_stop = link1,"delete_link=tied,,.started"
on_finished = link1,"create_link=tied,,.finished"
on_erase = link1,"delete_link=tied,,.finished"

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# Port range to use for listening.
port_range = 46881-48889

# Start opening ports at a random position within the port range.
port_random = yes

# Set whetever the client should try to connect to UDP trackers.
use_udp_trackers = yes

encryption = allow_incoming,enable_retry,try_outgoing

dht = auto
dht_port = 46881

# Listen for XMLRPC connections
scgi_port = 127.0.0.1:5000

# set UTF8 encoding
encoding_list = UTF-8
:wq

---------- arquivo de configuração do daemon do rtorrent ----------

vim /etc/sysconfig/rtorrentd
USER="wtorrent"
SOCKET="/tmp/rtorrent.dtach"
OPTIONS=""
:wq

---------- arquivo do daemon do rtorrent ----------

vim /etc/init.d/rtorrentd
#!/bin/sh
#
# Authors: Sergio Augusto Vladisauskis
#
# chkconfig: - 64 36
# description: Starts and stops the rTorrent backend daemon.
# processname: rtorrent
# pidfile: /var/run/rtorrentd.pid

# so we can rearrange this easily
description="rTorrent backend daemon"
processname="rtorrent"
servicename="rtorrentd"

RETVAL=0
PATH=/usr/local/bin:$PATH

# Sanity checks.
[ -x /usr/local/bin/$processname ] || exit 5

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
[ -r /etc/sysconfig/$servicename ] && . /etc/sysconfig/$servicename

start() {
echo -n $"Starting $description: "
if [ -z $USER ]; then
daemon --check $servicename /usr/bin/dtach -n $SOCKET /usr/local/bin/$processname $OPTIONS
else
daemon --check $servicename --user=$USER /usr/bin/dtach -n $SOCKET /usr/local/bin/$processname $OPTIONS
fi
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/$servicename
echo `pidof -o %PPID /usr/local/bin/$processname` > /var/run/$servicename.pid
fi
}

stop() {
echo -n $"Stopping $description: "
killproc $servicename -TERM
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/$servicename
rm -f /var/run/$servicename.pid
fi
}

reload() {
echo -n $"Reloading $description: "
killproc $servicename -HUP
RETVAL=$?
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $processname
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$servicename ]; then
stop
start
fi
;;
reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
;;
esac

exit $RETVAL
:wq


chkconfig --add rtorrentd
chkconfig 345 rtorrentd on

service rtorrentd start


5) Configurar o daemon do rtorrent

htpasswd -c /var/www/.htpasswd myrpcuser (cadastre a mesma senha que foi configurada no user.conf.php)

---------- arquivo de configuração do SCGI do Apache ----------

vim /etc/httpd/conf.d/scgi.conf
# (This actually better set up permanently with the command line
# "a2enmod scgi" but shown here for completeness)
LoadModule scgi_module modules/mod_scgi.so

# Set up a location to be served by an SCGI server process

# uncomment next line to serve SCGI process under /dynamic/
# SCGIMount /dynamic/ 127.0.0.1:4000

# Set up a location to be served by an SCGI server process
SCGIMount /RPC2 127.0.0.1:5000


AuthName "Private"
AuthType Basic
AuthBasicProvider file
AuthUserFile /var/www/.htpasswd
Require user myrpcuser

:wq

service httpd restart


6) Configurando o SAMBA/NFS

---------- arquivo de configuração do NFS ----------

vim /etc/exports
/home/wtorrent/torrents/done 10.0.0.0/24(rw,async,subtree_check,all_squash)
:wq

---------- arquivo de configuração do SAMBA ----------

vim /etc/samba/smb.conf
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the
# Samba-Guide which is generated daily and can be downloaded from:
# http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors.
#
#---------------
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# "samba-share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/...) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
#
#--------------
#
#======================= Global Settings =====================================

[global]

# ----------------------- Network Related Options -------------------------
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname
#
# Interfaces lets you configure Samba to use multiple interfaces
# If you have multiple network interfaces then you can list the ones
# you want to listen on (never omit localhost)
#
# Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
# specifiy it as a per share option as well
#
workgroup = WORKGROUP
server string = Samba Server Version %v

; netbios name = MYSERVER

; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
; hosts allow = 127. 192.168.12. 192.168.13.

# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.
#
# Max Log Size let you specify the max size log files should reach

# logs split per machine
; log file = /var/log/samba/%m.log
# max 50KB per log file, then rotate
; max log size = 50

# ----------------------- Standalone Server Options ------------------------
#
# Security can be set to user, share(deprecated) or server(deprecated)
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.

security = user
passdb backend = tdbsam


# ----------------------- Domain Members Options ------------------------
#
# Security must be set to domain or ads
#
# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Use password server option only with security = server or if you can't
# use the DNS to locate Domain Controllers
# The argument list may include:
# password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
# password server = *


; security = domain
; passdb backend = tdbsam
; realm = MY_REALM

; password server =

# ----------------------- Domain Controller Options ------------------------
#
# Security must be set to user for domain controllers
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
#
# Domain Logons let Samba be a domain logon server for Windows workstations.
#
# Logon Scrpit let yuou specify a script to be run at login time on the client
# You need to provide it in a share called NETLOGON
#
# Logon Path let you specify where user profiles are stored (UNC path)
#
# Various scripts can be used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
#
; security = user
; passdb backend = tdbsam

; domain master = yes
; domain logons = yes

# the login script name depends on the machine name
; logon script = %m.bat
# the login script name depends on the unix user used
; logon script = %u.bat
; logon path = \\%L\Profiles\%u
# disables profiles support by specifing an empty path
; logon path =

; add user script = /usr/sbin/useradd "%u" -n -g users
; add group script = /usr/sbin/groupadd "%g"
; add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u"
; delete user script = /usr/sbin/userdel "%u"
; delete user from group script = /usr/sbin/userdel "%u" "%g"
; delete group script = /usr/sbin/groupdel "%g"


# ----------------------- Browser Control Options ----------------------------
#
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
#
# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
#
# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
; local master = no
; os level = 33
; preferred master = yes

#----------------------------- Name Resolution -------------------------------
# Windows Internet Name Serving Support Section:
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
#
# - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server
#
# - WINS Server: Tells the NMBD components of Samba to be a WINS Client
#
# - WINS Proxy: Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
#
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups.

; wins support = yes
; wins server = w.x.y.z
; wins proxy = yes

; dns proxy = yes

# --------------------------- Printing Options -----------------------------
#
# Load Printers let you load automatically the list of printers rather
# than setting them up individually
#
# Cups Options let you pass the cups libs custom options, setting it to raw
# for example will let you use drivers on your Windows clients
#
# Printcap Name let you specify an alternative printcap file
#
# You can choose a non default printing system using the Printing option

load printers = no
cups options = raw

; printcap name = /etc/printcap
#obtain list of printers automatically on SystemV
; printcap name = lpstat
; printing = cups

# --------------------------- Filesystem Options ---------------------------
#
# The following options can be uncommented if the filesystem supports
# Extended Attributes and they are enabled (usually by the mount option
# user_xattr). Thess options will let the admin store the DOS attributes
# in an EA and make samba not mess with the permission bits.
#
# Note: these options can also be set just per share, setting them in global
# makes them the default for all shares

; map archive = no
; map hidden = no
; map read only = no
; map system = no
; store dos attributes = yes


#============================ Share Definitions ==============================

[homes]
comment = Home Directories
browseable = no
writable = yes
; valid users = %S
; valid users = MYDOMAIN\%S

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

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /var/lib/samba/netlogon
; guest ok = yes
; writable = no
; share modes = no


# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
; [Profiles]
; path = /var/lib/samba/profiles
; browseable = no
; guest ok = yes


# A publicly accessible directory, but read only, except for people in
# the "staff" group
; [public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = +staff

[Arquivos]
comment = Arquivos Baixados
path = /home/wtorrent/torrents/done
public = yes
writable = yes
printable = no
; write list = +staff
:wq

smbpasswd -a wtorrent (mesma senha do usuário wtorrent)
service samba start
service nfs start


7) Finalização

Acessar o endereço http://ip_do_servidor/wtorrent/install.php para configurar o wtorrent (a maioria das configurações já foram feitas), criar um usuário de administração e sua senha.
Acessar o endereço http://ip_do_servidor/wtorrent e desfrutar desse grande serviço!
Qualquer dúvida ou erro, mande um email.
Boa sorte! :D


8) Referencias:

http://www.wtorrent-project.org/trac/wiki
http://code.google.com/p/ntorrent

Nenhum comentário: