前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >树莓派配合云服务器实现内网穿透

树莓派配合云服务器实现内网穿透

原创
作者头像
dandelion1990
修改2024-02-06 16:53:03
1070
修改2024-02-06 16:53:03
举报

服务器准备

分配端口7000,作为bind port,分配端口6000,作为与树莓派ssh链接的端口。记得在云服务器中的安全组设置中给6000和7000端口开放出入的权限。

安装frp

服务器端

代码语言:shell
复制
# 下载与安装
wget https://github.com/fatedier/frp/releases/download/v0.24.1/frp_0.24.1_linux_amd64.tar.gz
tar -zxvf frp_0.24.1_linux_amd64.tar.gz

# 修改配置
[common]
bind_port = 7000
vhost_http_port = 8080

# 启动
./frps -c ./frps.ini

# 或者后台启动
nohup ./frps -c ./frps.ini

客户端

代码语言:shell
复制
# 下载与安装
wget https://github.com/fatedier/frp/releases/download/v0.24.1/frp_0.24.1_linux_arm.tar.gz
tar -zxvf frp_0.24.1_linux_arm.tar.gz

# 修改配置
[common]
server_addr = 服务器的公网ip
server_port = 7000
login_fail_exit = false

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

# 启动
./frpc -c ./frpc.ini

# 或者后台启动
nohup ./frpc -c ./frpc.ini

外网访问

代码语言:shell
复制
ssh -oPort=6000 pi@服务器的公网ip

使用 Systemd 实现自动启动 frp

代码语言:shell
复制
# 安装systemd
apt-get update
apt-get install systemd
apt-get install systemd-sysv
代码语言:shell
复制
# 复制文件
cp frpc /usr/local/bin/frpc
mkdir /etc/frp
cp frpc.ini /etc/frp/frpc.ini

# 编写 frp service 文件,以 centos7 为例,适用于 debian
mkdir /usr/lib/systemd/system
vim /usr/lib/systemd/system/frpc.service
# 内容如下
[Unit]
Description=frpc
After=network.target

[Service]
TimeoutStartSec=30
ExecStart=/usr/local/bin/frpc -c /etc/frp/frpc.ini
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target

# 树莓派要先修改root密码,才能启动服务
sudo passwd root

# 启动 frp 并设置开机启动
systemctl enable frpc
systemctl start frpc
systemctl status frpc

# 停止
systemctl stop frpc

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 服务器准备
  • 安装frp
  • 使用 Systemd 实现自动启动 frp
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档