macOS 上使用 Homebrew 安装和配置 frp 客户端

macOS 上使用 Homebrew 安装和配置 frp 客户端 (frpc) 指南

frp (Fast Reverse Proxy) 是一款高性能的反向代理应用,常用于内网穿透。本文将介绍在 macOS 上使用 Homebrew 安装 frpc,并进行配置和管理。


一、安装 frpc

使用 Homebrew 安装(推荐)

  1. 确保已安装 Homebrew

  2. 给终端中执行:

    bash 复制代码
    brew install frpc

安装完成后,frpc 可执行文件通常位于:

  • M1/M2 系列芯片:/opt/homebrew/bin/frpc
  • Intel 版 mac:/usr/local/bin/frpc

二、配置 frpc

创建配置文件

  1. 创建配置文件目录:

    bash 复制代码
    sudo mkdir -p /opt/homebrew/etc/frp
  2. 创建并编辑 frpc.toml

    bash 复制代码
    sudo nano /opt/homebrew/etc/frp/frpc.toml
  3. 配置示例:

    toml 复制代码
     # 公共配置
     serverAddr = "阿里云服务器公网IP"
     serverPort = 7000
     auth.method = "token"
     auth.token = "你的token"
     
     # Gitea 服务转发
     [[proxies]]
     name = "Gitea"
     type = "tcp"
     localIP = "127.0.0.1"
     localPort = 3000            # Gitea 在群晖上的端口
     remotePort = 3000           # 阿里云上的访问端口
     
     # GitLab 服务转发
     [[proxies]]
     name = "GitLab"
     type = "tcp"
     localIP = "127.0.0.1"
     localPort = 8888            # GitLab 在群晖上的端口
     remotePort = 8888           # 阿里云上的访问端口

注意:不要在 serverAddr 前加 http:// 或 https://


三、启动和关闭 frpc

启动 frpc

bash 复制代码
/opt/homebrew/bin/frpc -c /opt/homebrew/etc/frp/frpc.toml

如果配置正确,将看到例如下面的输出:

复制代码
[I] [service.go:288] login to server success, get run id [xxxxxxx]

关闭 frpc

bash 复制代码
pkill frpc

四、设置开机自启动

使用 Homebrew Services

  1. 先确保已安装 services 接口:

    bash 复制代码
    brew tap homebrew/services
  2. 启动 frpc 服务:

    bash 复制代码
    brew services start frpc

    默认会使用 /opt/homebrew/etc/frp/frpc.toml

  3. 停止 frpc 服务:

    bash 复制代码
    brew services stop frpc

五、查看日志

bash 复制代码
tail -f /opt/homebrew/var/log/frpc.log

附录:常见配置错误

错误示例:

复制代码
parse "http://[http://47.97.xx.xx]:7000": missing ']' in host

原因: serverAddr 中包含了 http:// 前缀

解决: 不要加 http://,直接写 IP 或域名


附录:推荐的 GUI 端

相关推荐
pe7er2 天前
macOS 应用无法打开(权限问题)解决方案
macos·mac
harmful_sheep5 天前
mac生效的终端查看
macos
iOS门童6 天前
macOS 应用"已损坏"无法打开?一文搞懂 Gatekeeper 与解决方案
macos
NPE~6 天前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具
差不多程序员6 天前
Mac安装OpenClaw-cn保姆级教程
macos
dzl843946 天前
mac 安装python
开发语言·python·macos
Bruce_Liuxiaowei6 天前
在 macOS 上通过 Docker 本地安装 OpenClaw 完整教程
macos·docker·容器·openclaw
阿捏利6 天前
详解Mach-O(十五)Mach-O __DATA_CONST
macos·ios·c/c++·mach-o
ShikiSuen6 天前
macOS 的 CpLk 中英切换卡顿的元凶在 InputMethodKit 本身
macos
xiayutian_c6 天前
如虎添翼-MacOS
macos