贴出我自己的环境:centos7 64
git,go,ngrok打包下载:
链接:http://pan.baidu.com/s/1c2tbOEc 密码:dqv5
go全部版本下载地址:http://www.golangtc.com/download
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++
卸载其他的git:
yum -y remove git*
cd /usr/local
下载git:
wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
tar zxvf git-2.6.0.tar.gz
cd git-2.6.0
./configure --prefix=/usr/local/git
make
make install
ln -s /usr/local/git/bin/* /usr/bin/
准备go环境,我的系统是64位的centos所以我下载amd64的包
cd /usr/local
wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-amd64.tar.gz
tar -zxvf go1.4.2.linux-amd64.tar.gz
ln -s /usr/local/go/bin/* /usr/bin/
注:这里把ip地址换成自己的;
git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="ngrok.baidu.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
y
确认即可)cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
vi /usr/local/ngrok/src/ngrok/log/logger.go
log "github.com/keepeye/log4go"
cd /usr/local/go/src
GOOS=linux GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server
注:编译后的客户端在/usr/local/ngrok/bin
下:
linux 64位操作系统使用下面的命令:
cd /usr/local/go/src
GOOS=linux GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-client
mac os 64位操作系统使用下面的命令:
cd /usr/local/go/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=darwin GOARCH=amd64 make release-client
Windows64位操作系统使用下面的命令:
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client
ngrok.cfg
注:这里把ip地址换成自己的;
新建一个ngrok.cfg
配置的文件放在客户端同一目录,内容如下:
server_addr: "ngrok.baidu.com:4443"
trust_host_root_certs: false
/usr/local/ngrok/bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":80"
如果重启过服务器,请用下面的命令再次启动ngrok服务端:
/usr/local/ngrok/bin/ngrokd -domain="ngrok.baidu.com" -httpAddr=":80"
linux客户端启动命令:
./ngrok -config=./ngrok.cfg -subdomain=blog 80
windowns客户端启动命令:
ngrok -config=./ngrok.cfg -subdomain=blog 80
如果想在linux的后台运行:
setsid ./ngrok -config=./ngrok.cfg -subdomain=test 80
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=4443/tcp --permanent
firewall-cmd --reload
到这里整个ngrok就搭建成功了,如果有什么问题或建议欢迎给我留言,么么哒!
结语:搭建属于自己的ngrok服务器,实现内网穿透,外网访问内网,可本地开发微信不需要上传服务器
出现下面这个错误说明需要安装hg:
package code.google.com/p/log4go: exec: "hg": executable file not found in $PATH
解决办法:
yum install hg -y
编译到 go get gopkg.in/yaml.v1 的时候卡住不走了,说明是git比较低,版本需要大于1.7.9.5以上
fatal: Unable to find remote helper for 'https'
出现这个问题,可以重新安装 curl curl-devel
然后再重装git
安装git-core
wget https://www.kernel.org/pub/software/scm/git/git-core-0.99.6.tar.gz
tar zxvf git-core-0.99.6.tar.gz
cd git-core-0.99.6
make prefix=/usr/libexec/git-core install
export PATH=$PATH:/usr/libexec/git-core/
感谢:http://www.sunnyos.com/article-show-48.html提供资料和思路