frp 是反向代理应用,支持 TCP/UDP/HTTP/HTTPS,可将内网服务暴露到公网。
安装目录:/root/frp
服务端配置
vim /root/frp/frps.ini
[common]
bind_port = 19000
allow_ports = 19001-19999
authentication_method = token
token = XXXXXXXXXXXXXXXXXX
log_file = /var/log/frp/frps.log
log_max_days = 30
开机自启 vim /etc/systemd/system/frps.service
[Unit]
Description = frp server
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 enable --now frps
客户端配置
vim /root/frp/frpc.ini
[common]
server_addr = 公网IP或域名
server_port = 19000
authentication_method = token
token = XXXXXXXXXXXXXXXXXX
log_file = /var/log/frp/frpc.log
log_max_days = 30
includes = /root/frp/servers/*.ini
/root/frp/servers/ 下可配置多个转发规则:
[name_ssh_01]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 19001
开机自启 vim /etc/systemd/system/frpc.service
[Unit]
Description = frp client
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
ExecStart = /root/frp/frpc -c /root/frp/frpc.ini
Restart = on-failure
RestartSec = 60
[Install]
WantedBy = multi-user.target
systemctl enable --now frpc
无 systemd 时(手动 crontab)
/root/start.sh
#!/bin/sh
count=$(ps -ef | grep frpc | grep -v grep | wc -l)
if [ $count -eq 0 ]; then
/root/frp/frpc -c /root/frp/frpc.ini &
fi
crontab -e
# 01 01 * * * /root/start.sh >> /var/log/frpc.log