frp记录

frp入门使用记录

简介: frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网

目前是因为没有公网ip 所以使用服务器的公网去映射

1. 安装

  • 下载
wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
  • 解压
tar -xvf frp_0.38.0_linux_amd64.tar.gz 
  • 移动至 /usr/local
mkdir /usr/local/frp
mv frp_0.38.0_linux_amd64/* /usr/local/frp/
  • 文件说明
frps.ini: 服务端配置文件
frps: 服务端软件
frpc.ini: 客户端配置文件
frpc: 客户端软件

2. 配置systemctl来控制,服务端运行

  • vim新建文件并写入配置内容
vim /usr/lib/systemd/system/frp.service
  • 写入以下内容,注意上文移动放置的路径和此处有关。这里是启动的服务端
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit

[Install]
WantedBy=multi-user.target
  • 重新加载服务的配置文件
systemctl daemon-reload
  • 现在就可以用 systemctl 套装来控制 frp 了。
  • 启动/停止/重启,查看状态,设置开机自启/关闭开机自启
systemctl start frp
systemctl stop frp
systemctl restart frp
systemctl status frp
systemctl enable frp
systemctl disable frp

3. 配置和使用

3.1 服务端

frps.ini

[common] #必须设置
bind_port = 7000 #是自己设定的frp服务端端口
vhost_http_port = 80 #是自己设定的http访问端口
token = 123  #核实身份用,加了更安全

[ssh] #ssh反向代理(不是必须设置)
listen_port = 6000 是自己设定的ssh访问端口

[web] #http反向代理[]里的内容可以自己设定,但是客户端和服务端必须要对应(如[aaa],[bbb]);
type = http #为服务类型,可以设为http,https
custom_domains = test1.a.com #为要映射的域名,记得域名的A记录要解析到外网主机的IP。

[web2] #同上(可设置多个)

示例

[common]
bind_port = 700
vhost_http_port = 9080

[ssh]
listen_port = 6000

[web]
type = http
custom_domains = onlylmf.cn
  • 启动
./frps -c ./frps.ini

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

# 因为我设置的端口是700 如果想关闭服务
netstat -auntp|grep 700
# 然后结束掉该进程 xxx是该pid
kill -9 xxxx

image-20220830142501385

至此服务端就已经启动成功了!

3.2 客户端

因为我使用的是win10

所以直接下载 cmd运行了

  • 下载
https://github.com/fatedier/frp/releases

选择自己操作系统对应的版本进行下载

image-20220902164451593

解压后 得到该目录

image-20220902164445625

frpc.ini

[common]
server_addr = 远程frp服务器ip
server_port = 远程frp服务器端口
token = 远程frp服务器token

[http]
type = http
local_ip = 127.0.0.1
local_port = 本地端口号
remote_port = 远程frp服务器的http服务端口号
custom_domains = 自定义配置的域名
subdomain = 匹配服务端配置的subdomain_host

示例

[common]
server_addr = 服务器公网ip
#绑定端口要和服务端配置的一样
server_port = 700 


[web]
type = http
local_ip = 192.168.3.46
local_port = 80
custom_domains = xxx.xxx.onlylmf.cn
#subdomain = zxy


[web2]
type = http
local_ip = 192.168.0.166
local_port = 11180
custom_domains = xxx.xxx.onlylmf.cn


[lapis]
type = http
local_ip = 127.0.0.1
local_port = 11180
custom_domains = xxx.xxx.onlylmf.cn

启动

./frpc -c ./frpc.ini

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

image-20220902164438544

4. Nginx 配置

  • 在域名网站 解析自定义域名后申请免费是ssl证书 下载crt和key放在服务器中

  • 配置nginx配置

    # 将访问80端口的网址 跳转到443 
    server{
                listen 80;
                server_name 需要跳转的网址;
                add_header  cettt $http_host; # 这里是自定义头
                rewrite ^(.*)$ https://$http_host$1 permanent;
        }
    
    server {
        	listen 443 ssl;
        	server_name 需要转发的域名;
        	
        	ssl_certificate 对应的ssl证书的crt.crt;
        	ssl_certificate_key 对应的ssl证书的key.key;
        
        	
        	ssl_session_timeout 30m;
        	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        	ssl_prefer_server_ciphers on;
            add_header  ffff $http_host; # 这里是自定义头
        	location / {
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass  http://127.0.0.1:8090/;
            }
        }
    

5. 配置连接家里的路由器

纯属是我自己的需要而已

因为我租的房子网络没有公网ip 用不了DDNS 所以使用frp进行内网穿透

因为买的一个阿里云的服务器没怎么用 就把服务端放在服务器上 使用服务器的公网ip

  1. 先在服务器上安装frps

步骤如前面的步骤

下载安装后 配置frps.ini

image-20220902164354435

我这边定义的 [web] 是我另外的穿透 现在使用的是 [Myrouter]

然后后台启动 服务端

  1. 在家里路由器上安装客户端

: 因为我刷了openwrt的固件 所以下载frpc客户端 以及luci可视化的管理页面

​ 可以在 软件包里搜索下载 frpc 、luci-app-frpc 、 语言包 luci-i18n0-frpc-zh-cn

​ 如果搜索不到 就先下载到本地 然后在通过文件传输到 路由上

image-20220902164348675

  • 装好后 如果服务里没有显示 Frp内网穿透 那么可能是缓存引起的

    登录路由器的ssh 把luci的缓存清空后 重启

    rm /tmp/luci-indexcache
    
    reboot
    
  • image-20220902164338759

    在如果 都安装完成了 但一直frp显示未启动 那么可能是被禁止了 去系统的启动项去 找到frp 启动

    image-20220902164334159

    然后不出意外的话应该就好了

  1. 进行全局和服务列表的配置

image-20220902164327921

保存后 配置服务列表

点击添加后

image-20220902175052975

至此就配置完成了

  1. 验证 在本地访问服务端的可视化界面查看

image-20220902164306837

当时在frps.ini中配置了 dashboard_port 就是访问端口 还要记得在服务器的防火墙将设置的端口开放

image-20220902164255269

  1. 设置 ssl 配置nginx 转发
  • 前提是申请 对应的自定义域名的证书 下载crt和key 放入服务器中

  • 配置nginx

    server {
        	listen 443 ssl;
        	server_name 需要跳转的域名;
        	
        	
        	ssl_certificate 申请的ssl的crt路径.crt;
        	ssl_certificate_key 申请的ssl的key路径.key;
        	
        	ssl_session_timeout 30m;
        	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        	ssl_prefer_server_ciphers on;
            add_header  ffff $http_host; # 这里是自定义头
        	location / {
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass  http://127.0.0.1:9080/;
          }
      }
    

    然后 访问自定义域名 则成功访问到转发网址

本处高能:因Frp作者更换新的模块,导致Frp v0.18.0与之前的版本不兼容,如果升级请服务器端同步升级。升级命令: wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh bash install-frps.sh update 首先感谢@sadoneli S大的帮助完成了frp插件web页面的制作。 WARNING:请仔细阅读完本教程1楼和2楼后再动手安装! frp 是一个高性能的反向代理应用,可以帮助您轻松地进行内网穿透,对外网提供服务,支持 tcp, http, https 等协议类型,并且 web 服务支持根据域名进行路由转发。 *因为frp是go语言写的,所以在路由器上使用的时候,请使用虚拟内存,请使用虚拟内存,请使用虚拟内存。 脚本是业余爱好,英文属于文盲,写的不好,欢迎您批评指正。 安装平台:CentOS、Debian、Ubuntu。 已测试过的平台: CentOS 6 32/64bit CentOS 7 32/64bit Debian 6 32/64bit Debian 7 32/64bit Debian 8 32/64bit Ubuntu 14 32/64bit 一、安装命令这个命令是在你自己的服务器上运行的!是在你自己的服务器上运行的!是在你自己的服务器上运行的!不是在路由器里运行的!不是在路由器里运行的!不是在路由器里运行的! wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh chmod 700 ./install-frps.sh ./install-frps.sh install 二、安装步骤 Loading network version for frps, please wait... frps Latest release file frp_0.8.1_linux_amd64.tar.gz #此步骤会自动获取frp最新版本,自动操作,无需理会 Loading You Server IP, please wait... You Server IP:12.12.12.12 #自动获取你服务器的IP地址 Please input your server setting: Please input frps bind_port [1-65535](Default Server Port: 5443): #输入frp提供服务的端口,用于服务器端和客户端通信 Please input frps dashboard_port [1-65535](Default dashboard_port: 6443): #输入frp的控制台服务端口,用于查看frp工作状态 Please input frps vhost_http_port [1-65535](Default vhost_http_port: 80): #输入frp进行http穿透的http服务端口 Please input frps vhost_https_port [1-65535](Default vhost_https_port: 443): #输入frp进行https穿透的https服务端口 Please input privilege_token (Default: WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq): #输入frp服务器和客户端通信的密码,默认是随机生成的 Please input frps max_pool_count [1-200](Default max_pool_count: 50): #设置每个代理可以创建的连接池上限,默认50 ##### Please select log_level ##### 1: info 2: warn 3: error 4: debug ##################################################### Enter your choice (1, 2, 3, 4 or exit. default [1]): #设置日志等级,4个选项,默认是info Please input frps log_max_days [1-30] (Default log_max_days: 3 day): #设置日志保留天数,范围是1到30天,默认保留3天。 ##### Please select log_file ##### 1: enable 2: disable ##################################################### Enter your choice (1, 2 or exit. default [1]): #设置是否开启日志记录,默认开启,开启后日志等级及保留天数生效,否则等级和保留天数无效 设置完成后检查你的输入,如果没有问题按任意键继续安装 ============== Check your input ============== You Server IP : 12.12.12.12 Bind port : 5443 Dashboard port : 6443 vhost http port : 80 vhost https port: 443 Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq Max Pool count : 50 Log level : info Log max days : 3 Log file : enable ============================================== 安装结束后显示: Congratulations, frps install completed! ============================================== You Server IP : 12.12.12.12 Bind port : 5443 Dashboard port : 6443 vhost http port : 80 vhost https port: 443 Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq Max Pool count : 50 Log level : info Log max days : 3 Log file : enable # 将上面信息添加到你的路由器frp穿透插件中吧 ============================================== frps Dashboard: http://12.12.12.12:6443/ # 这个是frp控制台访问地址 ============================================== 三、更新命令 ./install-frps.sh update 四、卸载命令 ./install-frps.sh uninstall 五、服务器端管理命令 /etc/init.d/frps start /etc/init.d/frps stop /etc/init.d/frps restart /etc/init.d/frps status /etc/init.d/frps config /etc/init.d/frps version 七、更多帮助请移步官方帮助文件 https://github.com/fatedier/frp/blob/master/README_zh.md
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值