开放3个端口,4443,4445,8081端口
4443给ngrok自身通信使用,这个端口最后别动
4445tcp转发使用,端口可自由变动(确保此端口没被占用)
8081 http请求转发使用,端口可自由变动(确保此端口没被占用)
安全组做了,防火墙这些端口也记得开放
在/home/ngrok-serve下创建者两个文件
touch Dockerfile
vi Dockerfile
复制下面的内容进去
FROM golang:1.7.1-alpine
ADD build.sh /
RUN apk add --no-cache git make openssl
RUN git clone https://github.com/inconshreveable/ngrok.git --depth=1 /ngrok
RUN sed -i "109,109s/tcp/tcp4/g" /ngrok/src/ngrok/server/tunnel.go
RUN sed -i "57,57s/tcp/tcp4/g" /ngrok/src/ngrok/conn/conn.go
RUN sh /build.sh
EXPOSE 8081
VOLUME [ "/ngrok" ]
CMD [ "/ngrok/bin/ngrokd"]
创建build.sh
touch build.sh
vi build.sh
export NGROK_DOMAIN="ngrok.xxxx.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 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
make release-server
#下面这些是生成的客户端,可根据自己的客户端进行挑选,不用全部都导出
GOOS=linux GOARCH=386 make release-client
GOOS=linux GOARCH=amd64 make release-client
GOOS=windows GOARCH=386 make release-client
GOOS=windows GOARCH=amd64 make release-client
GOOS=darwin GOARCH=386 make release-client
GOOS=darwin GOARCH=amd64 make release-client
GOOS=linux GOARCH=arm make release-client
需要修改的地方是:
export NGROK_DOMAIN="ngrok.xxxx.com"
2.1 docker安装
# 自动安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# 安装 Docker Engine-Community
sudo yum install docker-ce docker-ce-cli containerd.io
#启动
sudo systemctl start docker
# 运行hello-world验证docke安装成功没
docker run hello-world
2.2 docker构建镜像
docker build -t ngrok
启动容器
docker run -it -p 8081:8081 -p 4443:4443 -p 4445:4445 -d ngrok /ngrok/bin/ngrokd -domain="ngrok.xxxx.com" -httpAddr=":8081"
2.3 下载客户端文件
查找ngrok容器id
docker ps -a
查看容器具体信息
docker inspect xxid
找到Mounts下面的source,将该目录下面 bin下面的客户端文件下载下来
server_addr: "ngrok.xxxx.com:4443"
trust_host_root_certs: false
tunnels:
http:
proto:
http: 5432
subdomain: ngrok
tcp12345:
remote_port: 4445
proto:
tcp: 12345
讲解上面什么意思
4443这个端口是
5432是代理的本地http端口
12345代理的本地tcp端口
subdomain 二级域名
ngrok -config=ngrok.cfg -log=ngrok.log start-all