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 端

相关推荐
Architect_Lee34 分钟前
mac快速安装mysql
数据库·mysql·macos
User_芊芊君子2 小时前
STT + LLM + TTS:用一条流水线搓了个中英双向翻译助手
ide·macos·xcode
凤山老林19 小时前
在 Apple 芯片的 Mac 上通过 VMware Fusion 使用 Windows 11
windows·macos·vmware·虚拟机
c&0xff0021 小时前
mac通过网线连接树莓派
macos
孙启超1 天前
Token太贵自己写了一个mac版开源AI编程工具
人工智能·macos·开源·llm·agent·ai编程·ai应用开发
2601_965798471 天前
Launch Your Wellness App Fast: The Truth About Meditation Source Code
前端·macos·ios·objective-c·cocoa
2501_915909063 天前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915918413 天前
免 Xcode 开发 iOS,工具链替代方案与编译、签名、安装
ide·vscode·macos·ios·个人开发·xcode·敏捷流程
Architect_Lee3 天前
mac安装多个tomcat
macos