下载编译好的客户端/服务端
(2017年07月18日 更新)
发现自己编译的客户端跑在mac Sierra系统出现问题,暂时没有解决,这里下载编译好的客户端/服务端文件
http://www.ittun.com/apply.html
服务端启动命令
例子:
./ngrokd -domain="ngrok.xxx.com" -httpAddr=":8080" -httpsAddr=":8087" -tunnelAddr=":4443"
后台一直执行:
nohup bin/ngrokd -domain="ngrok.xxx.com" -httpAddr=":8080" -httpsAddr=":8087" -tunnelAddr=":44443" &
客户端配置
客户端配置过程不变
自己编译客户端
安装git、golang
安装git
安装依赖工具:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
yum remove git
cd /usr/src
wget -c wget -c https://github.com/git/git/archive/v2.13.3.tar.gz git-v2.13.3.tar.gz
tar xzf git-v2.13.3.tar.gz
cd git-2.13.3
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc
查看版本
[root@iZ2ze147skj2icrqqx7nhzZ ~]# git --version
git version 2.13.3
安装golang
查看版本:
# go version
go version go1.6.3 linux/amd64
go env 查看环境变量:
[root@iZ2ze147skj2icrqqx7nhzZ ~]# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
配置ngrok
1). clone到本地
git clone https://github.com/inconshreveable/ngrok.git ~/ngrok
2). 配置环境变量
export NGROK_DOMAIN="tunnel.mydomain.com"
tunnel.mydomain.com替换成你自己的域名。
4). 生成自签名ssl证书
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 device.key 2048
openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp device.crt assets/server/tls/snakeoil.crt
cp device.key assets/server/tls/snakeoil.key
编译服务端
路径以实际安装路径为准
从go env
可以看到我的GOROOT GOROOT="/usr/lib/golang"
cd /usr/lib/golang/src
GOOS=linux GOARCH=amd64 ./make.bash #(64位)
cd ~/ngrok/
GOOS=linux GOARCH=386 make release-server #(32 )
GOOS=linux GOARCH=amd64 make release-server #(64位)
结果会在ngork/bin
下生成ngrokd
文件。 还有一个go-bindata
文件。
编译客户端
要生成对应平台的客户端程序,需要继续进行交叉编译。
路径以实际安装路径为准
Linux
#如果是32位系统把amd64改成386
cd /usr/lib/golang/src
GOOS=linux GOARCH=amd64 ./make.bash #(64位)
cd ~/ngrok/
GOOS=linux GOARCH=amd64 make release-client #(64位) 生成`linux_386`文件
macOS
# MAC OS 64位操作系统(32位系统把amd64改成386)
cd /usr/lib/golang/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd ~/ngrok/
GOOS=darwin GOARCH=amd64 make release-client #(64位) 生成`darwin_amd64`文件
windows
# Windows 64位操作系统(32位系统把amd64改成386)
cd /usr/lib/golang/src
GOOS=windows GOARCH=amd64 ./make.bash
cd ~/ngrok/
GOOS=windows GOARCH=amd64 make release-client
运行
启动服务端
cd ~/ngrok/bin
#以8080端口为例
#请将`tunnel.mydomain.com`替换成自己的域名
./ngrokd -domain="tunnel.mydomain.com" -httpAddr=":8080"
#完整的参数
./ngrokd -domain="tunnel.mydomain.com" -httpAddr=":8080" -httpsAddr=":443" -tunnelAddr=":4443"
./ngrokd -domain="tunnel.tyrad.cc" -httpAddr=":8080" -httpsAddr=":8087"
访问: https://tunnel.mydomain.com:8080
,如果发现Tunnel tunnel.mydomain.com not found
说明启动成功
后台一直执行:
nohup bin/ngrokd -domain="tunnel.mydomain.com" -httpAddr=":8080" &
nohup ./ngrokd -domain="tunnel.tyrad.cc" -httpAddr=":8080" -httpsAddr=":8087" &
杀死:
ps -A #找到ngrokd的PID
kill xxx
启动客户端
下载客户端,以macOS为例,需要下载~/ngork/bin/darwin_amd64/ngrok
文件。
修改ngrok
文件的权限:
创建文件ngrok.cfg
,并编辑内容为(tunnel.mydomain.com替换成自己的域名):
server_addr: "tunnel.mydomain.com:4443"
trust_host_root_certs: false
并将ngrok
和ngrok.cfg
放到同一个文件夹下。
启动(xx是随便输入,相当于三级域名了):
./ngrok -config=ngrok.cfg -subdomain xxx 80
可以看到启动成功:
错误分析
编译报错:
执行GOOS=linux GOARCH=amd64 ./make.bash
之类的操作报错:
[root@iZ2ze147skj2icrqqx7nhzZ src]# GOOS=darwin GOARCH=amd64 ./make.bash
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /root/go1.4/bin/_/go.
ERROR: or /root/go1.4/bin/_/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
原因:
https://github.com/northbright/Notes/blob/master/Golang/china/install-go1.6-from-source-on-centos7-in-china.md
Go1.5+的编译过程需要Go1.4的二进来实现 bootstrap(自举)(简单来说: Go需要Go自身来编译)。
解决方法:
#clone到家目录
git clone https://github.com/golang/go.git ~/go1.4
#切换分支
git checkout -b 1.4.3 go1.4.3
cd src
./all.bash
操作完成,再重新尝试。
可能与服务器80、443端口冲突的问题
可以使用其他端口:
./ngrokd -domain="tunnel.tyrad.cc" -httpAddr=":8080" -httpsAddr=":8087"
几处参考
- 可以采用docker https://fengqi.me/unix/409.html
隔一段时间自动断连接?
服务端报错:
[16:09:32 CST 2017/07/17] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [ctl:61724a1d] [fe081219c8315a1d536d2b7ec5d6f463] Lost heartbeat
[16:09:32 CST 2017/07/17] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry] [ctl] Removed control registry id fe081219c8315a1d536d2b7ec5d6f463
[16:09:32 CST 2017/07/17] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [ctl:61724a1d] [fe081219c8315a1d536d2b7ec5d6f463] Closing
[16:09:32 CST 2017/07/17] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [http://aaabc.tunnel.tyrad.cc] Shutting down
[16:09:32 CST 2017/07/17] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [https://aaabc.tunnel.tyrad.cc] Shutting down
[16:09:32 CST 2017/07/17] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [pxy:4db711a4] [fe081219c8315a1d536d2b7ec5d6f463] Closing
[16:09:32 CST 2017/07/17] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [ctl:61724a1d] [fe081219c8315a1d536d2b7ec5d6f463] Shutdown complete
[16:09:32 CST 2017/07/17] [WARN] (ngrok/log.(*PrefixLogger).Warn:87) [ctl:61724a1d] [fe081219c8315a1d536d2b7ec5d6f463] Control::reader failed with error read tcp 172.17.71.179:4443->58.56.94.34:53190: use of closed network connection: goroutine 47 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
/usr/lib/golang/src/runtime/debug/stack.go:24 +0x80
ngrok/server.(*Control).reader.func1(0xc8202fa1b0)
/root/ngrok/src/ngrok/server/control.go:229 +0x53
panic(0x829580, 0xc82045c9b0)
/usr/lib/golang/src/runtime/panic.go:443 +0x4e9
ngrok/server.(*Control).reader(0xc8202fa1b0)
/root/ngrok/src/ngrok/server/control.go:246 +0x1cb
created by ngrok/server.NewControl
/root/ngrok/src/ngrok/server/control.go:124 +0x98a
暂时没有解决 (⊙﹏⊙)b
参考
https://git-scm.com/book/zh/v1/起步-安装-Git
https://git-scm.com/download/linux
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.1.md
https://github.com/northbright/Notes/blob/master/Golang/china/install-go1.6-from-source-on-centos7-in-china.md
http://www.jianshu.com/p/b254547b9fe5
问题:
- 微信的80端口和apache的冲突
- apache 443端口冲突,必须要关闭apache?