Skip to content

Commit 61fe5e3

Browse files
committed
no message
1 parent 15af7f2 commit 61fe5e3

1 file changed

Lines changed: 176 additions & 2 deletions

File tree

‎notes/archives/手把手教你,搭建内网穿透服务.md‎

Lines changed: 176 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
<!-- TOC -->
2+
3+
- [手把手教你,搭建内网穿透服务](#手把手教你搭建内网穿透服务)
4+
- [一、概述](#一概述)
5+
- [1.1 什么是内网穿透](#11-什么是内网穿透)
6+
- [1.2 什么是 lanproxy](#12-什么是-lanproxy)
7+
- [1.3 原理](#13-原理)
8+
- [二、快速开始](#二快速开始)
9+
- [2.1 硬件与环境要求](#21-硬件与环境要求)
10+
- [2.2 公网服务器配置(Docker 一键启动)](#22-公网服务器配置docker-一键启动)
11+
- [基础环境安装](#基础环境安装)
12+
- [通过 Docker,启动 lanproxy 服务](#通过-docker启动-lanproxy-服务)
13+
- [Nginx 反向代理配置域名](#nginx-反向代理配置域名)
14+
- [继续配置 lanproxy 后台服务](#继续配置-lanproxy-后台服务)
15+
- [2.3 内网电脑配置(Java 客户端)](#23-内网电脑配置java-客户端)
16+
- [Java 1.8 安装](#java-18-安装)
17+
- [maven 安装](#maven-安装)
18+
- [启动内网服务](#启动内网服务)
19+
- [运行 lanproxy client 服务](#运行-lanproxy-client-服务)
20+
- [lanproxy 网页后台服务](#lanproxy-网页后台服务)
21+
- [2.4 内网电脑配置(GO 客户端)](#24-内网电脑配置go-客户端)
22+
- [安装Go环境安装](#安装go环境安装)
23+
- [拉取 ffay/lanproxy-go-client 代码](#拉取-ffaylanproxy-go-client-代码)
24+
- [安装客户端依赖包](#安装客户端依赖包)
25+
- [启动客户端](#启动客户端)
26+
- [三、总结](#三总结)
27+
- [参考资料](#参考资料)
28+
29+
<!-- /TOC -->
30+
131
# 手把手教你,搭建内网穿透服务
232

333
在很多场景下内网穿透都是我们常常遇到的需求,之前也用过花生壳、ngrok、FRP 等等一些工具,但是由于限速、收费、安全各方面因素只好放弃了。
@@ -54,6 +84,8 @@ lanproxy 是一个将局域网个人电脑、服务器代理到公网的内网
5484
## 二、快速开始
5585

5686
> 这里我将手把手带你配置 lanproxy 穿透服务,这里配置主要分成了 **公网服务器配置** 和 **内网电脑配置** 。
87+
>
88+
> 在内网电脑配置中分为:Java 客户端和 GO 客户端
5789
5890
### 2.1 硬件与环境要求
5991

@@ -71,7 +103,7 @@ lanproxy 是一个将局域网个人电脑、服务器代理到公网的内网
71103

72104

73105

74-
### 2.2 公网服务器配置
106+
### 2.2 公网服务器配置(Docker 一键启动)
75107

76108
#### 基础环境安装
77109

@@ -232,7 +264,7 @@ $ service nginx restart
232264

233265

234266

235-
### 2.3 内网电脑配置
267+
### 2.3 内网电脑配置(Java 客户端)
236268

237269
> 这里我的内网是一台 Ubuntu 16.04 的服务器,以下我都将以此为例
238270
@@ -486,6 +518,148 @@ $ bash bin/stop.sh
486518

487519

488520

521+
### 2.4 内网电脑配置(GO 客户端)
522+
523+
GitHub 客户端主页:[lanproxy-go-client](https://github.com/ffay/lanproxy-go-client)
524+
525+
不想安装 Java 环境的可以选择 Go
526+
527+
#### 安装Go环境安装
528+
529+
**1. buntu、Debian或Linux Mint安装Go语言**
530+
531+
基于 Debian的 Linux 发行版本都可以使用 apt-get 命令来进行安装:
532+
533+
```shell
534+
sudo apt-get install golang
535+
```
536+
537+
要查看当前系统安装的 Go 语言版本可以使用如下命令:
538+
539+
```shell
540+
go version
541+
```
542+
543+
由于 Go 代码必需保存在 workspace(工作区)中,所以我们必需在 **Home** 目录(例如 ~/workspace)创建一个**workspace** 目录并定义 **GOPATH** 环境变量指向该目录,这个目录将被 Go 工具用于保存和编辑二进制文件。
544+
545+
```shell
546+
mkdir ~/workspace
547+
echo 'export GOPATH="$HOME/workspace"' >> ~/.bashrc
548+
source ~/.bashrc
549+
```
550+
551+
根据不同的需要,我们可以使用 apt-get 安装 Go tools:
552+
553+
```shell
554+
sudo apt-cache search golang
555+
```
556+
557+
558+
559+
**2. Fedora、CentOS或RHEL安装Go语言**
560+
561+
基于 Red Hat 的 Linux 发行版本都可以使用 yum 命令来进行安装:
562+
563+
```shell
564+
sudo yum install golang
565+
```
566+
567+
要查看当前系统安装的 Go 语言版本可以使用如下命令:
568+
569+
```shell
570+
go version
571+
```
572+
573+
接下来还是在 Home 目录(例如 ~/workspace)创建一个 workspace 目录并定义 GOPATH 环境变量指向该目录,这个目录将被 Go 工具用于保存和编辑二进制文件。
574+
575+
```shell
576+
mkdir ~/workspace
577+
echo 'export GOPATH="$HOME/workspace"' >> ~/.bashrc
578+
source ~/.bashrc
579+
```
580+
581+
根据不同的需要,我们可以使用 yum 安装 Go tools:
582+
583+
```shell
584+
yum search golang
585+
```
586+
587+
588+
589+
参考资料:[如何为Linux安装Go语言 - Go语言中文网 - Golang中文社区](https://studygolang.com/articles/7482)
590+
591+
592+
593+
#### 拉取 ffay/lanproxy-go-client 代码
594+
595+
```shell
596+
git clone https://github.com/ffay/lanproxy-go-client.git
597+
```
598+
599+
600+
601+
#### 安装客户端依赖包
602+
603+
```shell
604+
cd lanproxy-go-client
605+
sh build-release.sh
606+
```
607+
608+
安装后,这时候在目录下会出现文件。
609+
610+
611+
612+
#### 启动客户端
613+
614+
**普通端口连接**
615+
616+
```shell
617+
# mac 64位
618+
nohup ./client_darwin_amd64 -s SERVER_IP -p SERVER_PORT -k CLIENT_KEY &
619+
620+
# linux 64位
621+
nohup ./client_linux_amd64 -s SERVER_IP -p SERVER_PORT -k CLIENT_KEY &
622+
623+
# windows 64 位
624+
./client_windows_amd64.exe -s SERVER_IP -p SERVER_PORT -k CLIENT_KEY
625+
```
626+
627+
628+
629+
**SSL端口连接**
630+
631+
```shell
632+
# mac 64位
633+
nohup ./client_darwin_amd64 -s SERVER_IP -p SERVER_SSL_PORT -k CLIENT_KEY -ssl true &
634+
635+
# linux 64位
636+
nohup ./client_linux_amd64 -s SERVER_IP -p SERVER_SSL_PORT -k CLIENT_KEY -ssl true &
637+
638+
# windows 64 位
639+
./client_windows_amd64.exe -s SERVER_IP -p SERVER_SSL_PORT -k CLIENT_KEY -ssl true
640+
```
641+
642+
例如:
643+
644+
```
645+
nohup ./client_linux_amd64 -s lp.thingsglobal.org -p 4900 -k 01c1e176d6ee466c8db717a8 &
646+
```
647+
648+
命令参数:
649+
650+
```shell
651+
GLOBAL OPTIONS:
652+
-k value client key
653+
-s value proxy server host
654+
-p value proxy server port (default: 4900)
655+
--ssl value enable ssl (default: "false", -p value should be server ssl port)
656+
--cer value ssl cert path, default skip verify certificate
657+
--help, -h show help
658+
--version, -v print the version
659+
```
660+
661+
662+
489663
## 三、总结
490664

491665
通过以上的配置,只要有一台公网电脑,即可实现内网穿透功能。摆脱花生壳的域名端口限制,流量限制,带宽限制。笔者的公网服务器为 6M 带宽,通过公网映射,文件下载测试大概在 800K/s - 1.5M/s 范围,如果仅是普通的网站服务完全可以完美穿透。

0 commit comments

Comments
 (0)