synology开启nfs和Ubuntu安装aira2及开机启动配置

2020年07月25日 15点热度 0人点赞 0条评论
文章导航
[隐藏]

起因:最近群晖docker下的aria2经常死机没速度各种状况频发!
过程:千万别在pve下用lxc挂载,搞死人呀!一定要用kvm,kvm,kvm......
结果:个人觉得完美解决!
使用环境:nas/服务器等等一切,你脑洞打开吧!

群晖开启nfs支持

开启方式:控制面板--->共享文件夹--->你的文件夹名称--->编辑

设置权限,如图:

设置nfs,如图:

安装NFS客户端

修改ubuntu更新源

mv /etc/apt/sources.list /etc/apt/sourses.list.backup

新建/etc/apt/sources.list文件并添加以下内容

vim /etc/apt/sources.list

选取下面其中一段,这里Sandy使用aliyun的源,毕竟人家的云都在用!

#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

修改好了就保存

apt update
apt upgrade

安装nfs

apt install nfs-common

测试nfs是否通

showmount -e 192.168.1.178

挂载nfs

mkdir Downloads
chmod -R 0777 Downloads
mount -t nfs 192.168.1.178:/volume2/video/baidu /root/Downloads -o proto=tcp -o nolock

设置开机挂载

vim /etc/fstab

#内容如下
192.168.1.178:/volume2/video/baidu    /root/Downloads   nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

安装aria2

sudo apt-get install aria2

aria2配置

创建下载目录

sudo mkdir /root/data
sudo chmod 777 /root/data

创建配置文件

mkdir /etc/aria2
touch /etc/aria2/aria2.session
chmod 777 /etc/aria2/aria2.session
vi /etc/aria2/aria2.conf

aria2.conf文件内容

#临时存放目录
dir=/root/data
#移动到nfs目录
on-download-complete=/etc/aria2/mvgg.sh
input-file=/etc/aria2/aria2.session
save-session=/etc/aria2/aria2.session
save-session-interval=60

file-allocation=falloc
log-level=warn
enable-http-pipelining=true

max-concurrent-downloads=3
max-connection-per-server=10
min-split-size=10M
split=10
continue=true
max-overall-download-limit=0
max-overall-upload-limit=1K

enable-rpc=true
rpc-listen-all=true
rpc-allow-origin-all=true
rpc-listen-port=6800

listen-port=51413
# 单个种子最大连接数, 默认:55
#bt-max-peers=55
# 打开DHT功能, PT需要禁用, 默认:true
enable-dht=true
# 打开IPv6 DHT功能, PT需要禁用
#enable-dht6=false
# DHT网络监听端口, 默认:6881-6999
dht-listen-port=51413
# 本地节点查找, PT需要禁用, 默认:false
bt-enable-lpd=true
# 种子交换, PT需要禁用, 默认:true
enable-peer-exchange=true
# 每个种子限速, 对少种的PT很有用, 默认:50K
#bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0
seed-ratio=1.0
#最小做种时间
#此选项设置为 0 时, 将在 BT 任务下载完成后不进行做种.
seed-time=0
# 强制保存会话, 即使任务已经完成, 默认:false
# 较新的版本开启后会在任务完成后依然保留.aria2文件
#force-save=false
# BT校验相关, 默认:true
#bt-hash-check-seed=true
# 继续之前的BT任务时, 无需再次校验, 默认:false
bt-seed-unverified=true

# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false
bt-save-metadata=true
bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.opentrackr.org:1337/announce,udp://tracker.openbittorrent.com:80/announce,http://tracker.opentrackr.org:1337/announce,udp://tracker.internetwarriors.net:1337/announce,udp://tracker.leechers-paradise.org:6969/announce,udp://p4p.arenabg.com:1337/announce,udp://9.rarbg.to:2710/announce,udp://9.rarbg.me:2710/announce,udp://exodus.desync.com:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://retracker.lanta-net.ru:2710/announce,udp://open.stealth.si:80/announce,udp://tracker.tiny-vps.com:6969/announce,udp://tracker3.itzmx.com:6961/announce,udp://tracker.torrent.eu.org:451/announce,http://tracker3.itzmx.com:6961/announce,http://tracker1.itzmx.com:8080/announce,udp://tracker.moeking.me:6969/announce,udp://bt2.archive.org:6969/announce,udp://bt1.archive.org:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,http://tracker.nyap2p.com:8080/announce,udp://valakas.rollo.dnsabr.com:2710/announce,udp://tracker.uw0.xyz:6969/announce,udp://retracker.akado-ural.ru:80/announce,udp://opentor.org:2710/announce,udp://explodie.org:6969/announce,http://h4.trakx.nibba.trade:80/announce,http://explodie.org:6969/announce,udp://zephir.monocul.us:6969/announce,udp://www.loushao.net:8080/announce,udp://u.wwwww.wtf:1/announce,udp://tracker.zerobytes.xyz:1337/announce,udp://tracker.yoshi210.com:6969/announce,udp://tracker.skynetcloud.site:6969/announce,udp://tracker.lelux.fi:6969/announce,udp://tracker.jae.moe:6969/announce,udp://tracker.filemail.com:6969/announce,udp://tracker.ds.is:6969/announce,udp://tracker.dler.org:6969/announce,udp://tracker.army:6969/announce,udp://tracker-udp.gbitt.info:80/announce,udp://tr2.ysagin.top:2710/announce,udp://t3.leech.ie:1337/announce,udp://t2.leech.ie:1337/announce,udp://t1.leech.ie:1337/announce,udp://retracker.netbynet.ru:2710/announce,udp://qg.lorzl.gq:2710/announce,udp://opentracker.i2p.rocks:6969/announce,udp://chihaya.de:6969/announce,udp://aaa.army:8866/announce,https://w.wwwww.wtf:443/announce,https://tracker.tamersunion.org:443/announce,https://tracker.sloppyta.co:443/announce,https://tracker.nitrix.me:443/announce,https://tracker.nanoha.org:443/announce,https://tracker.lelux.fi:443/announce,https://tracker.jae.moe:443/announce,https://tracker.gbitt.info:443/announce,https://aaa.army:8866/announce,https://1337.abcvg.info:443/announce,http://www.loushao.net:8080/announce,http://vps02.net.orel.ru:80/announce,http://trun.tom.ru:80/announce,http://tracker.zerobytes.xyz:1337/announce,http://tracker.yoshi210.com:6969/announce,http://tracker.ygsub.com:6969/announce,http://tracker.sloppyta.co:80/announce,http://tracker.lelux.fi:80/announce,http://tracker.gbitt.info:80/announce,http://tracker.dler.org:6969/announce,http://tracker.bt4g.com:2095/announce,http://t.overflow.biz:6969/announce,http://t.nyaatracker.com:80/announce,http://retracker.sevstar.net:2710/announce,http://pow7.com:80/announce,http://opentracker.i2p.rocks:6969/announce,http://open.acgtracker.com:1096/announce,http://open.acgnxtracker.com:80/announce,http://aaa.army:8866/announce,udp://tracker6.dler.org:2710/announce,udp://tracker4.itzmx.com:2710/announce,udp://tracker2.itzmx.com:6961/announce,udp://tracker.zum.bi:6969/announce,udp://tracker.teambelgium.net:6969/announce,udp://tr.bangumi.moe:6969/announce,udp://bt2.54new.com:8080/announce,https://tracker.vectahosting.eu:2053/announce,https://tracker.imgoingto.icu:443/announce,https://tracker.hama3.net:443/announce,http://tracker4.itzmx.com:2710/announce,http://tracker2.itzmx.com:6961/announce,http://tracker2.dler.org:80/announce,http://tracker.zum.bi:6969/announce,http://t.acg.rip:6699/announce

