wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz --no-check-certificate
tar zxvf go1.8.3.linux-amd64.tar.gz
mv go /usr/local/
2、添加环境变量
vim /etc/profile
添加如下内容:
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
使配置生效
source /etc/profile
go version 查看go是否安装成功
yum –y install git
在服务器中dns解析中配置二级域名的解析,需要在域名管理里面设置二级域名的解析
server {
listen 80;
server_name ngrok.abc.cn;
access_log logs/ngrok.log;
error_log logs/ngrok.error;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8001;
}
配置好nginx以后,重新nginx
./nginx -s reload
https://github.com/Yaoshicn/make-ngrok
先看下make-ngrok.sh脚本内容如下:
#!/bin/bash
domain=$1
root="`pwd`/ngrok"
certificate_dir="$root/certificate"
release_dir="$root/../release"
RED='\033[0;31m'
NC='\033[0m'
if ["$1" = ""]; then
printf "Usage: ./make-ngrok.sh [YOUR DOMAIN]\n"
exit
fi
printf "Domain:$domain\n"
printf "${RED}Git clone...${NC}\n"
git clone https://github.com/inconshreveable/ngrok && cd $root
printf "${RED}Done${NC}\n"
printf "${RED}Install go-bindata...${NC}\n"
go get github.com/jteeuwen/go-bindata
[ -d $root/bin ] || mkdir $root/bin && cp $GOPATH/bin/go-bindata $root/bin
printf "${RED}Done${NC}\n"
[ -d $certificate_dir ] || mkdir $certificate_dir && cd $certificate_dir
printf "${RED}Generate self-sign certificate...${NC}\n"
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$domain" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=$domain" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
printf "${RED}Done${NC}\n"
printf "${RED}Copy certificates and key to target folders...${NC}\n"
cd $certificate_dir
cp rootCA.pem ../assets/client/tls/ngrokroot.crt
cp device.crt ../assets/server/tls/snakeoil.crt
cp device.key ../assets/server/tls/snakeoil.key
printf "${RED}Done${NC}\n"
# make
printf "${RED}Make release server and client...${NC}\n"
cd $root
make release-server release-client
printf "${RED}Done${NC}\n"
printf "${RED}Make client for other platforms...${NC}\n"
# Linux 32
unset GOBIN && GOOS="linux" GOARCH="386" make release-client
# Linux 64
unset GOBIN && GOOS="linux" GOARCH="amd64" make release-client
# ARM
unset GOBIN && GOOS="linux" GOARCH="arm" make release-client
# Windows 32
unset GOBIN && GOOS="windows" GOARCH="386" make release-client
# Windows 64
unset GOBIN && GOOS="windows" GOARCH="amd64" make release-client
# Mac 32
unset GOBIN && GOOS="darwin" GOARCH="386" make release-client
# Mac 64
unset GOBIN && GOOS="darwin" GOARCH="amd64" make release-client
printf "${RED}Done${NC}\n"
rm -rf $release_dir
[ -d $release_dir ] || mkdir $release_dir
cp -r $root/bin/* $release_dir
cd /usr/local
mkdir ngrok
cd mgrok
git clone https://github.com/Yaoshicn/make-ngrok.git
cp /usr/local/ngrok/make-ngrok/make-ngrok.sh make-ngrok.sh
pwd
/usr/local/ngrok/
ll
make-ngrok.sh
然后执行:
./make-ngrok.sh [YOUR DOMAIN] 比如:ngrok.abc.com
等待安装,安装完成后,在ngrok目录下会多出两个文件夹: release跟ngrok文件夹
点开release
cd release
ll
可以看到已经编译好的ngrokd
此时,已经成功,剩下就是启动ngrok,
编写一个启动脚本:
vi startNgrok.sh
#!/bin/bash
nohup /usr/local/ngrok/release/ngrokd -domain="ngrok.abc.cn" -log="/usr/local/ngrok/release/ngrok.log" -httpAddr=":8001" &
tail -f /usr/local/ngrok/release/ngrok.log
保存startNgrok.sh文件
chmod +x startNgrok.sh
./startNgrok.sh
此时能看到启动日志文件,表示已经安装成功了
你需要把域名解析到刚才的www.abc.com对应的服务器的ip地址上,添加一条
类似这个,需要在域名管理里面设置二级域名的解析
,
主机记录为你本地需要被别人访问的域名前缀,比如:www
记录值是上面ngrok服务端的ip地址
,然后本地启动客户端,客户端为服务器/usr/local/ngrok/release目录下对应的各种操作系统对应的版本,如果为windows x64位的操作系统就下载 windows_amd64目录下的ngrok.exe可执行程序,保存到本地的一个文件夹中,创建ngrok.cfg文件,复制下面两行配置
server_addr: ngrok.abc.cn:4443
trust_host_root_certs: false
ngrok.abc.cn 为你ngrok服务端分配的二级域名,保存
编写启动文件 start.bat
@echo OFF
color 0a
Title ngrok启动工具
Mode con cols=109 lines=30
:START
echo
:TUNNEL
ngrok -config=ngrok.cfg -hostname www.abc.com 80
PAUSE
goto TUNNEL
www.abc.com 为ngrok客户端配置的域名,
保存以后,启动就可以看到启动画面了.
显示online表示成功了.
最后一点,服务端的域名注册商要跟客户端的域名注册商是同一个服务商,比如阿里注册的域名,客户端的域名也要是阿里云,如果不为阿里云的话,就会让接入备案,建议可以用cc域名,现在不用备案,阿里云跟腾讯云通用.
教程到此结束.