Centos7 – frp内网穿透,访问内网web服务/访问内网websocket服务
原创文章,作者:StubbornHuang,如若转载,请注明出处:《Centos7 – frp内网穿透,访问内网web服务/访问内网websocket服务》https://www.stubbornhuang.com/788/
1 frp
Github地址:https://github.com/fatedier/frp
Github发布包地址:https://github.com/fatedier/frp/releases
官方教程:https://github.com/fatedier/frp/blob/master/README_zh.md
2 需求说明
如果我们在内网部署了一个网页即时聊天程序,使用websocket保持长连接并即时通信,网页http请求端口为80,而websocket请求端口为45635,该网页聊天服务在内网机子上部署。
需求:希望使用frp进行内网穿透,可以访问内网机子上的web服务打开聊天网页,也可以使用websocket服务进行网页即时聊天。
3 外网服务器frp服务端配置(安装时最新版本0.32.1为例)
3.1 下载frp
使用
mkdir frp
命令创建一个新的文件夹frp,然后在文件夹下使用命令:
wget https://github.com/fatedier/frp/releases/download/v0.32.1/frp_0.32.1_linux_amd64.tar.gz
下载frp。
3.2 解压,并进入解压文件夹
tar -zxvf frp_0.32.1_linux_amd64.tar.gz
cd frp_0.32.1_linux_amd64/
3.3 删掉不必要的客户端文件
rm -rf frpc
rm -rf frpc.ini
3.4 编辑frps.ini文件
vi frps.ini
打开该文件,并将该文件内容修改为:
[common]
# 服务器端监听客户端连接请求的端口
bind_port = 7000
# 服务器端监听http请求的端口
vhost_http_port = 80
保存退出。
3.5 防火墙开启相关端口
开启端口:
firewall-cmd --zone=public --add-port=7000/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=45635/tcp --permanent
重启防火墙:systemctl restart firewalld.service
3.6 启动服务的几种方式
3.6.1 正常启动
./frps -c ./frps.ini
3.6.2 使用nohup后台挂起服务
nohup ./frps -c frps.ini > ./log.txt 2>&1 &
日志输出到log.txt
3.6.3 制作一键启动sh脚本
3.6.3.1 启动脚本start.sh
#! /bin/bash
nohup ./frps -c frps.ini > log.txt 2>&1 &
echo $! >./pid.txt
3.6.3.2 停止脚本stop.sh
#! /bin/bash
PID=(cat ./pid.txt)
kill -9PID
3.6.3.4 实时日志查看
tail -f ./log.txt
4 内网服务器frp客户端配置(安装时最新版本0.32.1为例)
4.1 下载
使用
mkdir frp
命令创建一个新的文件夹frp,然后在文件夹下使用命令:
wget https://github.com/fatedier/frp/releases/download/v0.32.1/frp_0.32.1_linux_amd64.tar.gz
下载frp。
4.2 解压,并进入解压文件夹
tar -zxvf frp_0.32.1_linux_amd64.tar.gz
cd frp_0.32.1_linux_amd64/
4.3 删掉不必要的客户端文件
rm -rf frps
rm -rf frps.ini
4.4 编辑frpc.ini文件
vi frpc.ini
打开该文件,并将该文件内容修改为:
[common]
server_addr = xx.xx.xx.xx(外网主机ip)
server_port = 7000
# 内网web服务,监听端口为80
[web]
type = http
local_port = 80
custom_domains = xx.xx.xx.xx(外网主机ip,和server_addr的相同,或者写域名,但是要做dns解析)
# websocket服务,端口假设为45635
[web01]
type = tcp
local_port = 45635
custom_domains = xx.xx.xx.xx(外网主机ip,和server_addr的相同,或者写域名,但是要做dns解析)
remote_port = 45635
保存退出。
4.5 防火墙开启相关端口
开启端口:
firewall-cmd --zone=public --add-port=7000/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=45635/tcp --permanent
重启防火墙:systemctl restart firewalld.service
4.6 启动服务的几种方式
4.6.1 正常启动
./frpc -c ./frpc.ini
4.6.2 使用nohup后台挂起服务
nohup ./frpc -c frpc.ini > ./log.txt 2>&1 &
日志输出到log.txt
4.6.3 制作一键启动sh脚本
4.6.3.1 启动脚本start.sh
#! /bin/bash
nohup ./frpc -c frpc.ini > log.txt 2>&1 &
echo $! >./pid.txt
4.6.3.2 停止脚本stop.sh
#! /bin/bash
PID=(cat ./pid.txt)
kill -9PID
4.6.3.4 实时日志查看
tail -f ./log.txt
5 访问测试
分别开启远程主机frp服务,以及内网frp服务,保证相关端口已开启。
frp内网穿透访问内网web服务:xx.xx.xx.xx:80
frp内网穿透访问内网websocket服务:xx.xx.xx.xx:45635
当前分类随机文章推荐
- Centos7 - 防火墙操作以及开启和关闭特定端口
- Centos7 - frp内网穿透,访问内网web服务/访问内网websocket服务
- Centos - 更换SSH端口
- Centos7 - 配置Go环境
- Centos7 - nohup方式优雅的部署jar包
全站随机文章推荐
- 资源分享 - OpenGL编程指南(原书第7版)- OpenGL红宝书高清扫描版PDF下载
- 资源分享 - Efficient Illumination Algorithms for Global Illumination In Interactive and Real-Time Rendering英文PDF下载
- Modern OpenGL从零开始 - Fbxsdk::FbxAMatrix转换为glm::mat4
- 资源分享 - GPU Zen 1:Advanced Rendering Techniques英文原版Pdf下载
- OpenCV - 读取一张图片显示,并将其重写为灰度图
- WordPress - 插件WP Editor.md 在网站更换为https后无法正确加载
- 我的项目 - Windows/Linux动态库加载类
- 资源下载 - 地球编年史1-7本高清带书签PDF下载
- C++11 - std::bind简要介绍以及可绑定函数的几种形式总结
- 资源分享 - 8i Voxelized Full Bodies – A Voxelized Point Cloud Dataset下载