如何搭建Claude Code/Gemini Cli镜像站

关键点

  • 自己购买太贵,可多人拼车分摊成本

  • 本地梯子需频繁切换梯子,影响电脑环境

1.环境准备

可在RackNerd自行购买一个洛杉矶节点的KVM VPS虚拟机,选择Debian 12 1核 1G虚拟机,价格大概80RMB一年,购买完成之后,会在邮箱收到服务器ip和用户名密码,需要自己使用ssh的方式连接服务器
enter image description here

enter image description here

 

2.部署claude镜像站

claude-relay-service在github上的地址是

https://github.com/Wei-Shaw/claude-relay-service

2.1.快速安装

步骤1:脚本安装crs

curl -fsSL https://raw.githubusercontent.com/Wei-Shaw/claude-relay-service/main/scripts/manage.sh -o manage.sh

chmod +x manage.sh

./manage.sh install

chmod +x /usr/bin/crs

enter image description here

步骤2:启动服务

crs start

enter image description here

  • 管理命令

    crs install   # 安装服务
    crs start     # 启动服务
    crs stop      # 停止服务
    crs restart   # 重启服务
    crs status    # 查看状态
    crs update    # 更新服务
    crs uninstall # 卸载服务

  • 修改配置示例

     crs install
    
    # 会依次询问:
    安装目录 (默认: ~/claude-relay-service): 
    服务端口 (默认: 3000): 8080
    Redis 地址 (默认: localhost): 
    Redis 端口 (默认: 6379): 
    Redis 密码 (默认: 无密码): 
    
    # 安装完成后自动启动并显示:
    服务已成功安装并启动!
    
    访问地址:
      本地 Web: http://localhost:8080/web
      公网 Web: http://YOUR_IP:8080/web
    
    管理员账号信息已保存到: data/init.json

3.管理Claude Code镜像

浏览器访问:http://你的服务器IP:3000/web
enter image description here

3.1.登录管理后台

enter image description here
enter image description here
enter image description here

3.2.添加Claude账户

这一步需要Claude授权
enter image description here
enter image description here
复制链接到浏览器授权登录,讲获取到的token粘贴到授权框完成授权
enter image description here
enter image description here
enter image description here

3.3.创建API Key

enter image description here
enter image description here

3.4.配置本地环境变量

  • Claude Code 设置环境变量

    export ANTHROPIC_BASE_URL="http://127.0.0.1:3000/api/" # 根据实际填写你服务器的ip地址或者域名
    export ANTHROPIC_AUTH_TOKEN="后台创建的API密钥"

  • Gemini CLI 设置环境变量

    export CODE_ASSIST_ENDPOINT="http://127.0.0.1:3000/gemini" # 根据实际填写你服务器的ip地址或者域名
    export GOOGLE_CLOUD_ACCESS_TOKEN="后台创建的API密钥"  # 使用相同的API密钥即可
    export GOOGLE_GENAI_USE_GCA="true"

    enter image description here
    enter image description here

 

作者:admin  创建时间:2025-08-05 10:06
最后编辑:admin  更新时间:2025-08-05 15:10