树莓派-Transmission编译安装
缘起
如N多的树莓派搭建transmission的文章所说,直接apt install
就完事了,然后直接配置下就行了。
为什么还要费劲的折腾着从源码编译安装呢?
起初使用apt
安装的transmission运行非常不稳定,在运行一段时间之后,占用了数百MB的内存,这在树莓派上显然是不能接受的,经常出现运行一段时间后挂掉的情况。
此文主要记录下transmission的编译安装过程,方便以后查看。
折腾过程
1、源码下载&编译
首先安装transmission的依赖,如下
sudo apt install ca-certificates libcurl4-openssl-dev libssl-dev pkg-config build-essential checkinstall
transmission在github有仓库,因此直接从github拉取项目即可,如下:
git clone https://github.com/transmission/transmission Transmission cd Transmission git submodule update --init ./autogen.sh # 配置适合树莓派的参数 ./configure --without-gtk --disable-libnotify --disable-mac --disable-wx --disable-beos --enable-utp --enable-inotify --enable-daemon --enable-cli CPPFLAGS=-DTR_EMBEDDED # 8线程并行编译,会快一点,注意不要太多的线程,否则可能导致树莓派死机 make -j8 sudo make install
2、配置transmission
linux系统上编译安装安装的transmission配置文件的目录在$HOME/.config/transmission-daemon
目录,其文件夹结构如下:
pi@raspberrypi:~ $ sudo ls -la ~/.config/transmission-daemon/
总用量 44
drwsr-x--- 5 debian-transmission debian-transmission 4096 4月 9 2018 .
drwxr-xr-x 3 root root 4096 3月 31 2018 ..
drwxr-xr-x 2 debian-transmission debian-transmission 4096 4月 1 2018 blocklists
-rw------- 1 debian-transmission debian-transmission 778 4月 9 2018 dht.dat
drwxr-xr-x 2 debian-transmission debian-transmission 12288 4月 9 2018 resume
lrwxrwxrwx 1 root root 38 4月 9 2018 setting.json -> /etc/transmission-daemon/settings.json
-rw------- 1 debian-transmission debian-transmission 157 4月 9 2018 stats.json
drwxr-xr-x 2 debian-transmission debian-transmission 12288 4月 9 2018 torrents
我们需要设置的是setting .json
文件,比如我的配置文件如下:
{ "alt-speed-down": 15, "alt-speed-enabled": false, "alt-speed-time-begin": 540, "alt-speed-time-day": 127, "alt-speed-time-enabled": false, "alt-speed-time-end": 1020, "alt-speed-up": 15, "bind-address-ipv4": "0.0.0.0", "bind-address-ipv6": "::", "blocklist-enabled": true, "blocklist-url": "http://list.iblocklist.com/?list=ydxerpxkpcfqjaybcssw&fileformat=p2p&archiveformat=gz", "cache-size-mb": 16, "dht-enabled": true, "download-dir": "/home/pi/downloads/transmission/completed", "download-limit": 100, "download-limit-enabled": 0, "download-queue-enabled": true, "download-queue-size": 100, "encryption": 1, "idle-seeding-limit": 30, "idle-seeding-limit-enabled": true, "incomplete-dir": "/home/pi/downloads/transmission/downloading", "incomplete-dir-enabled": true, "lpd-enabled": true, "max-peers-global": 2500, "message-level": 3, "open-file-limit": 18000, "peer-congestion-algorithm": "", "peer-id-ttl-hours": 6, "peer-limit-global": 12800, "peer-limit-per-torrent": 4900, "peer-port": 65083, "peer-port-random-high": 65535, "peer-port-random-low": 49152, "peer-port-random-on-start": false, "peer-socket-tos": "default", "pex-enabled": true, "port-forwarding-enabled": true, "preallocation": 1, "prefetch-enabled": true, "queue-stalled-enabled": false, "queue-stalled-minutes": 30, "ratio-limit": 2, "ratio-limit-enabled": true, "rename-partial-files": true, "rpc-authentication-required": true, "rpc-bind-address": "0.0.0.0", "rpc-enabled": true, "rpc-host-whitelist": "", "rpc-host-whitelist-enabled": true, "rpc-password": "你的密码", "rpc-port": 9091, "rpc-url": "/transmission/", "rpc-username": "你的用户名", "rpc-whitelist": "127.0.0.1", "rpc-whitelist-enabled": false, "scrape-paused-torrents-enabled": true, "script-torrent-done-enabled": false, "script-torrent-done-filename": "", "seed-queue-enabled": false, "seed-queue-size": 50, "speed-limit-down": 100, "speed-limit-down-enabled": false, "speed-limit-up": 200, "speed-limit-up-enabled": true, "start-added-torrents": true, "trash-original-torrent-files": true, "umask": 0, "upload-limit": 100, "upload-limit-enabled": 0, "upload-slots-per-torrent": 14, "utp-enabled": true }
如上设置了下载队列大小,是否启用dht、rpc网页登录用户名、密码等参数,我的设置是9091端口为rpc的端口,以后我们可以通过http://[树莓派ip]:9091/transmission/来进行web界面下载管理。
3、开机自启动
通过上面的设置,可以通过transmission-daemon进行启动操作,但是作为一个下载服务器来说,是需要开机自启,一直服务的,因此我们需要将transmission作为开机自启动项目。
3.1 通过service自启
比较常用的方法,即为采用linux系统服务进行自启,同时,可以对这个服务做start
,stop
,restart
等操作,用起来比较方便。
1、编辑 /etc/init.d/transmission-daemon,输入以下内容:
#! /bin/sh ### BEGIN INIT INFO # Provides: transmission-daemon # Required-Start: networking # Required-Stop: networking # Default-Start: 2 3 5 # Default-Stop: 0 1 6 # Short-Description: Start the transmission BitTorrent daemon client. ### END INIT INFO # Original Author: Lennart A. J脙艗tte, based on Rob Howell's script # Modified by Maarten Van Coile & others (on IRC) # Do NOT "set -e" # # ----- CONFIGURATION ----- # # For the default location Transmission uses, visit: # http://trac.transmissionbt.com/wiki/ConfigFiles # For a guide on how set the preferences, visit: # http://trac.transmissionbt.com/wiki/EditConfigFiles # For the available environement variables, visit: # http://trac.transmissionbt.com/wiki/EnvironmentVariables # # The name of the user that should run Transmission. # It's RECOMENDED to run Transmission in it's own user, # by default, this is set to 'transmission'. # For the sake of security you shouldn't set a password # on this user USERNAME=root # ----- *ADVANCED* CONFIGURATION ----- # Only change these options if you know what you are doing! # # The folder where Transmission stores the config & web files. # ONLY change this you have it at a non-default location TRANSMISSION_HOME="/etc/transmission-daemon" TRANSMISSION_WEB_HOME="/usr/local/share/transmission/web" # # The arguments passed on to transmission-daemon. # ONLY change this you need to, otherwise use the # settings file as per above. TRANSMISSION_ARGS="--logfile /var/log/transmission.log" # ----- END OF CONFIGURATION ----- # # PATH should only include /usr/* if it runs after the mountnfs.sh script. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DESC="bittorrent client" NAME=transmission-daemon DAEMON=$(which $NAME) PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # 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 [ -f /etc/default/rcS ] && . /etc/default/rcS # # Function that starts the daemon/service # do_start() { # Export the configuration/web directory, if set if [ -n "$TRANSMISSION_HOME" ]; then export TRANSMISSION_HOME fi if [ -n "$TRANSMISSION_WEB_HOME" ]; then export TRANSMISSION_WEB_HOME fi # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \ --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \ || return 1 start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \ --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \ || return 2 } # # 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/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON 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" } case "$1" in start) echo "Starting $DESC" "$NAME..." do_start case "$?" in 0|1) echo " Starting $DESC $NAME succeeded" ;; *) echo " Starting $DESC $NAME failed" ;; esac ;; stop) echo "Stopping $DESC $NAME..." do_stop case "$?" in 0|1) echo " Stopping $DESC $NAME succeeded" ;; *) echo " Stopping $DESC $NAME failed" ;; esac ;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # echo "Restarting $DESC $NAME..." do_stop case "$?" in 0|1) do_start case "$?" in 0|1) echo " Restarting $DESC $NAME succeeded" ;; *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;; esac ;; *) echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 3 ;; esac
2、添加transmission-daemon
的可执行权限
3、通过sudo update-rc.d transmission-daemon defaults
设置开机自启动
3.2 通过crontab自启
第二种简单的自启动的方法是使用crontab的@reboot
命令,在每次启动后开启transmission。
1、crontab -e 开启命令编辑 2、输入回车进入编辑模式 3、输入 @reboot sleep 10 && transmission-daemon -g ~/.config/transmission-daemon/setting.json 4、按esc,然后shift + :,wq保存退出
这种方法呢,不是很系统,不是作为linux系统下的服务运行的,不是特别推荐,如果嫌系统服务设置麻烦的可以采用。
总结
至此,transmission的编译安装以及配置已经ok啦,树莓派可以作为一个长期稳定运行的transmission下载服务器了。
经过测试,运行时比较稳定的~ 当然了,在国内网络环境下,各种资源的速度真的是非常非常的慢了,这是网络环境导致的,下载工具是没问题的
参考文档
https://github.com/transmission/transmission/wiki/Configuration-Files
发表评论