frp下载地址:https://github.com/fatedier/frp/releases

frp官方文档:https://gofrp.org/docs

服务端frps配置

下载

1
2
3
wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_amd64.tar.gz
tar -zxvf frp_0.37.1_linux_amd64.tar.gz
mv frp_0.37.1_linux_amd64 frp

配置

阿里云服务器需要配置安全组,开放6000/8000端口

查看防火墙状态:systemctl status firewalld.service,如果出现绿色字样标注的“active(running)”,说明防火墙是开启状态,执行systemctl stop firewalld.service关闭防火墙

1
2
3
4
5
6
cd frp
vim frps.ini

[common]
bind_port = 7000
token = xxxx

挂载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vim /lib/systemd/system/frps.service

[Unit]
Description=frps service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
ExecStart=/root/frp/frps -c /root/frp/frps.ini

[Install]
WantedBy=multi-user.target

systemctl start frps
systemctl enable frps

客户端frpc配置

下载

1
2
3
wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_amd64.tar.gz
tar -zxvf frp_0.37.1_linux_amd64.tar.gz
mv frp_0.37.1_linux_amd64 frp

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
cd frp
vim frpc.ini

[common]
server_addr = xxx.xxx.xxx.xxx(服务端公网地址)
server_port = 7000
token = xxx

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

挂载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vim /lib/systemd/system/frpc.service

[Unit]
Description=frpc service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
ExecStart=/root/frp/frpc -c /root/frp/frpc.ini

[Install]
WantedBy=multi-user.target

systemctl start frpc
systemctl enable frpc

补充

不知为何,家里的ubuntu不能开机自启frpc

1
2
3
4
5
6
root@oyal-desktop:~# systemctl status frpc
● frpc.service - frapc service
Loaded: loaded (/lib/systemd/system/frpc.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2021-09-04 12:25:31 CST; 1min 58s ago
Process: 673 ExecStart=/root/frp/frpc -c /root/frp/frpc.ini (code=exited, status=1/FAILURE)
Main PID: 673 (code=exited, status=1/FAILURE)

改用supervisor

1
2
3
4
5
6
7
8
9
10
11
apt install supervisor
vim /etc/supervisor/conf.d/frpc.conf

[program:frp]
command = /root/frp/frpc -c /root/frp/frpc.ini
autostart = true

systemctl restart supervisor

root@oyal-desktop:~# supervisorctl status
frpc RUNNING pid 1438, uptime 0:02:26

常用指令

1
2
3
4
5
6
7
8
supervisorctl status # 查看进程运行状态
supervisorctl start 进程名 # 启动进程
supervisorctl stop 进程名 # 关闭进程
supervisorctl restart 进程名 # 重启进程
supervisorctl update # 重新载入配置文件
supervisorctl shutdown # 关闭supervisord
supervisorctl clear # 进程名 清空进程日志
supervisorctl # 进入到交互模式下。使用help查看所有命令。

访问

可以通过ssh xxx.xxx.xxx.xxx:6000来连接到客户端的22端口