由于某些内部网络的站点需要外部调用或者访问,则需要一个外网能够访问内网的方法,而内网穿透就是这个方法之一。
1、一个外网能够访问的服务器,比如阿里云、腾讯云、华为云等服务器
2、一个与该服务器备案的域名
3、有一些linux配置基础
1、远程连接工具:可以使用windows自带的ssh,也可以有FinalShell,本次分享使用FinalShell
1、go环境,下载地址http://www.golangtc.com/download
2、git环境,下载地址Git - Downloads
1、下载ngrok源码,GitHub - inconshreveable/ngrok: Introspected tunnels to localhost
2、安装编译时候的依赖环境
yum -y install zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker hg wget gcc gcc-c++
#下载
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.18.5.tar.gz
#解压
tar zxvf git-2.18.5.tar.gz
#编译
cd git-2.18.5
./configure --prefix=/usr/local/git make
make install
#设置环境变量
vim /etc/profile
export GIT_HOME=/usr/local/git
export PATH=$GIT_HOME/bin:$PATH
source /etc/profile
#也可以使用
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
source /etc/profile
#下载
wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-386.tar.gz
#解压
tar -zxvf go1.4.2.linux-386.tar.gz mv go /usr/local/
#设置环境变量
vim /etc/profile
#设置goroot的环境变量 此环境变量指的是go的根目录
export GOROOT=/usr/local/go
#设置go的环境变量
export PATH=$PATH:/usr/local/go/bin
PATH=$PATH:$HOME/bin
export PATH
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
//替换码云 https://gitee.com/feiy/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="xx.xx.com"
cd ngrok
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
vim /usr/local/ngrok/src/ngrok/log/logger.go log "github.com/keepeye/log4go"
cd /usr/local/go/src
GOOS=linux GOARCH=386 ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=386 make release-server
cd /usr/local/go/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=darwin GOARCH=amd64 make release-client
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client
server_addr: "xx.xx.com:4443" trust_host_root_certs: false
/usr/local/ngrok/bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":80"
./ngrok -config=./ngrok.cfg -subdomain=blog 80 setsid ./ngrok -config=./ngrok.cfg -subdomain=test 80