frp提供内网穿透的功能,它不会在客户端监听额外的端口(会启动一个后台进程),会在服务端监听2个端口,一个端口是跟客户端通信用,访问另一个端口就是穿透到客户端指定的一个端口上
功能完成后,FRP将在Server端监听2个端口,一个端口用来与FRP Client通信,另外一个端口则是要访问的实际端口,FRP在客户端上不监听额外的端口
安装
# wget http://dld.as4k.top/frp_0.34.1_linux_amd64.tar.gz
# tar xf frp_0.34.1_linux_amd64.tar.gz
# ls /data/frp/frp_0.34.1_linux_amd64
frpc frpc_full.ini frpc.ini frps frps_full.ini frps.ini LICENSE systemd
# cp frps frpc /usr/bin
frp server端配置
# cat << 'EOF' > /data/frp/frps_7001.ini
[common]
bind_port = 7001
EOF
配置supervisor管理
cat << 'EOF' > /etc/supervisord.d/frps_7001.ini
[program:frps_7001]
command=/usr/bin/frps -c /data/frp/frps_7001.ini
EOF
supervisor 安装及使用参考 https://blog.csdn.net/xys2015/article/details/109410032
启动
systemctl restart supervisord.service
supervisorctl status
supervisorctl status frps_7001
此时服务器上会监听7001端口,该端口用来跟客户端通信
安装
与server端基本一样,此处不在赘述
frp client端配置
# cat << 'EOF' > /data/frp/frpc.ini
[common]
server_addr = xx.xx
server_port = 7001
[http]
type = tcp
local_ip = 127.0.0.1
local_port = 80
remote_port = 7002
EOF
配置supervisor管理
cat << 'EOF' > /etc/supervisord.d/frpc.ini
[program:frpc]
command=/usr/bin/frpc -c /data/frp/frpc.ini
EOF
启动
systemctl restart supervisord.service
supervisorctl status
supervisorctl status frpc
访问
http://xx.xx:7002 #xx.xx 替换成实际的云服务器公网IP地址或者域名s
server:7002 --> client:80
用bash脚本管理,参考脚本如下
server
[root@ip-172-31-42-40 frp_0.29.0_linux_amd64]# cat xfrps_7001.sh
#!/bin/bash
# frp server manager script
fdir=/as4k/frp_0.29.0_linux_amd64
frps_config_file=$fdir/frps_7001.ini
kill `ps aux | grep "$frps_config_file" | grep -v grep | awk '{print $2}'` &> /dev/null
sleep 1
cat << 'EOF' > $frps_config_file
[common]
bind_port = 7001
EOF
nohup $fdir/frps -c $frps_config_file &>> $fdir/frps.log &
sleep 2
tail $fdir/frps.log
client
root@DESKTOP-PM5KOT8:~# cat xfrpc_7001.sh
#!/bin/bash
fdir=/as4k/frp_0.29.0_linux_amd64
frpc_config_file=$fdir/frpc_7001.ini
kill `ps aux | grep "$frpc_config_file" | grep -v grep | awk '{print $2}'` &> /dev/null
sleep 1
cat << 'EOF' > $frpc_config_file
[common]
server_addr = aws.as4k.top
server_port = 7001
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 6001
EOF
nohup $fdir/frpc -c $frpc_config_file &>> $fdir/frps.log &
sleep 2
tail $fdir/frps.log
server
=================
[root@qingcloud ~]# netstat -lntup | grep frp
tcp6 0 0 :::7001 :::* LISTEN 30621/frps
tcp6 0 0 :::7002 :::* LISTEN 30621/frps
[root@qingcloud ~]# ps aux | grep frp
root 30621 0.0 0.5 717072 20548 ? Sl 19:35 0:00 /usr/bin/frps -c /data/frp/frps_7001.ini
[root@qingcloud ~]# supervisorctl status frps_7001
frps_7001 RUNNING pid 30621, uptime 0:59:36
client
=================
[root@10-222-32-122 ~]# ps aux | grep frp
root 958 0.0 0.3 712956 11688 ? Sl 20:07 0:00 /usr/bin/frpc -c /data/frp/frpc.ini
[root@10-222-32-122 ~]# supervisorctl status frpc
frpc RUNNING pid 958, uptime 0:29:40
https://github.com/fatedier/frp
https://github.com/fatedier/frp/blob/dev/README_zh.md
https://github.com/fatedier/frp/releases
https://github.com/fatedier/frp/releases/download/v0.34.1/frp_0.34.1_linux_amd64.tar.gz
http://dld.as4k.top/frp_0.34.1_linux_amd64.tar.gz
博客地址:https://blog.csdn.net/xys2015/article/details/109498816