linux版uTorrent安装手记
本帖最后由 taxigps 于 2011-1-16 21:58 编辑
原动力的PT资源需要用uTorrent来下载,而原来uTorrent只有windows版本。我的NAS下载机安装的是linux系统,没有相应版本 的uTorrent可以使用,让人比较纠结。网上也有介绍使用wine在linux下运行windows版的uTorrent,总之不是太爽。原生的 linux版uTorrent终于在2010年9月发布,到现在3个多月过去了,虽然还是Alpha版而非正式版,应该也比较成熟了,因此决定尝试安装使 用。
一、安装环境
先说说我的NAS机器,这个东东的DIY过程已经在本版发帖做过介绍。主要是用ATOM330CPU的离子主板配的下载机。操作系统是ubuntu9.10server版,装了mldonkey下载资源,装了XBMC来播放。
二、uTorrent安装
到uTorrent的主页下载最新的linux版压缩包:http://www.utorrent.com/downloads/linux
我下载回来的uTorrent Server alpha (3.0 build 23418)文件是utorrent-server-3.0-23418.tar.gz
在linux系统中解压:
tar zxvf utorrent-server-3.0-23418.tar.gz
解压出一个目录utorrent-server-v3_0可以看到目录结构:
utorrent-server-v3_0 —+— docs (文档资料目录)
+— utserver(主程序)
+— webui.zip(web界面系统)
这个东西说起来也简单,直接运行utserver就行,当然,运行前还得创建一个配置文件utserver.conf,最好还是编写一个脚本来方便地启动和停止utserver服务。uTorrent的linux版还不是正式版本,安装工作自己还得多动点手。
(一)初级班
对于入门级用户,首先能用起来可能就满足了。适合这个简单的初级班教程。
1. 用wget命令下载安装包
wget http://download.utorrent.com/linux/utorrent-server-3.0-23418.tar.gz
(注意:具体安装包文件名可能会变化)
2. 用ls命令看看是否成功下载
ls
3. 如果下载成功,就用tar命令解压安装包
tar zxvf utorrent-server-3.0-23418.tar.gz
(如前所述,压缩包文件名也许与我这个不同)
4. 进入解压出来的目录
ls
cd utorrent-server-v3_0
5. 运行uTorrent Server的主程序
./utserver
6. 在浏览器中连接uTorrent Server的web控制页面,默认登录用户admin,密码为空
http://localhost:8080/gui/
(这里是从本机访问,当然也可以从其它电脑访问,把localhost改成uTorrent Server所在电脑IP就可)
复制代码
初级班课程到此结束。
(二)高级班
作为高级班的同学,咱们当然得仔细研究下布局了。我考虑照通常软件安装的目录来办,执行主程序放到/usr/bin目录,配置文件、运行记录log文件等都放到/var/lib/utorrent目录,主要文件分布如下:
/usr/bin/utserver(主程序)
/etc/init.d/utserver(启动脚本)
/var/lib/utorrent/utserver.conf(配置文件)
/var/lib/utorrent/utserver.log(运行记录)
/var/lib/utorrent/webui.zip(web界面文件)
复制代码
而且为了方便自己管理下载回来的资源,决定让utserver进程以我的个人用户权限运行,对我来说就是用户为taxigps,组也为taxigps。当然你也可以专门为运行utorrent创建一个用户。创建用户的问题在这里就不细表了。
1. 咱们先创建utserver的工作目录
sudo mkdir /var/lib/utorrent
sudo chown taxigps /var/lib/utorrent
sudo chgrp taxigps /var/lib/utorrent
sudo mkdir /var/run/utserver
sudo chown taxigps /var/run/utserver
sudo chgrp taxigps /var/run/utserver
(这里的用户名和组名可别抄我的)
2. 把相关文件拷贝到指定目录
sudo cp utserver /usr/bin
cp webui.zip /var/lib/utorrent
复制代码
下面一项重要工作就是创建启动脚本了,用这个命令:
sudo nano /etc/init.d/utserver
复制代码
脚本内容如下:
#! /bin/sh
### BEGIN INIT INFO
# Provides: utserver
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the utserver.
# Description: uTorrent Server for Linux. A headless
# bittorrent client with a WebUI.
### END INIT INFO
# Author: John Doe <[email protected]>
#
# Please remove the “Author” lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT “set -e”
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=”uTorrent Server for Linux”
CHDIR=/usr/bin
NAME=utserver
UT_CONFIG=/var/lib/utorrent/$NAME.conf
UT_SETTINGS=/var/lib/utorrent/
UT_LOG=/var/lib/utorrent/$NAME.log
#DAEMON_ARGS=”-daemon -configfile ${UT_CONFIG} -settingspath ${UT_SETTINGS} -logfile ${UT_LOG}”
DAEMON_ARGS=”-configfile ${UT_CONFIG} -settingspath ${UT_SETTINGS} -logfile ${UT_LOG}”
DAEMON=$CHDIR/$NAME
USER=taxigps
GROUP=taxigps
PIDFILE=/var/run/$NAME/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
STOP_TIMEOUT=5
INIT_VERBOSE=yes
# Exit if the package is not installed
[ -x “$DAEMON” ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon –start –quiet –make-pidfile –pidfile $PIDFILE –chuid $USER:$GROUP –chdir $CHDIR –background –exec $DAEMON –test > /dev/null
|| return 1
start-stop-daemon –start –quiet –make-pidfile –pidfile $PIDFILE –chuid $USER:$GROUP –chdir $CHDIR –background –exec $DAEMON —
$DAEMON_ARGS
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon –stop –quiet –retry=TERM/30/KILL/5 –pidfile $PIDFILE –name $NAME
RETVAL=”$?”
[ “$RETVAL” = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon –stop –quiet –oknodo –retry=0/30/KILL/5 –exec $DAEMON
[ “$?” = 2 ] && return 2
# Many daemons don’t delete their pidfiles when they exit.
rm -f $PIDFILE
return “$RETVAL”
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon –stop –signal 1 –quiet –pidfile $PIDFILE –name $NAME
return 0
}
case “$1” in
start)
[ “$VERBOSE” != no ] && log_daemon_msg “Starting $DESC” “$NAME”
do_start
case “$?” in
0|1) [ “$VERBOSE” != no ] && log_end_msg 0 ;;
2) [ “$VERBOSE” != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ “$VERBOSE” != no ] && log_daemon_msg “Stopping $DESC” “$NAME”
do_stop
case “$?” in
0|1) [ “$VERBOSE” != no ] && log_end_msg 0 ;;
2) [ “$VERBOSE” != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc “$DAEMON” “$NAME” && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave ‘force-reload’ as an alias for ‘restart’.
#
#log_daemon_msg “Reloading $DESC” “$NAME”
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the “reload” option is implemented then remove the
# ‘force-reload’ alias
#
log_daemon_msg “Restarting $DESC” “$NAME”
do_stop
case “$?” in
0|1)
do_start
case “$?” in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo “Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}” >&2
echo “Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}” >&2
exit 3
;;
esac
:
复制代码
脚本中这几行代码请根据你自己的情况修改:
CHDIR=/usr/bin
UT_CONFIG=/var/lib/utorrent/$NAME.conf
UT_SETTINGS=/var/lib/utorrent/
UT_LOG=/var/lib/utorrent/$NAME.log
USER=taxigps
GROUP=taxigps
PIDFILE=/var/run/$NAME/$NAME.pid
复制代码
启动脚本创建完成后还要设置成可执行代码:
sudo chmod a+x /etc/init.d/utserver
复制代码
现在你可以用脚本命令来启动和停止utorrent服务了:
/etc/init.d/utserver start(启动utorrent)
/etc/init.d/utserver stop(停止utorrent)
复制代码
现在用起来更方便了吧。
(三)尖子班
尖子班的同学还有更高的追求,比如我就想把720P的电影和1080P的电影下载存放到不同的目录。让我们先建两个目录吧:
mkdir /mnt/data/utorrent
mkdir /mnt/data/share/电影/720P
mkdir /mnt/data/share/电影/1080P
复制代码
注 意,你得保证这些目录utorrent服务程序有访问的权限,由于我的utorrent服务程序以taxigps用户权限运行,我这两个目录也以 taxigps用户的身份创建。这里/mnt/data/utorrent目录准备作为utorrent的工作目录,存放下载过程中的临时文件,下载完成 后再移动到完成目录,要保证临时目录和完成目录在同一硬盘,避免大量的文件拷贝。
下一个重要步骤就是编辑utorrent的配置文件了,还是用nano命令:
nano /var/lib/utorrent/utserver.conf
复制代码
参考配置文件内容如下:
# web界面端口号
ut_webui_port:8080
# token认证
token_auth_enable:1
# 保存正在下载项目的临时文件目录
dir_active:/mnt/data/utorrent
# 保存完成下载项目的默认目录
dir_completed:/mnt/data/share/电影/720P
# 保存完成下载项目的可选目录(可以是多个)
dir_download:/mnt/data/share/电影/720P
dir_download:/mnt/data/share/电影/1080P
# web界面登录用户名
admin_name:admin
# web界面登录密码
admin_password:test
复制代码
最后,要在web界面使用分目录存放下载文件功能,你需要下载最新的webui界面系统。到此下载:http://forum.utorrent.com/viewtopic.php?id=58156
要发表评论,您必须先登录。