天天看点

编译ngrok的Windows、Mac的客户端

    ngrok是一个ddns服务,为内网机器绑定一个公网域名,方便开发调试远程接口(如微信开发)。

之前博文里面写过如何安装ngrok,但是由于公司里面的研发工程师的笔记本有windows本和mac本,所以本次主要讲怎么生成windows、mac客户端。

    准备工作:需要参考http://nanchunle.blog.51cto.com/9244770/1710295,安装完成ngrok

一、编译Windwos客户端

cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash
cd /usr/local/ngrok
GOOS=windows GOARCH=amd64 make release-client
#同理,这里的amd64是64位系统,32位改成386
#应该会在 bin/windows_amd64 目录下生成ngrok客户端程序
      
编译ngrok的Windows、Mac的客户端

到这里,编译就完成了,就可以将ngrok.exe下载到windows操作系统。

启动步骤:

1、将ngrok.exe放在D:\ngrok,并且在D:\ngrok编辑配置文件ngrok.cfg

server_addr: "example.com:4443"

trust_host_root_certs: false

2.打开windows控制台win+r ,进入D:\ngrok,执行

./ngrok -config=ngrok.cfg -log=ngrok.log -subdomain=test 8080

二、编译Mac客户端

cd /usr/local/go/src

GOOS=darwin GOARCH=amd64 ./make.bash

然后回去ngrok目录,接着编译:

cd /usr/local/src/ngrok

GOOS=darwin GOARCH=amd64 make release-client

完成后会在 /usr/local/src/ngrok/bin/darwin_amd64/ 下发现 ngrok 文件,将其拷贝到Mac上面,像上面windows

的设置即可使用。

三、注意事项

1、Centos/Linux下源码安装golang:

  1. wget https:

    //storage

    .googleapis.com

    /golang/go1

    .4.1.linux-amd64.

    tar

    .gz

  2. tar

    -C 

    /usr/local

    -xzf go1.4.1.linux-amd64.

    tar

    .gz

  3. mkdir

    $HOME

    /go

  4. echo

    'export GOROOT=/usr/local/go'

    >> ~/.bashrc

  5. echo

    'export GOPATH=$HOME/go'

    >> ~/.bashrc

  6. echo

    'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin'

    >> ~/.bashrc

  7. source

    $HOME/.bashrc

2、在步骤GOOS=darwin GOARCH=amd64 make release-client出现错误

imports runtime: C source files not allowed when not using cgo or SWIG: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_darwin.c mfixalloc.c mgc0.c mheap.c msize.c os_darwin.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c

make: *** [deps] Error 1

解决方法:参考网站 http://stackoverflow.com/questions/27772831/golang-c-source-files-not-allowed-when-not-using-cgo   

https://github.com/golang/go/wiki/InstallFromSource#introduction

Introduction

This is a companion to http://golang.org/doc/install/source providing additional instructions for various operating systems.

Install C tools

On OS X, a C compiler is bundled in the command line tools for Xcode, and you don't need to install the whole Xcode to compile Go. If you have already installed Xcode 4.3+, you can install command line tools from the Components tab of the Downloads preferences panel. In more recent versions of Xcode, you can use 

xcode-select --install

 command to install the command line tools without opening Xcode. To verify you have a working compiler, just invoke 

gcc

 in a freshly created Terminal window, unless you see the 

"gcc: command not found"

 error, you are ready to go.

On Ubuntu/Debian, use 

sudo apt-get install gcc libc6-dev

. If you want to build 32-bit binaries on a 64-bit system you'll also need the 

libc6-dev-i386

 package.

On RedHat/Centos 6, use 

sudo yum install gcc glibc-devel

. If you want to build 32-bit binaries on a 64-bit system you'll need both 

glibc-devel.i386

 and 

glibc-devel.x86_64

 packages.

继续阅读