sshuttle

github地址

1
2
3
4
5
# 本地安装
brew install sshuttle

# 本地执行命令, 将10.0.1.0/24流量代理到服务器中去
sshuttle --sudoers-user fa -r jump.local.container2222-sshuttle.fa.intranet.company 10.0.1.0/24

vllm使用记录

GitHub地址

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 安装 Miniconda
# 运行安装脚本:

# Linux:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p ${HOME}/software/miniconda3
# macOS:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh -b -p ${HOME}/software/miniconda3

# 配置环境变量:

# 将以下内容添加到 ~/.bashrc 或 ~/.zshrc 文件中:
export PATH=${HOME}/software/miniconda3/bin:$PATH
# 刷新环境变量:
source ~/.bashrc
# 验证安装:
conda --version
# 如果显示版本号,说明安装成功。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# (Recommended) Create a new conda environment.
conda create -n vllm python=3.12 -y
conda activate vllm
# PS: 有时可能需要先初始化 conda init 然后执行 bash 重新打开终端, 之后才能使用 conda activate vllm
# 取消激活环境
conda deactivate


# 配置 pip 源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn


# 在虚拟环境中安装 vllm 0.4.2 版本
pip install vllm==0.4.2
# 或者安装最新版本
pip install vllm
  • docker 安装
1
2
3
4
5
6
7
8
9
# vLLM 提供了一个官方 Docker 镜像用于部署。该镜像可用于运行与 OpenAI 兼容服务器,并且可在 Docker Hub 上以 vllm/vllm-openai 的形式获取。
# PS: 需要英伟达运行时
docker run --runtime nvidia --gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HUGGING_FACE_HUB_TOKEN=<secret>" \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:latest \
--model mistralai/Mistral-7B-v0.1
  • 源码安装
1
2
3
4
5
6
7
8
9
10
# 启用Docker BuildKit
# export DOCKER_BUILDKIT=1
# export COMPOSE_DOCKER_CLI_BUILD=1
docker build -f Dockerfile.cpu -t vllm-cpu-env --shm-size=4g .
docker run -it \
--rm \
--network=host \
--cpuset-cpus=<cpu-id-list, optional> \
--cpuset-mems=<memory-node, optional> \
vllm-cpu-env

使用

1
2
3
# Run the following command to start the vLLM server with the Qwen2.5-1.5B-Instruct model:
vllm serve Qwen/Qwen2.5-1.5B-Instruct
vllm serve BAAI/bge-reranker-v2-m3

异常问题

  • ModuleNotFoundError: No module named 'torch'
1
pip install torch
  • for instructions on how to install GCC 5 or higher.
1
2
yum install centos-release-scl
yum install devtoolset-11-gcc devtoolset-11-gcc-c++

sshuttle

github地址

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装
brew install sshuttle

# 配置本地mac免密
sshuttle --sudoers-no-modify
# 执行后会打印配置内容
# 执行以下命令, 将配置内容写入到以下文件中
visudo /etc/sudoers.d/sshuttle_auto

# 免密使用(fa为免密用户, 需指定)(配合ssh config使用)
# PS: 貌似并没有免密
sshuttle --sudoers-user fa -r jump.local.container2222-sshuttle.fa.intranet.company 10.0.1.0/24

1
2
3
4
5
6
7
8
9
10
11
12
13

# 其他使用方式示例
sshuttle -r root@10.0.1.90 --python $(which python3) 0.0.0.0/0

# 成功命令(--python指定的是服务端的python命令, 在服务端安装了python3)
sshuttle -r root@container2222.fa.intranet.company --python /usr/bin/python3 0.0.0.0/0
# 简化版
sshuttle -r container2222.fa.intranet.company 0.0.0.0/0

# 通过内部mac服务器访问网络, mac中连接了其他公司内部VPN, 一下命令实现让本机也能访问受VPN限制的网络
sshuttle -r mac.intranet.company 0.0.0.0/0
# 可以指定代理的域名
sshuttle -r mac.intranet.company baidu.com

高级操作(客户端零配置功能测试失败)

一、服务器端配置(一次性操作)

1. 创建专用 VPN 用户

1
2
sudo useradd -r -s /usr/sbin/nologin vpn-tunnel  # 创建无登录权限的系统用户
sudo mkdir -p /home/vpn-tunnel/.ssh

2. 生成服务器专用密钥对

1
2
3
4
5
# 在服务器上生成密钥(仅需执行一次)
sudo ssh-keygen -t ed25519 -f /etc/ssh/vpn-server-key -N "" -C "vpn-server@company"

# 设置权限
sudo chmod 600 /etc/ssh/vpn-server-key*

3. 配置自动授权

1
2
3
# 将公钥设为 VPN 用户的唯一授权方式
sudo cp /etc/ssh/vpn-server-key.pub /home/vpn-tunnel/.ssh/authorized_keys
sudo chown -R vpn-tunnel:vpn-tunnel /home/vpn-tunnel/.ssh

4. 加固 SSH 配置 (/etc/ssh/sshd_config)

1
2
3
4
5
6
7
8
9
10
# 限制 VPN 用户权限
Match User vpn-tunnel
AllowTcpForwarding no # 禁用端口转发
PermitTunnel yes # 允许创建隧道
ForceCommand /bin/false # 禁止执行任何命令
AuthenticationMethods publickey
PermitRootLogin no
X11Forwarding no
AllowAgentForwarding no
IdentityFile /etc/ssh/vpn-server-key

5. 应用配置

1
2
3
4
5
6
7
8
# 重启sshd
sudo systemctl restart sshd
# 如果没有上面的命令, 则使用下面的方案

# 测试 sshd 配置文件的语法是否正确
/usr/sbin/sshd -t
# 发送 HUP 信号, 促使 sshd 进程重新加载配置。
/usr/sbin/sshd -k HUP

二、客户端零配置连接方案

方案 B:证书认证(更安全,适合生产环境)

1
2
3
4
5
6
7
# 在服务器上生成 CA 证书
sudo ssh-keygen -t ed25519 -f /etc/ssh/ca_key -N ""

# 签署 VPN 用户证书(有效期 30 天)
sudo ssh-keygen -s /etc/ssh/ca_key -I "vpn-cert" -n vpn-tunnel -V +30d /home/vpn-tunnel/.ssh/authorized_keys

# 客户端只需信任 CA 公钥即可连接

Terminal

Arthas

Docker

Git

Gradle

0%