基于fpc实现http内网穿透

一、 概述

受限于内网环境,外面无法直接访问边缘端的服务,给运维带来不便,而fpc可以帮我们解决问题。

frp的官网地址: 概览 | frp

二、下载fpc

fpc的包是放在github上 https://github.com/fatedier/frp/releases 

ps : 保持同一版本,服务端与客户端可以架构不一样

三、服务器frps配置

文件:frps.toml

#启用http类型监听端口
vhostHTTPPort = 8088
#frps服务监听端口
bindPort = 9000
#web服务端口
webServer.port = 9001
#登录web服务的用户名
webServer.user = "admin"
#登录web服务的密码
webServer.password = "admin"
#web服务绑定的ip
webServer.addr = "0.0.0.0"
#frpc连接的校验信息
auth.token = "abc"

四、 客户端frpc配置

文件:frpc.toml

# frps服务ip
serverAddr = "x.x.x.x"
# frps服务端口
serverPort = 9000
# 连接frps的token信息
auth.token = "abc"
# 代理配置
[[proxies]]
# 名称
name = "web"
#类型为http
type = "http"
# 绑定本机ip
localIP = "127.0.0.1"
# 绑定本机端口
localPort = 80
# 访问域名,如果没有则填ip
customDomains = ["web.yourdomain.com"]
# 可选参数 URL 路由,对应项目上下文路径,会自动拼接在请求地址后,如location=/api ,则请求 http://{server}/api/xx/yy 对应本地请求 http://{local_server}/api/xx/yy 
locations = ["/"]

PS : 配置自定义域名customDomains的目的是为了区分不同的映射,原理是通过请求头的Host字段区分转发的目的的。

配置方法:

在本机的hosts文件配置域名解析

目录:C:\Windows\System32\drivers\etc\hosts

x.x.x.x web.yourdomain.com

其中 x.x.x.x为frps服务器ip,然后用域名访问 http://web.yourdomain.com/....

这样请求头自带Host:web.yourdomain.com ,frps服务就可以正确转发。(同理,如果使用ip直接访问,则需要自己添加Host参数)

五、fprc一键部署脚本

以AMD64架构为例

#!/bin/bash
FRP_VERSION="0.52.3"
FRP_INSTALL_DIR="/home/frp"
FRP_INSTALL_DIR_BAK="${FRP_INSTALL_DIR}/frp_${FRP_VERSION}_linux_amd64"
FRP_CONFIG_FILE="${FRP_INSTALL_DIR}/frp_${FRP_VERSION}_linux_amd64/frpc.toml"
FRP_DOWNLOAD_URL="https://github.com/fatedier/frp/releases/download/${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz"
FRP_SERVICE_FILE="/home/frp/frpc.service"

if [ ! -d "$FRP_INSTALL_DIR" ]; then
    mkdir -p "$FRP_INSTALL_DIR"
fi

if [ ! -f "$FRP_INSTALL_DIR/frp_${FRP_VERSION}_linux_amd64.tar.gz" ]; then
    wget -P "$FRP_INSTALL_DIR" "$FRP_DOWNLOAD_URL"
fi

if [ ! -f "$FRP_INSTALL_DIR/frp_${FRP_VERSION}_linux_amd64" ]; then
    tar -zxvf "${FRP_INSTALL_DIR}/frp_${FRP_VERSION}_linux_amd64.tar.gz" -C "$FRP_INSTALL_DIR"
fi

cat > "${FRP_CONFIG_FILE}" << EOF
serverAddr = "x.x.x.x"
serverPort = 9000
auth.token = "abc"
[[proxies]]
name = "web"
type = "http"
localIP = "127.0.0.1"
localPort = 80
customDomains = ["x.x.x.x"]
locations = ["/"]
EOF

cat > "${FRP_SERVICE_FILE}" << EOF
[Unit]
Description=Frp Client 
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=${FRP_INSTALL_DIR_BAK}/frpc -c ${FRP_CONFIG_FILE}

[Install]
WantedBy=multi-user.target
EOF

sudo mv $FRP_INSTALL_DIR/frpc.service /etc/systemd/system/

# 授权
sudo chmod 644 /etc/systemd/system/frpc.service
# 刷新配置
sudo systemctl daemon-reload
# 停止frpc
sudo systemctl restart frpc
# 添加到开机启动
sudo systemctl enable frpc
#查询状态
sudo systemctl status frpc

  • 14
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个使用Verilog语言实现FPGA FOC的示例代码: ``` module FOC(input clk, input rst, input [31:0] current_a, input [31:0] current_b, input [31:0] voltage_a, input [31:0] voltage_b, output reg [31:0] duty_a, output reg [31:0] duty_b); parameter KP = 100; // 比例常数 parameter KI = 10; // 积分常数 parameter KFF = 0; // 前馈常数 reg [31:0] theta; // 电机转子角度 reg [31:0] sin_theta; // 正弦值 reg [31:0] cos_theta; // 余弦值 reg [31:0] voltage_d; // d轴电压 reg [31:0] voltage_q; // q轴电压 reg [31:0] current_d; // d轴电流 reg [31:0] current_q; // q轴电流 reg [31:0] error_d; // d轴误差 reg [31:0] error_q; // q轴误差 reg [31:0] integral_d; // d轴积分项 reg [31:0] integral_q; // q轴积分项 reg [31:0] voltage_a_new; // 新的a轴电压 reg [31:0] voltage_b_new; // 新的b轴电压 always @(posedge clk) begin if (rst) begin theta <= 0; sin_theta <= 0; cos_theta <= 1; voltage_d <= 0; voltage_q <= 0; current_d <= 0; current_q <= 0; error_d <= 0; error_q <= 0; integral_d <= 0; integral_q <= 0; voltage_a_new <= 0; voltage_b_new <= 0; duty_a <= 0; duty_b <= 0; end else begin // 计算转子角度 theta <= theta + 100; // 计算sin和cos值 sin_theta <= sin(theta); cos_theta <= cos(theta); // 坐标变换 current_d <= current_a * cos_theta + current_b * sin_theta; current_q <= -current_a * sin_theta + current_b * cos_theta; // 计算d轴电压 error_d <= voltage_d - current_d; integral_d <= integral_d + error_d; voltage_d <= KP * error_d + KI * integral_d + KFF * current_d; // 计算q轴电压 error_q <= voltage_q - current_q; integral_q <= integral_q + error_q; voltage_q <= KP * error_q + KI * integral_q + KFF * current_q; // 逆坐标变换 voltage_a_new <= voltage_d * cos_theta - voltage_q * sin_theta; voltage_b_new <= voltage_d * sin_theta + voltage_q * cos_theta; // 更新PWM占空比 duty_a <= voltage_a_new / 100; duty_b <= voltage_b_new / 100; end end endmodule ``` 这个模块使用了PI控制器和前馈控制器来计算d轴和q轴电压,然后进行逆坐标变换得到新的a轴和b轴电压,最后将其转换为PWM占空比输出。在实际应用中,还需要根据具体的电机参数进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值