go安装 (下载地址http://www.golangtc.com/download)
wget http://www.golangtc.com/static/go/go1.6beta1/go1.6beta1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.6beta1.linux-amd64.tar.gz
cat >>/etc/profile<<EOF
export PATH=$PATH:/usr/local/go/bin
EOF
source /etc/profile
#检查下是否成功
go version
#在当前用户目录下新建go目录作为项目目录
mkdir -p $HOME/go
#用cat的方法在尾部增加配置配置golang的 GOROOT GOPATH
cat >>$HOME/.bash_profile<<EOF
export GOROOT=/usr/local/go
export GOPATH=\$HOME/go
export PATH=\$PATH:\$GOROOT/bin
EOF
#让配置生效
source $HOME/.bash_profile
#检查下go的env环境变量
go env
安装最新版git
wget https://www.kernel.org/pub/software/scm/git/git-2.7.0.tar.gz (https://www.kernel.org/pub/software/scm/git/)
tar -zxvf git-2.7.0.tar.gz
cd git-2.7.0
make configure
./configure --prefix=/usr/local/git --with-iconv=/usr/local/lib(如果没有安装libiconv请自行安装)
make && make install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc
git --version
安装ngrok
yum -y install mercurial bzr subversion
git clone https://github.com/inconshreveable/ngrok.git
cd ngrok
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=tunnel.taoerqu.com" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=tunnel.taoerqu.com" -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
GOOS=linux GOARCH=amd64 #如果是32位系统,这里 GOARCH=386
vi src/ngrok/log/logger.go
看到里面有一个import中引用了google code,将其改为:"github.com/keepeye/log4go",PS :国内的服务器才需要怎么做
make release-server release-client
PS 未尝试(
交叉编译生成windows客户端
上述编译过程生成的服务端和客户端都是linux下的,不能在windows下用。如果想编译生成windows客户端,需要重新配置环境并编译。 交叉编译过程如下:
进入go目录,进行环境配置
cd /usr/local/go/src/
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./make.bash
进入ngrok目录重新编译
cd /usr/local/src/ngrok/
GOOS=windows GOARCH=amd64 make release-server release-client
)
配置dns
*.tunnel A 服务器ip地址
启动ngrokd服务端
bin/ngrokd -domain="tunnel.taoerqu.com" -httpAddr=":8000"
注意,让程序一直在后台运行可以执行
nohup bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8000" &
启动ngrok客户端
客户端使用,拷贝刚刚生成的ngrok文件到本地,创建ngrok.cfg配置文件,可以根据自己的实际情况进行配置
server_addr: "tunnel.taoerqu.com:4443"
trust_host_root_certs: false
ngrok -config=ngrok.cfg -subdomain test 8080(使用tomcat并配置8080端口的情况、nginx配置8080反向代理)
控制台输出如果看见online恭喜可以了
浏览器访问 test.tunnel.taoerqu.com:8000 能正确输出网页就表示成功
设置NGINX反向代理去掉8000端口
vi /usr/local/nginx/conf/vhost/tunnel.conf
server { listen 80; server_name *.tunnel.taoerqu.com; access_log /home/wwwlogs/tunnel.log access; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host:8000; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection ""; proxy_pass http://ngrok; } } upstream ngrok { server 127.0.0.1:8000; keepalive 64; }
nginx -s reload
重启ngrok即可~