go安裝 (下載地址https://golang.google.cn/dl/)node
wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gzlinux
tar -C /usr/local -xzf go1.12.1.linux-amd64.tar.gznginx
cat >>/etc/profile<<EOFgit
export PATH=$PATH:/usr/local/go/bingithub
EOFgolang
source /etc/profilewindows
#檢查下是否成功瀏覽器
go versiontomcat
#在當前用戶目錄下新建go目錄做爲項目目錄bash
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
(安裝報錯結果方案:
a、usr/local/git/share/locale'
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
解決:yum install perl-ExtUtils-MakeMaker
b、tclsh failed; using unoptimized loading
MSGFMT po/de.msg make[1]: *** [po/de.msg] Error 127
解決:yum install tcl
c、/bin/sh: msgfmt: command not found
make: *** [po/build/locale/da/LC_MESSAGES/git.mo] Error 127
解決:yum install gettext-devel
d、git clone時候提示fatal: Unable to find remote helper for 'https'
解決:yum install libcurl-devel 安裝完成後,版本確認。
)
安裝ngrok(注意git版本要高於1.7,若是不是請yum remove git而後按上面方式安裝)
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
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.taoerqu.com 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便可~
注:若是反向代理出現502bad gateway
vi /usr/local/nginx/conf/vhost/tunnel.conf
加入如下代碼:(若是header過大,超出了默認的1k,就會引起upstream sent too big header )
proxy_buffer_size 64k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;