Linux shell script one-click Installation Ngrok

Source: Internet
Author: User
Tags curl install go openssl openssl x509 pack zip ssh subdomain

Recently, to the internal network for debugging and access, bought 3 peanuts can only map 6 ports, is not enough to meet the needs, just have a friend to me said Ngrok can also be carried through the intranet, research for a few days, light installation will kill a gang of people, fortunately found on the GitHub a button to install Ngrok footsteps, Let's share them first.
System: CentOS 6.x (64-bit)

Script content:
Cat ngrok.sh

#!/bin/bash
#-*-Coding:utf-8-*-

# Get the current script execution path
selfpath=$ (CD "$ (dirname" $) "; pwd)
Goos= ' Go env | grep GOOS | Awk-f\ "' {print $} '
Goarch= ' Go env | grep Goarch | Awk-f\ "' {print $} '
Echo ' Please enter a domain name '
Read DOMAIN
Install_yilai () {
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++ Unzip
}

# Install Git
Install_git () {
Unstall_git
if [!-F $SELFPATH/git-2.6.0.tar.gz];then
wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
Fi
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/
RM-RF $SELFPATH/git-2.6.0
}

# uninstall Git
Unstall_git () {
Rm-rf/usr/local/git
Rm-rf/usr/local/git/bin/git
Rm-rf/usr/local/git/bin/git-cvsserver
Rm-rf/usr/local/git/bin/gitk
Rm-rf/usr/local/git/bin/git-receive-pack
Rm-rf/usr/local/git/bin/git-shell
Rm-rf/usr/local/git/bin/git-upload-archive
Rm-rf/usr/local/git/bin/git-upload-pack
}


# Install Go
Install_go () {
CD $SELFPATH
Uninstall_go
# dynamic link library, for the following judgment conditions to take effect
Ldconfig
# to determine the number of operating system bits download a different installation package
If [$ (getconf word_bit) = ' $ '] && [$ (getconf long_bit) = '];then '
# to determine if a file already exists
if [!-F $SELFPATH/go1.4.2.linux-amd64.tar.gz];then
wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-amd64.tar.gz
Fi
Tar zxvf go1.4.2.linux-amd64.tar.gz
Else
if [!-F $SELFPATH/go1.4.2.linux-386.tar.gz];then
wget http://www.golangtc.com/static/go/1.4.2/go1.4.2.linux-386.tar.gz
Fi
Tar zxvf go1.4.2.linux-386.tar.gz
Fi
MV go/usr/local/
Ln-s/usr/local/go/bin/*/usr/bin/
}

# Uninstall Go

Uninstall_go () {
Rm-rf/usr/local/go
Rm-rf/usr/bin/go
Rm-rf/usr/bin/godoc
Rm-rf/usr/bin/gofmt
}

# Install Ngrok
Install_ngrok () {
Uninstall_ngrok
Cd/usr/local
if [!-f/usr/local/ngrok.zip];then
cd/usr/local/
wget Http://www.sunnyos.com/ngrok.zip
Fi
Unzip Ngrok.zip
Export gopath=/usr/local/ngrok/
Export ngrok_domain= $DOMAIN
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 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
# Replace download Source Address
Sed-i ' s#code.google.com/p/log4go#github.com/keepeye/log4go# '/usr/local/ngrok/src/ngrok/log/logger.go
Cd/usr/local/go/src
goos= $GOOS goarch= $GOARCH./make.bash
Cd/usr/local/ngrok
goos= $GOOS goarch= $GOARCH make Release-server
/usr/local/ngrok/bin/ngrokd-domain= $NGROK _domain-httpaddr= ": 80"
}

# Uninstall Ngrok
Uninstall_ngrok () {
Rm-rf/usr/local/ngrok
}

# Compiling clients
Compile_client () {
Cd/usr/local/go/src
Goos=$1 goarch=$2./make.bash
cd/usr/local/ngrok/
Goos=$1 goarch=$2 make Release-client
}

# Generate Client
Client () {
echo "1, Linux 32 bits"
echo "2, Linux 64 bits"
echo "3, Windows 32-bit"
echo "4, Windows 64-bit"
echo "5, Mac OS 32 bits"
echo "6, Mac OS 64 bits"
echo "7, Linux ARM"

Read num
Case "$num" in
[1])
Compile_client Linux 386
;;
[2])
Compile_client Linux AMD64
;;
[3])
Compile_client Windows 386
;;
[4])
Compile_client Windows AMD64
;;
[5])
Compile_client Darwin 386
;;
[6])
Compile_client Darwin AMD64
;;
[7])
Compile_client Linux Arm
;;
*) echo "Select Error, exit";;
Esac

}


echo "Please enter the following number to select"
echo "#############################################"
echo "#作者网名: Sunny"
echo "#作者博客: www.sunnyos.com"
echo "#作者QQ: 327388905"
echo "#作者QQ群: 57914191"
echo "#作者微博: http://weibo.com/2442303192"
echo "#############################################"
echo "------------------------"
echo "1, New Installation"
echo "2, installation Dependencies"
echo "3, install Git"
echo "4, install go Environment"
echo "5, install Ngrok"
echo "6, Build Client"
echo "7, uninstall"
echo "8, start service"
echo "9, view configuration file"
echo "------------------------"
Read num
Case "$num" in
[1])
Install_yilai
Install_git
Install_go
Install_ngrok
;;
[2])
Install_yilai
;;
[3])
Install_git
;;
[4])
Install_go
;;
[5])
Install_ngrok
;;
[6])
Client
;;
[7])
Unstall_git
Uninstall_go
Uninstall_ngrok
;;
[8])
echo "Enter startup domain name"
Read domain
echo "Boot port"
Read Port
/usr/local/ngrok/bin/ngrokd-domain= $domain-httpaddr= ": $port"
;;
[9])
echo "Enter startup domain name"
Read domain
echo server_addr: ' "' $domain: 4443 '"
echo "Trust_host_root_certs:false"

;;
*) echo "";;
Esac

Ps:
This step is only suitable for CentOS, other Linux please find another.

Default installation path
Git:/usr/local/git
Go:/usr/local/go
Ngrok:/usr/local/ngrok

The client compiles the stored path:
/usr/local/ngrok/bin/

Ngrok Service-side startup command:
Nohup/usr/local/ngrok/bin/ngrokd-domain= "slogra.com"-tlscrt= "/usr/local/ngrok/server.crt"-tlsKey= "/usr/local/" Ngrok/server.key "-httpaddr=": 8080 "-tunneladdr=": 4443 "-log-level=" INFO ">/var/log/ngrok.log 2>&1 &

Ngrok Client configuration file:
SERVER_ADDR: "Your own domain name: 4443"
Tunnels:
Www:
Subdomain: "Test" #定义服务器分配域名前缀, same as on the platform
Proto
HTTP:80 #映射端口, do not add IP default native
Https:80
Web:
Subdomain: "Web" #定义服务器分配域名前缀
Proto
Http:192.168.1.100:80 #映射端口, can be added by IP for any one of the intranet map
Https:192.168.1.100:80
Ssh:
remote_port:50001 #服务器分配tcp转发端口, if this is not completed, then the server is assigned
Proto
Tcp:22 #映射本地的22端口
SSH1: #将由服务器分配端口
Proto
Tcp:21

PS: You can modify the client configuration file according to your own needs.

Client startup command:
1, enter the directory where Ngrok and ngrok.cfg
2. Start a single service./ngrok-config ngrok.cfg start www.
3, start multiple services./ngrok-config ngrok.cfg start www web ssh ssh1
4, background operation can use Setsid./ngrok-config ngrok.cfg Start www

OK, you can configure it according to your needs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.