我是靠谱客的博主 笨笨小海豚,最近开发中收集的这篇文章主要介绍frp内网穿透并实现开机自启动,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

本文中使用到的端口记得在阿里云服务器的安全组中开放该端口

在公网服务器(阿里云服务器)上执行下面的命令,安装frp

wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_arm64.tar.gz
-- 解压到/usr/local
cd /usr/local
tar -zxvf frp_0.38.0_linux_amd64.tar.gz
-- 开始编辑frps.ini
vi frps.ini
====>
[common]
bind_port = 5001
vhost_http_port = 3389
vhost_https_port = 3399
auto_token = ******  #这里是自己定义的密钥
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
    
-- 启动frps服务
./frps -c ./frps.ini
=====>后台启动
nohup ./frps -c ./frps.ini &
安装frp客户端  frpc
-- 编辑frpc.ini
vi frpc.ini
====>  每一行后面的空格记得注释都要去掉,否则可能会报错
[common]
server_addr = 公网ip   
server_port = 5001
auto_token = ******  #这里是自己定义的密钥,和上面的需保持一致
admin_addr = 0.0.0.0
admin_port = 7500
admin_user = admin
admin_pwd = admin
log_file = ./frpc.log
log_level = info
custom_domains = www.letitgo.club
[http-info]
type = http
local_ip = 内网服务器ip
local_port = 80
remote_port = 3389
custom_domains = http.letitgo.club
[https-info]
type = https
local_ip = 内网服务器ip
local_port = 8080
remote_port = 3399
custom_domains = https.letitgo.club
[ssh-info]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

实现frp的自启动,写一个frpc后台启动的脚本文件 start_frp.sh 在dell服务器(需要穿透的内网服务器),文件放在/home/boot_file目录下

#!/bin/bash
sudo nohup  /home/software/frp_0.38.0_linux_amd64/frpc -c  /home/software/frp_0.38.0_linux_amd64/frpc.ini &

在服务器的/etc/rc.d目录中的rc.local文件中添加下面的内容

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
chmod +x /etc/rc.d/rc.local
/home/boot_file/add_bridge.sh
#开机自启动frpc服务
chmod +x /home/boot_file/start_frp.sh
chmod +x /etc/rc.d/rc.local
su - root -c '/home/boot_file/start_frp.sh'

在具有公网ip的服务器中的/usr/local/boot_file目录下创建一个脚本start_frp.sh

sudo nohup /usr/local/frp_0.38.0_linux_amd64/frps -c /usr/local/frp_0.38.0_linux_amd64/frps.ini &

在服务器的/etc/rc.d目录中的rc.local文件中添加下面的内容

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
chmod +x /usr/local/boot_file/start_frp.sh
chmod +x /etc/rc.d/rc.local
su - root -c '/usr/local/boot_file/start_frp.sh'

尝试将dell服务器重启,重启完毕后,在随便一个shell远程工具中执行下面的操作,如果能够正确的ssh到内网服务器中,就说明自启动成功了

ssh userName@公网ip -p tcp连接方式的remote_port

欢迎访问博主的个人博客网站 金木研大数据之路

最后

以上就是笨笨小海豚为你收集整理的frp内网穿透并实现开机自启动的全部内容,希望文章能够帮你解决frp内网穿透并实现开机自启动所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部