Roy

  • 首页
  • Linux
  • VPS
  • Nas
  • Ruby
  1. 首页
  2. Nas
  3. 正文

Debian/Ubuntu 原生部署Nas-tools

2023年4月9日 959点热度 1人点赞 0条评论

nas-tools是一个开源优秀的PT资源订阅软件,可以实现订阅,自动下载,自动重命名,自动移动等功能

https://github.com/NAStool/nas-tools

环境

建议Python3.10(按官方文档还需要安装Cython)

如果你的系统没有python3.10,可以用以下脚本安装Python3.10与Cython

sudo apt update
sudo apt upgrade
sudo apt install -y wget build-essential libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz  -O - | tar -xz
cd Python-3.10.0
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
python3.10 -m pip install Cython

下载与安装

没必要使用root用户来运行安装nas-tools

假设你需要安装在/var/www/nas-tools下(如有变动,请自行修改INSTALL_DIR变量),使用下面的脚本可以把库和系统安装完。

INSTALL_DIR="/var/www/nas-tools"
sudo apt install -y git
sudo mkdir -p $INSTALL_DIR
sudo chown $(whoami):$(whoami) $INSTALL_DIR
git clone -b master https://github.com/NAStool/nas-tools --recurse-submodule $INSTALL_DIR
cd $INSTALL_DIR
python3.10 -m pip install -r requirements.txt
# 弄一个方便的升级脚本,这里使用的在setup.py 因为这个文件在gitignore里排除掉的,所以不会更改到git库
cat << EOF | tee $INSTALL_DIR/setup.py
#! /usr/bin/env bash
sudo systemctl stop nas-tools
cd $INSTALL_DIR
git pull
git submodule update --recursive --remote
python3.10 -m pip install -r requirements.txt
sudo systemctl start nas-tools
EOF
chmod +x $INSTALL_DIR/setup.py

我们可以使用systemd来运行nas-tools,假设你保存nas-tools的数据库放在你的HOME下。(如有变动,请自行修改INSTALL_DIR和CONFIG_DIR变量)

INSTALL_DIR="/var/www/nas-tools"
CONFIG_DIR="$HOME/nas-tools"
mkdir -p $CONFIG_DIR
cat << EOF | sudo tee /lib/systemd/system/nas-tools.service
[Unit]
Description=Nas Tools
[Service]
Environment=PATH=$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin
Environment=HOME=$HOME
Environment=RCLONE_CONFIG=$HOME/.config/rclone/rclone.conf
Environment=NASTOOL_CONFIG=$CONFIG_DIR/config.yaml
WorkingDirectory=$INSTALL_DIR
User=$(whoami)
ExecStart=/usr/local/bin/python3.10 run.py
Restart=on-failure
RestartSec=15
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable nas-tools
sudo systemctl start nas-tools

结尾

上面已经成功运行起nas-tools了,如果你需要查看nas-tools的运行状态等,以下是命令

# 查看运行状态
sudo systemctl status nas-tools
# 停止
sudo systemctl stop nas-tools
# 开启
sudo systemctl start nas-tools
# 重启
sudo systemctl restart nas-tools

你可能想要用nginx来反向代理访问nas-tools,以下是配置文件供你参考

server {
  listen  443 ssl http2;
  server_name  你的域名;
  ssl_certificate 证书路径;
  ssl_certificate_key 证书密钥路径;

  client_max_body_size 64M;
  location / {
    proxy_pass  http://127.0.0.1:3000/;
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    proxy_set_header   X-Forwarded-Proto https;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_read_timeout 86400;
  }
}

如何升级nas-tools?

很简单,我们刚才已经在nas-tools的运行目录下的setup.py写入了升级脚本,你需要的仅仅是在命令行下运行该脚本。$INSTALL_DIR/setup.py

标签: 暂无
最后更新:2023年4月18日

roy

这个人很懒,什么都没留下

点赞

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 Roy. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang