1. 配置域名解析(略):
  2. 服务端:
    1. 安装依赖:
      yum -y install gcc golang
    2. 下载:
      git clone https://github.com/job520/ngrok.git
      cd ngrok
    3. 配置环境变量:
      export NGROK_DOMAIN="xxxxx.com"
    4. 生成证书:
      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
    5. 拷贝证书到指定目录:
      cp rootCA.pem assets/client/tls/ngrokroot.crt
      cp server.crt assets/server/tls/snakeoil.crt
      cp server.key assets/server/tls/snakeoil.key
    6. 生成服务器文件:
      make release-server
    7. 生成客户端文件:
      #  linux:
      GOOS=linux GOARCH=amd64 make release-client
      #  windows:
      GOOS=windows GOARCH=amd64 make release-client
      #  mac
      GOOS=darwin GOARCH=amd64 make release-client
    8. 启动:
      ngrok/bin/ngrokd -log="/var/log/ngrok/ngrok.log" -domain="xxxxx.com"
    9. 停止:
      pkill ngrok
  3. 客户端:
    1. 下载生成的对应平台的客户端文件到本地(略)
    2. 编写配置文件:
      vim ngrok.conf
      server_addr: "xxxxx.com:4443"
      trust_host_root_certs: false
      tunnels:
      http:
       subdomain: "test"
      proto:
       http: "80"
      ssh:
       remote_port: 22
      proto:
       tcp: "22"
    3. 连接:
      ./ngrok -log=ngrok.log -config=ngrok.conf start http ssh
文档更新时间: 2020-08-08 20:40   作者:lee