Create ngrok with centos 7 to implement Intranet penetration

It was a hassle. I had to do a lot of research to figure it out. If you don’t want to torment, simply use ngrok to achieve Intranet penetration, you can move to my tutorial using ngrok free Intranet penetration deployment wechat development debugging environment.

One, environment installation

Install git if there is no yum program found, or very slow please move to this course

Install git dependencies
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++  

Git # download the new version (version list of https://www.kernel.org/pub/software/scm/git/).
cd /usr/localWget HTTP: / / https://www.kernel.org/pub/software/scm/git/git-2.16.2.tar.gz# decompressionThe tar ZXVF git - 2.16.2. Tar. Gz# compile git
cdGit - 2.16.2. / configure -- prefix = / usr /local/git  
make  
make install  

# Delete git package you just downloaded
cd /usr/localThe rm git - 2.16.2. Tar. Gz - yCopy the code

Install the go

# download go
cd /usr/localwww.golangtc.com/static/go (here is the list, how much is the pay attention to your system, Linux - amd64 is 64. Linux - 386 is a 32-bit wget) https://www.golangtc.com/static/go/1.9.2/go1.9.2.linux-amd64.tar.gz if slowly, can be downloaded to the local, uploaded to the server# decompressionThe tar - ZXVF go1.9.2. Linux - amd64. Tar. Gz/usr /local/  

The # go command needs to do a soft link to /usr/bin
ln -s /usr/local/go/bin/* /usr/bin/ 

# Delete the downloaded Go packageThe rm go1.9.2. Linux - amd64. Tar. Gz - yCopy the code

Go Environment Settings

Install the go language installation environment
yum install mercurial bzr subversion -y
Create the go directory as the project directory
mkdir -p $HOME/go
Configure Golang's GOROOT GOPATH with cat
# GOROOT = GOROOT = GOROOT = GOROOT = GOROOT = GOROOT = GOROOT = GOROOTI'm gonna go ahead and copy and paste the whole thing cat >>$HOME/.bash_profile<<EOF
export GOROOT=/usr/local/go    
export GOPATH=\$HOME/go
export PATH=\$PATH: \$GOROOT/bin
EOF
Let the configuration take effect
source $HOME/.bash_profile /.bash_profile /.bash_profile /.bash_profile /.bash_profile"amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"

Copy the code

Two, ngrok configuration

Download ngrok

cd /usr/local/  
git clone https://github.com/inconshreveable/ngrok.git
Copy the code

The environment variable

export GOPATH=/usr/local/ngrok/  
export NGROK_DOMAIN="xxx.com"   Write your own domain name here, without the prefix, such as WWW
Copy the code

If you wish to access your service by xxx.ngrok.xxx.com as a final domain name, you may wish to use xxx.ngrok.xxx.com as a final domain name. You can use level 3 after level 2 is successful, but you have to work from the environment variable step down again. Take a look at the following tutorial: super simple illustration of three-level domain name resolution

Generate a certificate

cd /usr/local/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 
Copy the code

Copy the certificate to override ngrok’s original certificate

Process will let you enter y enter cp rootCA. Pem assets/client/TLS/ngrokroot CRT cp server. The CRT/assets/server/TLS snakeoil. CRT cp server. The key assets/server/tls/snakeoil.keyCopy the code

Generate the server

cd /usr/local/ngrok/  
GOOS=linux GOARCH=amd64 make release-server  # GOOS is your system, I'm Linux, GOARCH is the system, amD64 is 64-bit, 386 is 32-bitThen wait for the download, no progress bar, wait patiently. There could be all kinds of mistakes here, and I was devastated. The generated server is at /usr/localNgrokd file in /ngrok/binCopy the code

Error: Cannot cross-compile Cannot install cross-compiled binaries

$ make release-server GOOS=linux GOARCH=386  
bin/go-bindata -nomemcopy -pkg=assets -tags=release \  
        -debug=false \  
        -o=src/ngrok/client/assets/assets_release.go \  
        assets/client/...  
bin/go-bindata -nomemcopy -pkg=assets -tags=release \  
        -debug=false \  
        -o=src/ngrok/server/assets/assets_release.go \  
        assets/server/...  
go get -tags 'release' -d -v ngrok/...  
go install -tags 'release' ngrok/main/ngrokd  
go install: cannot install cross-compiled binaries when GOBIN is set  
make: *** [server] Error 1
Copy the code

The solution

cd /usr/local/ngrok
mkdir bin  
cp $GOBIN/go-bindata bin/  
unset GOBIN
Copy the code

Generate client

cd /usr/local/ngrok/  
GOOS=windows GOARCH=amd64 make release-client  # GOOS is your system, I want to start the client on Windows, GOARCH is the system, 64 bits is amD64,32 bits is 386Then wait for the download, no progress bar, wait patiently. Generated at /usr/local/ngrok/bin/windows_amd64 ngrok.exe is in bin. The server is Ngrokd and the client is NgrokCopy the code

Start the server

For convenience, I directly use port 80 here. Please confirm that your port 80 is not occupied and close the corresponding service. It is recommended to use nginx reverse proxy to ngrok.cd /usr/local/ngrok/bin
ngrokd -domain="xxx.com" -httpAddr=": 80" -httpsAddr=": 8081" -tunnelAddr=": 4443"

#-domain after the domain name you wrote above -httpaddr HTTP port -httpsaddr HTTPS port
# -tunnerLaddr Client port, connection port
Copy the code

Start client (Window) now download ngrok.exe to your PC and create file ngrok.conf in the same directory. As follows:

server_addr: "xxxx.com:4443"   # the domain name you wrote above
trust_host_root_certs: false  

Open the command line in the # directory
ngrok -config=./ngrok.conf -subdomain=blog 80 
You can change the prefix of the subdomain.
Add secondary domain resolution to DNS
Copy the code

Add secondary domain name resolution

Finally, visit your local server at blog.xxx.com