Linux安装Frp客户端 - xiaohao0576/odoo-doc GitHub Wiki

下载Frp客户端程序

https://github.com/fatedier/frp/releases

frpc程序放到 /usr/local/bin目录下

设置frpc文件运行权限

sudo chmod +x /usr/local/bin/frpc

准备配置文件

创建/etc/frp/frpc.toml,内容如下

serverAddr = "103.222.333.99"
serverPort = 7000
auth.method = "token"
auth.token = "Frps@Password"

[proxies](/xiaohao0576/odoo-doc/wiki/proxies)
name = "client-ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 31020

创建systemd服务

$ sudo vim /etc/systemd/system/frpc.service

[Unit]
Description = Frp Client
After=network-online.target
Wants=network-online.target

[Service]
Type = simple
Restart=on-failure
RestartSec=5s
ExecStart = /usr/local/bin/frpc -c /etc/frp/frpc.toml

[Install]
WantedBy = multi-user.target

设置开机自启动

sudo systemctl enable frpc

使用 systemd 命令管理 frpc 服务

# 启动frp
sudo systemctl start frpc
# 停止frp
sudo systemctl stop frpc
# 重启frp
sudo systemctl restart frpc
# 查看frp状态
sudo systemctl status frpc

参考文档: https://gofrp.org/zh-cn/docs/setup/systemd/

构建deb安装包

~/Downloads$ tree frpc_0.61.0
frpc_0.61.0
├── DEBIAN
│   ├── control
│   └── postinst
├── etc
│   ├── frp
│   │   └── frpc.toml
│   └── systemd
│       └── system
│           └── frpc.service
└── usr
    └── local
        └── bin
            └── frpc

9 directories, 5 files

~/Downloads$ cat frpc_0.61.0/DEBIAN/control 
Package: frpc
Version: 0.61.0
Architecture: amd64
Section: net
Priority: optional
Maintainer: Your Name <[email protected]>
Description: frp client for Linux
 A fast reverse proxy client to help you expose a local server
 behind a NAT or firewall to the Internet.
~/Downloads$ cat frpc_0.61.0/DEBIAN/postinst 

#!/bin/bash
set -e

# 设置权限
chmod 755 /usr/local/bin/frpc
chmod 644 /etc/frp/frpc.toml
chmod 644 /etc/systemd/system/frpc.service

# 重载systemd
systemctl daemon-reload

# 启用并启动服务
systemctl enable frpc
systemctl start frpc

~/Downloads$ dpkg-deb --build frpc_0.61.0 frpc_0.61.0_amd64.deb
dpkg-deb: building package 'frpc' in 'frpc_0.61.0_amd64.deb'.