centos一键安装ngrok
今天同事买了个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个链接里的都经过本人测试,都可以正常使用.


这个脚本我在阿里云centos 7.0上安装成功了的,所以不用区分centos6和7.
}
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’