centos一键安装ngrok

post by rocdk890 / 2017-3-28 16:50 Tuesday linux技术
   今天同事买了个vps让我帮忙装ngrok,想对他家里的nas进行穿透,我一口就答应下来了,因为我想的是用之前的一键安装脚本来搞定,没想到Sunny这个抠娃居然把他自己的ngrok.zip这个文件给删除了,我又懒不想自己慢慢去编译,重新找了个一键安装脚本.
   系统:centos (64位)

脚本内容:
cat /root/soft_shell/install_ngrok.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "NOT SURE WORD FINE!"
echo "ONLY FOR TEST"

#check root
function rootness()
{
  if [[ $EUID -ne 0 ]]; then
        echo "Error:This script must be run as root!" 1>&2
        exit 1
   fi
}

# Check OS bit
function check_os_bit()
{
    if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
        Os_bit='amd64'
    else
        Os_bit='386'
    fi
}

#set domain
function fun_set_ngrok_domain()
{
    # Set ngrok domain
    NGROK_DOMAIN=""
    read -p "Please input domain for Ngrok(e.g.:ngrok.example.com):" NGROK_DOMAIN
    check_input
}

#check domain
function check_input()
{
    # check ngrok domain
    if [ "$NGROK_DOMAIN" = "" ]; then
        echo -e "Your input is empty,please input again..."
        fun_set_ngrok_domain
    else
        echo -e "Your domain: "${NGROK_DOMAIN}" ."
    fi
}


yum -y install zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker hg wget gcc gcc-c++

#install git
cd
wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
tar zxvf git-2.6.0.tar.gz
cd git-2.6.0
./configure --prefix=/usr/local/git
make
make install
ln -s /usr/local/git/bin/* /usr/bin/

#install go
cd
wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-${Os_bit}.tar.gz
tar -zxvf go1.4.2.linux-${Os_bit}.tar.gz
mv go /usr/local/
ln -s /usr/local/go/bin/* /usr/bin/

#install ngrok
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="${NGROK_DOMAIN}"
cd ngrok

#ssl certification
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 -f rootCA.pem assets/client/tls/ngrokroot.crt
cp -f server.crt assets/server/tls/snakeoil.crt
cp -f server.key assets/server/tls/snakeoil.key

#!!!waiting test!!!
sed -e '5c/log "github.com/keepeye/log4go"' /usr/local/ngrok/src/ngrok/log/logger.go

cd /usr/local/go/src
GOOS=linux GOARCH=${Os_bit} ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=${Os_bit} make release-server


#run
nohup /usr/local/ngrok/bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8088" &

编译好服务端之后,大家记得自己把客户端也编译起,客户端的编译参数:
Linux 平台 32 位系统:GOOS=linux GOARCH=386
Linux 平台 64 位系统:GOOS=linux GOARCH=amd64
Windows 平台 32 位系统:GOOS=windows GOARCH=386
Windows 平台 64 位系统:GOOS=windows GOARCH=amd64
MAC 平台 32 位系统:GOOS=darwin GOARCH=386
MAC 平台 64 位系统:GOOS=darwin GOARCH=amd64
ARM 平台:GOOS=linux GOARCH=arm

例如linux 64位的客户端编译命令:
GOOS=linux GOARCH=amd64 make release-client

这样客户端就会编译到/usr/local/ngrok/bin下面去.

ps:
https://github.com/FeulerLoup/ngrok_1.7_one_key_install
https://github.com/chengangwin/ngrok
这2个链接里的都经过本人测试,都可以正常使用.
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-694.html

标签: centos 安装 shell 脚本 install ngrok ngrok1.7

  1. 2017-09-01 16:03
    @whtaangel:我看了下是脚本中的go地址失效了,换个go地址就可以了,把脚本里的wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-${Os_bit}.tar.gz改成wget https://mirrors.ustc.edu.cn/golang/go1.4.2.linux-${Os_bit}.tar.gz.

    这个脚本我在阿里云centos 7.0上安装成功了的,所以不用区分centos6和7.
  1. gravatar whtaangel
    2017-08-28 10:10
    确实有点错误  是不是因为centos7的原因呢


    }

    func Warn(arg0 string, args ...interface{}) error {
        return root.Warn(arg0, args...)
    }

    func Error(arg0 string, args ...interface{}) error {
        return root.Error(arg0, args...)
    }
    ./ngrok2.sh: line 87: cd: /usr/local/go/src: No such file or directory
    ./ngrok2.sh: line 88: ./make.bash: No such file or directory
    GOOS="" GOARCH="" go get github,com/jteeuwen/go-bindata/go-bindata
    /bin/sh: go: command not found
    make: *** [bin/go-bindata] Error 127
    nohup: appending output to ‘nohup.out’
  1. 2017-05-17 11:17
    @sharkyzh:请把报错信息贴出来哦
  1. gravatar sharkyzh
    2017-05-16 12:37
    多谢博主的分享,用你的一键脚本安装的时候报错了,环境Centos7.3 64bit

评论: