Post

服务器快速命令

服务器快速命令

代理

巨坑之导出代理

在导出代理时,必须大小写全部导出:

1
PORT=7890 && export http_proxy=http://127.0.0.1:$PORT && export https_proxy=http://127.0.0.1:$PORT && export HTTP_PROXY=http://127.0.0.1:$PORT && export HTTPS_RPOXY=http://127.0.0.1:$PORT

在某些 shell 或 Python 环境里(特别是 root + conda base 环境),小写版并不会被继承。

取消代理:

1
unset http_proxy && unset https_proxy && unset HTTP_PROXY && unset HTTPS_RPOXY

SSH 反向代理服务器的网络到本机

在本机终端执行:

1
ssh -R host:7891:127.0.0.1:7890 username@host

连接完成后,执行:

1
export https_proxy=http://127.0.0.1:7891 http_proxy=http://127.0.0.1:7891 all_proxy=socks5://127.0.0.1:7891

如果需使用 conda install 来安装第三方库,还需执行:

1
2
conda config --set proxy_servers.http http://127.0.0.1:7891
conda config --set proxy_servers.https https://127.0.0.1:7891

如果要使用 Git,还需执行:

1
2
git config --global http.proxy http://127.0.0.1:7891
git config --global https.proxy https://127.0.0.1:7891

为什么这个方法,ping 不通 www.baidu.com?ping 是使用的 ICMP 协议,而 SSH 只转发 TCP 流量。

SSH

生成 SSH 密钥对

1
ssh-keygen -t ed25519 -C "sunsealucky@gmail.com" -f ~/.ssh/id_ed25519_sunsealucky

配置服务器免密登录

1
2
3
vim ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

数据传输

数据高速下载方案

方案一:Aria2 + AList + 阿里云盘

  1. 配置 AList
1
curl -fsSL "https://alist.nn.ci/v3.sh" -o v3.sh && bash v3.sh

如果是基于容器的服务器,则无法使用脚本内自带的命令,因为其中包含 systemctl 命令,容器环境无法使用。应当直接:

1
cd /opt/alist

启动 AList 服务器

1
./alist server

设置账号密码

1
./alist admin set 123456789

进入 http://localhost:5244/ 后,点击下方的管理按钮,添加一个新的阿里云存储。刷新令牌地址。

  1. 配置 Aria2

执行:

1
sudo apt update && sudo apt install aria2 aria2p

复制 AList 中需要下载文件的链接,执行:

1
2
$URL=<url>
aria2c --enable-rpc --rpc-listen-all -s 3 -j 3 -c -l download.log -D $URL

其中 -s 3 表示同时下载三个任务,-j 3 表示同时使用三个下载连接,-c 表示断点续传,-l download.log 表示日志文件,-D 表示指定下载目录。

可以通过如下命令查看下载进度:

1
aria2p top

AutoDL

配置 HuggingFace 和 Conda 缓存路径

1
2
3
4
5
6
7
8
mkdir -p /root/autodl-tmp/.cache/huggingface
echo "export HF_HOME=/root/autodl-tmp/.cache/huggingface" >> ~/.bashrc
echo "export HF_ENDPOINT=https://hf-mirror.com" >> ~/.bashrc
mkdir -p /root/autodl-tmp/.cache/conda/pkgs
mkdir -p /root/autodl-tmp/.cache/conda/envs
conda config --add pkgs_dirs /root/autodl-tmp/.cache/conda/pkgs
conda config --add envs_dirs /root/autodl-tmp/.cache/conda/envs
source ~/.bashrc
This post is licensed under CC BY 4.0 by the author.