码迷,mamicode.com
首页 > 其他好文 > 详细

centos7搭建ngrok

时间:2018-05-25 13:54:34      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:centos7搭建ngrok

  • 解析域名:
    技术分享图片
    或者
    技术分享图片
  • 安装 git、gcc、golang、wget:
    yum  -y  install  gcc  golang  wget
  • 下载ngrok:
    cd  /usr/local/
    git  clone  https://github.com/dollarphper/ngrok.git
    cd  ngrok/
  • 配置环境变量:
    export  NGROK_DOMAIN="dollarphp.com"
  • 生成证书:
    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
  • 拷贝证书到指定目录:
    cp rootCA.pem assets/client/tls/ngrokroot.crt
    cp server.crt assets/server/tls/snakeoil.crt
    cp server.key assets/server/tls/snakeoil.key
  • 生成服务器文件:
    make  release-server
  • 生成客户端文件:
    #  linux:
    GOOS=linux GOARCH=amd64 make release-client
    #  windows:
    GOOS=windows GOARCH=amd64 make release-client
    #  mac
    GOOS=darwin GOARCH=amd64 make release-client
  • 生成自启动文件:
    vim /etc/init.d/ngrokd
    a. 编写启动脚本:
    #!/bin/bash
    NGROK_DOMAIN=dollarphp.com
    function start()
    {
    /usr/local/ngrok/bin/ngrokd -log="/var/log/ngrok/ngrok.log" -domain="$NGROK_DOMAIN" 1> /dev/null 2> /var/log/ngrok/ngrok.log &
    }
    function stop()
    {
    pkill ngrokd
    }
    case "$1" in
    start)
        start
    ;;  
    stop)
        stop
    ;;  
    restart)
        stop
        start
    ;;
    *)
        echo "Usage : start | stop | restart"
    ;;
    esac

    b. 添加可执行权限:

    chmod  a+x  /etc/init.d/ngrokd

    c. 刷新系统启动项:

    systemctl  daemon-reload

    d. 创建日志文件:

    mkdir  -p  /var/log/ngrok
    touch  /var/log/ngrok/ngrok.log
  • 启动服务:
    systemctl  start  ngrokd
  • 拷贝服务端文件到客户端:
    scp  root@104.225.233.xxx://usr/local/ngrok/bin/ngrok  ./
  • 编写配置文件:
    vim ngrok.conf
    server_addr: "dollarphp.com:4443"
    trust_host_root_certs: false
    tunnels:
    http:
    subdomain: "test"
    proto:
      http: "80"
    ssh:
    remote_port: 8023
    proto:
      tcp: "22"
  • 连接:
    ./ngrok  -log=ngrok.log  -config=ngrok.conf  start  http  ssh
  • centos7搭建ngrok

    标签:centos7搭建ngrok

    原文地址:http://blog.51cto.com/12173069/2120166

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!