创建mvgg.sh文件

vi /etc/aria2/mvgg.sh
#内容如下

#!/bin/bash
path="$3" #取原始路径,我的环境下如果是单文件则为/data/demo.png,如果是文件夹则该值为文件夹内某个文件比如/data/a/b/c/d.jpg
downloadpath='/root/data' #下载目录
mv='/root/Downloads'   #mv挂载的目录

if [ $2 -eq 0 ] #下载文件为0跳出脚本
        then
                exit 0
fi

while true; do  #提取下载文件根路径,如把/data/a/b/c/d.jpg变成/data/a
    filepath=$path
    path=${path%/*}; 
    if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ]
        then
        mv=${filepath/#$downloadpath/$mv} #替换路径
        mv -f "${filepath}" "${mv}"
        exit 0
    elif [ "$path" = "$downloadpath" ]   #文件夹
        then
        mv -f "${filepath}" "${mv}"/
        rm -rf  "${filepath}"
        exit 0
    fi
done

测试aria2安装是否成功

sudo aria2c --conf-path=/etc/aria2/aria2.conf

没有错误提示即为成功,ctrl+c可停止运行;

服务模式开机启动

增加开机启动脚本

sudo vi /etc/init.d/aria2c

添加如下内容:

#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Aria2 Downloader
### END INIT INFO

case "$1" in
start)

 echo -n "已开启Aria2c"
 sudo aria2c --conf-path=/etc/aria2/aria2.conf -D
;;
stop)

 echo -n "已关闭Aria2c"
 killall aria2c
;;
restart)

 killall aria2c
 sudo aria2c --conf-path=/etc/aria2/aria2.conf -D
;;
esac
exit

修改文件权限为755

sudo chmod 755 /etc/init.d/aria2c

添加aria2c服务到开机启动

sudo update-rc.d aria2c defaults

启动服务

sudo service aria2c start

查看服务状态

sudo systemctl status aria2c

增加自动更新bt trackers列表

创建trackers-list-aria2.sh文件

vim trackers-list-aria2.sh

内容如下

#!/bin/bash
service aria2 stop
list=`wget -qO- https://blog.e9china.net/github/trackers_all.txt|awk NF|sed ":a;N;s/\n/,/g;ta"`
if [ -z "`grep "bt-tracker" /etc/aria2/aria2.conf`" ]; then
    sed -i '$a bt-tracker='${list} /etc/aria2/aria2.conf
    echo add......
else
    sed -i "[email protected]=.*@[email protected]" /etc/aria2/aria2.conf
    echo update......
fi
service aria2 start

上面脚本使用的是sandy在国外服务器自动下载的,国内毕竟下载不了github,所以........如果你不喜欢用那么就用回官方的地址

#sandy中转服务器更新每天凌晨1点更新
https://blog.e9china.net/github/trackers_all.txt
https://blog.e9china.net/github/all.txt
https://blog.e9china.net/github/best.txt
https://blog.e9china.net/github/http.txt

#这里是对应上面自动更新的官方url
https://trackerslist.com/all.txt
https://trackerslist.com/best.txt
https://trackerslist.com/http.txt
https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt

设置crontab,让他每天都更新

crontab -e
0 6 * * * bash /etc/aria2/trackers-list-aria2.sh

Sandyliao

保持飢渴好吃的性格、維持好攝之徒的愛好、繼續在三流的技術下活著!

文章评论

您需要 登录 之后才可以评论