【frp】利用frp搭建内网穿透——保姆级教程

一、服务器端(云服务器)

1.开放端口

如果是运营商买的云服务器需要在安全组开放frp的端口7000、面板端口以及代理映射要用到的端口。

2.下载frp并解压

GitHub下载地址:https://github.com/fatedier/frp/releases
根据自己的需求使用wget下载相应版本

# 下载frp可执行包
wget https://github.com/fatedier/frp/releases/download/v0.xxx/frp_0.xxx_linux_amd64.tar.gz

# 解压
tar zxf frp_0.xxx_linux_amd64.tar.gz

3.配置服务器端

frps.ini是服务器端的配置文件(server)

#进入目录
cd frp_0.34.2_linux_amd64/
# 修改配置
vi frps.ini 

配置文件如下:

[common]
# 服务器端和客户端通信的端口
bind_port = 7000

# http映射用端口
vhost_http_port = 6001

# 连接认证token(选用)
#token = 123456

# 面板端口
dashboard_port = 7500

#面板登录
dashboard_user = admin
dashboard_pwd = xxx

配置好之后就可以使用配置文件启动了

./frps -c frps.ini 

4.设置服务开机自启动和进程守护

开机自启动

# 创建后台启动模版
vi /etc/systemd/system/frps.service
# 内容如下:
[Unit]
Description=frps
After=network.target

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

[Install]
WantedBy=multi-user.target
# 启动测试
systemctl start frps.service
# 查看启动状态
systemctl status frps.service
# 开机自启
systemctl enable frps.service

supervisor进程守护

#安装supervistor
yum install supervisor -y
#新建目录和文件/etc/supervisor/conf.d/frps.conf
[program:frps]
user=root
command=/root/frp/frps -c /root/frp/frps.ini
startsecs=1
startretries=100
autorstart=true
autorestart=true
stderr_logfile=/tmp/err-frps.log
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=10
stdout_logfile=/tmp/out-frps.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
#重载
supervisorctl update

二、客户端(公司电脑)

1.下载客户端软件

在GitHub上选择自己电脑的版本。
frp下载对应版本
解压即可

2.配置客户端

frpc.ini是客户端的配置文件(client)
type:通信方式
local_port:被映射的端口(本地端口)
remote_port:映射的端口(云服务器端口)

[common]
#服务器地址
server_addr=39.96.172.xx
#服务器通信端口
server_port=7100

[maven]
type=http
local_ip=192.168.1.xx
local_port=8081
#http域名
custom_domains = www.xxx.xyz

[mysql]
type=tcp
local_ip= 192.168.1.xx
local_port=3306
remote_port=3306

[mongo]
type=tcp
local_ip= 192.168.1.xx
local_port=27017
remote_port=27017

[redis]
type=tcp
local_ip= 192.168.1.xx
local_port=6379
remote_port=6379

3.设置开机自启动服务

原理:使用winsw将shell命令包成服务并设置开机自启动
winsw github地址:https://github.com/winsw/winsw/releases/tag/v2.11.0
下载后将winsw放在和frp同级目录
新建xml文件,进行配置,如下:

<service>
	<id>frp</id>
	<name>frp</name>
	<description>frp服务</description>
	<executable>frpc</executable>
	<arguments>-c frpc.ini</arguments>
	<logmode>reset</logmode>
</service>

文件结构如下图所示:
winsw文件结构
运行命令:

winsw.exe install
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值